diff --git a/apps/ui-playground/components/ui/IconGrid.tsx b/apps/ui-playground/components/ui/IconGrid.tsx index 6bcdb153d0..8ead4d51a1 100644 --- a/apps/ui-playground/components/ui/IconGrid.tsx +++ b/apps/ui-playground/components/ui/IconGrid.tsx @@ -22,6 +22,7 @@ type IconName = | "binary" | "blocks" | "bold" + | "book" | "book-open-check" | "book-open" | "book-user" diff --git a/apps/web/modules/settings/organizations/privacy/blocklist-table.tsx b/apps/web/modules/settings/organizations/privacy/blocklist-table.tsx index 34fe92f86f..fce84cdf13 100644 --- a/apps/web/modules/settings/organizations/privacy/blocklist-table.tsx +++ b/apps/web/modules/settings/organizations/privacy/blocklist-table.tsx @@ -1,23 +1,18 @@ "use client"; -import { keepPreviousData } from "@tanstack/react-query"; -import { getCoreRowModel, getSortedRowModel, useReactTable, type ColumnDef } from "@tanstack/react-table"; -import { useMemo, useState } from "react"; +import { useState } from "react"; -import { DataTableWrapper, DataTableToolbar, useDataTable } from "@calcom/features/data-table"; +import { DataTableToolbar } from "@calcom/features/data-table"; import { useLocale } from "@calcom/lib/hooks/useLocale"; -import { trpc } from "@calcom/trpc"; -import type { RouterOutputs } from "@calcom/trpc/react"; -import { Badge } from "@calcom/ui/components/badge"; import { Button } from "@calcom/ui/components/button"; -import { ButtonGroup } from "@calcom/ui/components/buttonGroup"; -import { ConfirmationDialogContent, Dialog } from "@calcom/ui/components/dialog"; -import { showToast } from "@calcom/ui/components/toast"; +import { ToggleGroup } from "@calcom/ui/components/form"; -import { BlocklistEntryDetailsSheet } from "./components/blocklist-entry-details-sheet"; +import PendingReportsBadge from "./components/PendingReportsBadge"; +import { BlockedEntriesTable } from "./components/blocked-entries-table"; import { CreateBlocklistEntryModal } from "./components/create-blocklist-entry-modal"; +import { PendingReportsTable } from "./components/pending-reports-table"; -type BlocklistEntry = RouterOutputs["viewer"]["organizations"]["listWatchlistEntries"]["rows"][number]; +type ViewType = "blocked" | "pending"; interface BlocklistTableProps { permissions?: { @@ -29,179 +24,49 @@ interface BlocklistTableProps { export function BlocklistTable({ permissions }: BlocklistTableProps) { const { t } = useLocale(); - const { limit, offset, searchTerm } = useDataTable(); - + const [activeView, setActiveView] = useState("blocked"); const [showCreateModal, setShowCreateModal] = useState(false); - const [showDetailsSheet, setShowDetailsSheet] = useState(false); - const [selectedEntry, setSelectedEntry] = useState(null); - const [entryToDelete, setEntryToDelete] = useState(null); - const [showDeleteDialog, setShowDeleteDialog] = useState(false); - - const { data, isPending } = trpc.viewer.organizations.listWatchlistEntries.useQuery( - { - limit, - offset, - searchTerm, - }, - { - placeholderData: keepPreviousData, - } - ); - - const utils = trpc.useUtils(); - - const deleteWatchlistEntry = trpc.viewer.organizations.deleteWatchlistEntry.useMutation({ - onSuccess: async () => { - await utils.viewer.organizations.listWatchlistEntries.invalidate(); - showToast(t("blocklist_entry_deleted"), "success"); - setShowDeleteDialog(false); - setEntryToDelete(null); - }, - onError: (error) => { - showToast(error.message, "error"); - }, - }); - - const handleDelete = (entry: BlocklistEntry) => { - setEntryToDelete(entry); - setShowDeleteDialog(true); - }; - - const confirmDelete = () => { - if (entryToDelete) { - deleteWatchlistEntry.mutate({ id: entryToDelete.id }); - } - }; - - const handleViewDetails = (entry: BlocklistEntry) => { - setSelectedEntry(entry); - setShowDetailsSheet(true); - }; - - const totalRowCount = data?.meta?.totalRowCount ?? 0; - const flatData = useMemo(() => data?.rows ?? [], [data]); - - const columns = useMemo[]>( - () => [ - { - id: "value", - header: t("value"), - accessorKey: "value", - enableHiding: false, - cell: ({ row }) => {row.original.value}, - }, - { - id: "type", - header: t("type"), - accessorKey: "type", - size: 100, - cell: ({ row }) => ( - {row.original.type === "EMAIL" ? t("email") : t("domain")} - ), - }, - { - id: "createdBy", - header: t("blocked_by"), - size: 180, - cell: ({ row }) => { - const audit = row.original.audits?.[0] as - | { changedByUserId: number | null } - | { - changedByUser?: { id: number; email: string; name: string | null } | undefined; - changedByUserId: number | null; - } - | undefined; - const email = - (audit && "changedByUser" in audit ? audit.changedByUser?.email : undefined) ?? undefined; - return {email ?? "—"}; - }, - }, - { - id: "actions", - header: "", - size: 120, - enableHiding: false, - enableSorting: false, - enableResizing: false, - cell: ({ row }) => { - const entry = row.original; - return ( -
- -
- ); - }, - }, - ], - [t, permissions?.canDelete] - ); - - const table = useReactTable({ - data: flatData, - columns, - getCoreRowModel: getCoreRowModel(), - getSortedRowModel: getSortedRowModel(), - manualPagination: true, - pageCount: Math.ceil(totalRowCount / limit), - }); return ( <> - -
+
+
+ { + if (value) setActiveView(value as ViewType); + }} + options={[ + { value: "blocked", label: t("blocked") }, + { + value: "pending", + label: ( + + {t("pending")} + + + ), + }, + ]} + /> -
- {permissions?.canCreate && ( - - )} -
- +
+ {permissions?.canCreate && ( + + )} +
+
+ + {activeView === "blocked" ? ( + setShowCreateModal(true)} /> + ) : ( + + )} setShowCreateModal(false)} /> - - { - setShowDetailsSheet(false); - setSelectedEntry(null); - }} - /> - - - - {t("delete_blocklist_entry_confirmation", { value: entryToDelete?.value })} - - ); } diff --git a/apps/web/modules/settings/organizations/privacy/components/PendingReportsBadge.tsx b/apps/web/modules/settings/organizations/privacy/components/PendingReportsBadge.tsx new file mode 100644 index 0000000000..aec0f3781e --- /dev/null +++ b/apps/web/modules/settings/organizations/privacy/components/PendingReportsBadge.tsx @@ -0,0 +1,12 @@ +import { trpc } from "@calcom/trpc/react"; +import { Badge } from "@calcom/ui/components/badge"; + +export default function PendingReportsBadge() { + const { data: pendingReportsCount } = trpc.viewer.organizations.pendingReportsCount.useQuery(); + if (!pendingReportsCount) return null; + return ( + + {pendingReportsCount} + + ); +} diff --git a/apps/web/modules/settings/organizations/privacy/components/blocked-entries-columns.tsx b/apps/web/modules/settings/organizations/privacy/components/blocked-entries-columns.tsx new file mode 100644 index 0000000000..cd81c18ad0 --- /dev/null +++ b/apps/web/modules/settings/organizations/privacy/components/blocked-entries-columns.tsx @@ -0,0 +1,108 @@ +import type { ColumnDef } from "@tanstack/react-table"; +import { useMemo } from "react"; + +import type { RouterOutputs } from "@calcom/trpc/react"; +import { Badge } from "@calcom/ui/components/badge"; +import { Button } from "@calcom/ui/components/button"; +import { + Dropdown, + DropdownItem, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuTrigger, +} from "@calcom/ui/components/dropdown"; + +type BlocklistEntry = RouterOutputs["viewer"]["organizations"]["listWatchlistEntries"]["rows"][number]; + +interface UseBlockedEntriesColumnsProps { + t: (key: string) => string; + canDelete?: boolean; + onViewDetails: (entry: BlocklistEntry) => void; + onDelete: (entry: BlocklistEntry) => void; +} + +export function useBlockedEntriesColumns({ + t, + canDelete, + onViewDetails, + onDelete, +}: UseBlockedEntriesColumnsProps) { + return useMemo[]>( + () => [ + { + id: "email_slash_domain", + header: t("email_slash_domain"), + accessorKey: "value", + enableHiding: false, + cell: ({ row }) => {row.original.value}, + }, + { + id: "type", + header: t("type"), + accessorKey: "type", + size: 100, + cell: ({ row }) => ( + {row.original.type === "EMAIL" ? t("email") : t("domain")} + ), + }, + { + id: "createdBy", + header: t("blocked_by"), + size: 180, + cell: ({ row }) => { + const audit = row.original.audits?.[0] as + | { changedByUserId: number | null } + | { + changedByUser?: { id: number; email: string; name: string | null } | undefined; + changedByUserId: number | null; + } + | undefined; + const email = + (audit && "changedByUser" in audit ? audit.changedByUser?.email : undefined) ?? undefined; + return {email ?? "—"}; + }, + }, + { + id: "actions", + header: "", + size: 90, + minSize: 90, + maxSize: 90, + enableHiding: false, + enableSorting: false, + enableResizing: false, + cell: ({ row }) => { + const entry = row.original; + return ( +
+ + +
+ ); + }, + }, + ], + [t, canDelete, onViewDetails, onDelete] + ); +} diff --git a/apps/web/modules/settings/organizations/privacy/components/blocked-entries-table.tsx b/apps/web/modules/settings/organizations/privacy/components/blocked-entries-table.tsx new file mode 100644 index 0000000000..e8013c63ad --- /dev/null +++ b/apps/web/modules/settings/organizations/privacy/components/blocked-entries-table.tsx @@ -0,0 +1,165 @@ +"use client"; + +import { keepPreviousData } from "@tanstack/react-query"; +import { getCoreRowModel, getSortedRowModel, useReactTable } from "@tanstack/react-table"; +import { useMemo, useState } from "react"; + +import { DataTableWrapper, useDataTable } from "@calcom/features/data-table"; +import { IS_CALCOM } from "@calcom/lib/constants"; +import { useLocale } from "@calcom/lib/hooks/useLocale"; +import { trpc } from "@calcom/trpc"; +import type { RouterOutputs } from "@calcom/trpc/react"; +import { Button } from "@calcom/ui/components/button"; +import { ConfirmationDialogContent, Dialog, DialogClose } from "@calcom/ui/components/dialog"; +import { EmptyScreen } from "@calcom/ui/components/empty-screen"; +import { showToast } from "@calcom/ui/components/toast"; + +import { useBlockedEntriesColumns } from "./blocked-entries-columns"; +import { BlocklistEntryDetailsSheet } from "./blocklist-entry-details-sheet"; + +type BlocklistEntry = RouterOutputs["viewer"]["organizations"]["listWatchlistEntries"]["rows"][number]; + +interface BlockedEntriesTableProps { + permissions?: { + canRead: boolean; + canCreate: boolean; + canDelete: boolean; + }; + onAddClick: () => void; +} + +export function BlockedEntriesTable({ permissions, onAddClick }: BlockedEntriesTableProps) { + const { t } = useLocale(); + const { limit, offset, searchTerm } = useDataTable(); + + const [showDetailsSheet, setShowDetailsSheet] = useState(false); + const [selectedEntry, setSelectedEntry] = useState(null); + const [entryToDelete, setEntryToDelete] = useState(null); + const [showDeleteDialog, setShowDeleteDialog] = useState(false); + + const { data, isPending } = trpc.viewer.organizations.listWatchlistEntries.useQuery( + { + limit, + offset, + searchTerm, + }, + { + placeholderData: keepPreviousData, + } + ); + + const utils = trpc.useUtils(); + + const deleteWatchlistEntry = trpc.viewer.organizations.deleteWatchlistEntry.useMutation({ + onSuccess: async () => { + await utils.viewer.organizations.listWatchlistEntries.invalidate(); + showToast(t("blocklist_entry_deleted"), "success"); + setShowDeleteDialog(false); + setEntryToDelete(null); + }, + onError: (error) => { + showToast(error.message, "error"); + }, + }); + + const handleViewDetails = (entry: BlocklistEntry) => { + setSelectedEntry(entry); + setShowDetailsSheet(true); + }; + + const handleDelete = (entry: BlocklistEntry) => { + setEntryToDelete(entry); + setShowDeleteDialog(true); + }; + + const confirmDelete = () => { + if (entryToDelete) { + deleteWatchlistEntry.mutate({ id: entryToDelete.id }); + } + }; + + const columns = useBlockedEntriesColumns({ + t, + canDelete: permissions?.canDelete, + onViewDetails: handleViewDetails, + onDelete: handleDelete, + }); + + const totalRowCount = data?.meta?.totalRowCount ?? 0; + const flatData = useMemo(() => data?.rows ?? [], [data]); + + const table = useReactTable({ + data: flatData, + columns, + getCoreRowModel: getCoreRowModel(), + getSortedRowModel: getSortedRowModel(), + manualPagination: true, + pageCount: Math.ceil(totalRowCount / limit), + }); + + return ( + <> + } + headline={searchTerm ? t("no_result_found_for", { searchTerm }) : t("pbac_resource_blocklist")} + description={t("add_people_to_blocklist")} + className="bg-muted mb-16" + iconWrapperClassName="bg-default" + dashedBorder={false} + buttonRaw={ +
+ + {IS_CALCOM && ( + + )} +
+ } + /> + } + totalRowCount={totalRowCount} + /> + + { + setShowDetailsSheet(false); + setSelectedEntry(null); + }} + handleDeleteBlocklistEntry={handleDelete} + /> + + + + {t("remove")} + + }> + {t("remove_value_from_blocklist_description")} + + + + ); +} diff --git a/apps/web/modules/settings/organizations/privacy/components/blocklist-entry-details-sheet.tsx b/apps/web/modules/settings/organizations/privacy/components/blocklist-entry-details-sheet.tsx index 3ac4140fa2..1120d1ed0e 100644 --- a/apps/web/modules/settings/organizations/privacy/components/blocklist-entry-details-sheet.tsx +++ b/apps/web/modules/settings/organizations/privacy/components/blocklist-entry-details-sheet.tsx @@ -1,12 +1,21 @@ "use client"; import { format } from "date-fns"; +import Link from "next/link"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import type { RouterOutputs } from "@calcom/trpc/react"; import { trpc } from "@calcom/trpc/react"; -import { Badge } from "@calcom/ui/components/badge"; -import { Sheet, SheetContent, SheetHeader, SheetTitle } from "@calcom/ui/components/sheet"; +import { Button } from "@calcom/ui/components/button"; +import { Icon } from "@calcom/ui/components/icon"; +import { + Sheet, + SheetContent, + SheetBody, + SheetHeader, + SheetTitle, + SheetFooter, +} from "@calcom/ui/components/sheet"; import { SkeletonText } from "@calcom/ui/components/skeleton"; type BlocklistEntry = RouterOutputs["viewer"]["organizations"]["listWatchlistEntries"]["rows"][number]; @@ -15,9 +24,15 @@ interface BlocklistEntryDetailsSheetProps { entry: BlocklistEntry | null; isOpen: boolean; onClose: () => void; + handleDeleteBlocklistEntry: (entry: BlocklistEntry) => void; } -export function BlocklistEntryDetailsSheet({ entry, isOpen, onClose }: BlocklistEntryDetailsSheetProps) { +export function BlocklistEntryDetailsSheet({ + entry, + isOpen, + onClose, + handleDeleteBlocklistEntry, +}: BlocklistEntryDetailsSheetProps) { const { t } = useLocale(); const { data, isLoading } = trpc.viewer.organizations.getWatchlistEntryDetails.useQuery( @@ -27,104 +42,115 @@ export function BlocklistEntryDetailsSheet({ entry, isOpen, onClose }: Blocklist } ); - const getActionVariant = (action: string) => { - switch (action) { - case "BLOCK": - return "red"; - case "REPORT": - return "orange"; - case "ALERT": - return "blue"; - default: - return "gray"; - } - }; - return ( - { if (!open) onClose(); }}> - - - {t("blocklist_entry_details")} + { + if (!open) onClose(); + }}> + + + {entry?.value} - {isLoading ? ( -
- - - - - - -
- ) : data?.entry ? ( -
-
-
- - - {data.entry.type === "EMAIL" ? t("email") : t("domain")} - -
- -
- -

{data.entry.value}

-
- -
- - - {t(data.entry.action.toLowerCase())} - -
- -
- -

{data.entry.description || t("no_description_provided")}

-
- -
- -

{data.auditHistory[0]?.changedByUser?.email || "—"}

-
+ + {isLoading ? ( +
+ +
+ ) : data?.entry ? ( +
+
+

{t("details")}

-
+
+
+ +

{data.entry.value}

+
-
-

{t("audit_history")}

- {data.auditHistory.length > 0 ? ( -
- {data.auditHistory.map((audit, index) => ( -
-
-
- {t("by")}: - {audit.changedByUser?.email || "—"} -
- - {format(new Date(audit.changedAt), "MMM d, h:mm a")} - -
-
- {t("added")}: - {audit.value} -
+
+ +

+ {data.entry.type === "EMAIL" ? t("email") : t("domain")} +

+
+ +
+ +

{data.auditHistory[0]?.changedByUser?.email || "—"}

+
+ +
+ +

+ {data.entry.description || t("no_description_provided")} +

+
+ + {data.entry.bookingReports && data.entry.bookingReports.length > 0 && ( +
+ + + {data.entry.bookingReports.map((report) => { + return ( + +
+ {report.booking.title} + +
+ + ); + })}
- ))} + )}
- ) : ( -

{t("no_audit_history")}

- )} +
+ +
+

{t("history")}

+ {data.auditHistory.length > 0 ? ( +
+ {data.auditHistory.map((audit) => ( +
+
+
+ + {audit.changedByUser?.name || audit.changedByUser?.email || "—"} + + {t("added")} +
{audit.value}
+
+ + {format(new Date(audit.changedAt), "MMM d, h:mm a")} + +
+
+ ))} +
+ ) : ( +

{t("no_audit_history")}

+ )} +
-
- ) : ( -
{t("blocklist_entry_not_found")}
- )} + ) : ( +
{t("blocklist_entry_not_found")}
+ )} + + + + ); diff --git a/apps/web/modules/settings/organizations/privacy/components/booking-report-entry-details-modal.tsx b/apps/web/modules/settings/organizations/privacy/components/booking-report-entry-details-modal.tsx new file mode 100644 index 0000000000..5d0858fd3d --- /dev/null +++ b/apps/web/modules/settings/organizations/privacy/components/booking-report-entry-details-modal.tsx @@ -0,0 +1,208 @@ +"use client"; + +import Link from "next/link"; +import { Controller, useForm } from "react-hook-form"; + +import { useLocale } from "@calcom/lib/hooks/useLocale"; +import { WatchlistType } from "@calcom/prisma/enums"; +import type { RouterOutputs } from "@calcom/trpc/react"; +import { trpc } from "@calcom/trpc/react"; +import { Button } from "@calcom/ui/components/button"; +import { Dialog, DialogContent, DialogFooter, DialogHeader } from "@calcom/ui/components/dialog"; +import { ToggleGroup } from "@calcom/ui/components/form"; +import { Icon } from "@calcom/ui/components/icon"; +import { showToast } from "@calcom/ui/components/toast"; + +type BookingReport = RouterOutputs["viewer"]["organizations"]["listBookingReports"]["rows"][number]; + +interface BookingReportEntryDetailsModalProps { + entry: BookingReport | null; + isOpen: boolean; + onClose: () => void; +} + +interface FormData { + blockType: WatchlistType; +} + +export function BookingReportEntryDetailsModal({ + entry, + isOpen, + onClose, +}: BookingReportEntryDetailsModalProps) { + const { t } = useLocale(); + const utils = trpc.useUtils(); + + const { + control, + handleSubmit, + reset, + formState: { isSubmitting }, + } = useForm({ + defaultValues: { + blockType: WatchlistType.EMAIL, + }, + }); + + const addToWatchlist = trpc.viewer.organizations.addToWatchlist.useMutation({ + onSuccess: async () => { + await utils.viewer.organizations.listBookingReports.invalidate(); + await utils.viewer.organizations.listWatchlistEntries.invalidate(); + showToast(t("blocklist_entry_created"), "success"); + onClose(); + reset(); + }, + onError: (error) => { + showToast(error.message, "error"); + }, + }); + + const dismissBookingReport = trpc.viewer.organizations.dismissBookingReport.useMutation({ + onSuccess: async () => { + await utils.viewer.organizations.listBookingReports.invalidate(); + showToast(t("booking_report_dismissed"), "success"); + onClose(); + reset(); + }, + onError: (error) => { + showToast(error.message, "error"); + }, + }); + + const onSubmit = (data: FormData) => { + if (!entry) return; + + addToWatchlist.mutate({ + reportIds: [entry.id], + type: data.blockType, + }); + }; + + const handleDismiss = () => { + if (!entry) return; + + dismissBookingReport.mutate({ + reportId: entry.id, + }); + }; + + const handleGoBack = () => { + onClose(); + reset(); + }; + + const reasonMap: Record = { + SPAM: t("spam"), + DONT_KNOW_PERSON: t("dont_know_person"), + OTHER: t("other"), + }; + + if (!entry) return null; + + return ( + + + +
+
+
+

{t("details")}

+
+
+ +

{entry.bookerEmail}

+
+ +
+ +

{reasonMap[entry.reason] || entry.reason}

+
+ +
+ +

{entry.reporter?.email || "—"}

+
+ +
+ +

{entry.description || t("no_description_provided")}

+
+ +
+ + +
+ {entry.booking.title} + +
+ +
+
+
+ +
+

+ {t("what_would_you_like_to_block")} +

+ ( + { + if (value) field.onChange(value); + }} + options={[ + { + value: WatchlistType.EMAIL, + label: t("block_this_email"), + iconLeft: , + }, + { + value: WatchlistType.DOMAIN, + label: t("block_all_from_domain"), + iconLeft: , + }, + ]} + /> + )} + /> +
+
+ + +
+ + +
+ + +
+
+
+
+
+
+ ); +} diff --git a/apps/web/modules/settings/organizations/privacy/components/create-blocklist-entry-modal.tsx b/apps/web/modules/settings/organizations/privacy/components/create-blocklist-entry-modal.tsx index b2b5d036c2..75645eb05f 100644 --- a/apps/web/modules/settings/organizations/privacy/components/create-blocklist-entry-modal.tsx +++ b/apps/web/modules/settings/organizations/privacy/components/create-blocklist-entry-modal.tsx @@ -8,7 +8,8 @@ import { WatchlistType } from "@calcom/prisma/enums"; import { trpc } from "@calcom/trpc/react"; import { Button } from "@calcom/ui/components/button"; import { Dialog, DialogContent, DialogFooter, DialogHeader } from "@calcom/ui/components/dialog"; -import { Input, Select, Label, TextArea } from "@calcom/ui/components/form"; +import { Input, Label, TextArea, ToggleGroup } from "@calcom/ui/components/form"; +import { Icon } from "@calcom/ui/components/icon"; import { showToast } from "@calcom/ui/components/toast"; interface CreateBlocklistEntryModalProps { @@ -80,35 +81,34 @@ export function CreateBlocklistEntryModal({ isOpen, onClose }: CreateBlocklistEn }; const typeOptions = [ - { label: t("email"), value: WatchlistType.EMAIL }, - { label: t("domain"), value: WatchlistType.DOMAIN }, + { label: t("email"), value: WatchlistType.EMAIL, iconLeft: }, + { label: t("domain"), value: WatchlistType.DOMAIN, iconLeft: }, ]; return ( - +
( -