feat: system admin blocklist table (#25039)

* feat: system admin blocklist table

* chore: text

* fix: type error

* fix: type error

* fix: type error

* fix: frontend bug

* chore: improvments

* refactor: use shared components

* refactor: improvements

* fix: delete

* refactor: support multiple watchlist

* chore: update translation

* fix: type err

* fix: bulk bug

* tests: add unit test

* refactor: file

* refactor: file

* fix: type error

* fix: type error

* chore: translation

* refactor: use shared comments

* fix: imports

* fix: type error
This commit is contained in:
Udit Takkar authored and GitHub committed 2026-01-09 08:19:54 -03:00
1 parent d865f6cb5f
commit 0330d14210
34 files changed
+1970 -633

No files matched your search

@@ -1,16 +1,21 @@
"use client";
import { keepPreviousData } from "@tanstack/react-query";
import { useState } from "react";
import {
BlockedEntriesTable,
CreateBlocklistEntryModal,
PendingReportsBadge,
PendingReportsTable,
} from "@calcom/features/blocklist";
import { useDataTable } from "@calcom/features/data-table";
import { DataTableToolbar } from "~/data-table/components";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { trpc } from "@calcom/trpc/react";
import { Button } from "@calcom/ui/components/button";
import { ToggleGroup } from "@calcom/ui/components/form";
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";
import { showToast } from "@calcom/ui/components/toast";
type ViewType = "blocked" | "pending";
@@ -24,8 +29,86 @@ interface BlocklistTableProps {
export function BlocklistTable({ permissions }: BlocklistTableProps) {
const { t } = useLocale();
const { limit, offset, searchTerm } = useDataTable();
const [activeView, setActiveView] = useState<ViewType>("blocked");
const [showCreateModal, setShowCreateModal] = useState(false);
const [selectedEntryId, setSelectedEntryId] = useState<string | null>(null);
const utils = trpc.useUtils();
const { data: blockedData, isPending: isBlockedPending } =
trpc.viewer.organizations.listWatchlistEntries.useQuery(
{ limit, offset, searchTerm },
{ placeholderData: keepPreviousData, enabled: activeView === "blocked" }
);
const { data: reportsData, isPending: isReportsPending } =
trpc.viewer.organizations.listBookingReports.useQuery(
{
limit,
offset,
searchTerm,
filters: { hasWatchlist: false, status: ["PENDING"] },
},
{ placeholderData: keepPreviousData, enabled: activeView === "pending" }
);
const { data: pendingReportsCount } =
trpc.viewer.organizations.pendingReportsCount.useQuery();
const { data: entryDetails, isLoading: isDetailsLoading } =
trpc.viewer.organizations.getWatchlistEntryDetails.useQuery(
{ id: selectedEntryId ?? "" },
{ enabled: !!selectedEntryId }
);
const createEntry =
trpc.viewer.organizations.createWatchlistEntry.useMutation({
onSuccess: async () => {
await utils.viewer.organizations.listWatchlistEntries.invalidate();
showToast(t("blocklist_entry_created"), "success");
setShowCreateModal(false);
},
onError: (error) => {
showToast(error.message, "error");
},
});
const deleteEntry =
trpc.viewer.organizations.deleteWatchlistEntry.useMutation({
onSuccess: async () => {
await utils.viewer.organizations.listWatchlistEntries.invalidate();
setSelectedEntryId(null);
showToast(t("blocklist_entry_deleted"), "success");
},
onError: (error) => {
showToast(error.message, "error");
},
});
const addToWatchlist = trpc.viewer.organizations.addToWatchlist.useMutation({
onSuccess: async () => {
await utils.viewer.organizations.listBookingReports.invalidate();
await utils.viewer.organizations.listWatchlistEntries.invalidate();
await utils.viewer.organizations.pendingReportsCount.invalidate();
showToast(t("blocklist_entry_created"), "success");
},
onError: (error) => {
showToast(error.message, "error");
},
});
const dismissReport =
trpc.viewer.organizations.dismissBookingReport.useMutation({
onSuccess: async () => {
await utils.viewer.organizations.listBookingReports.invalidate();
await utils.viewer.organizations.pendingReportsCount.invalidate();
showToast(t("booking_report_dismissed"), "success");
},
onError: (error) => {
showToast(error.message, "error");
},
});
return (
<>
@@ -43,7 +126,7 @@ export function BlocklistTable({ permissions }: BlocklistTableProps) {
label: (
<span className="flex items-center">
{t("pending")}
<PendingReportsBadge />
<PendingReportsBadge count={pendingReportsCount} />
</span>
),
},
@@ -53,7 +136,11 @@ export function BlocklistTable({ permissions }: BlocklistTableProps) {
</div>
<div className="flex items-center gap-2">
{permissions?.canCreate && (
<Button color="primary" StartIcon="plus" onClick={() => setShowCreateModal(true)}>
<Button
color="primary"
StartIcon="plus"
onClick={() => setShowCreateModal(true)}
>
{t("add")}
</Button>
)}
@@ -61,12 +148,46 @@ export function BlocklistTable({ permissions }: BlocklistTableProps) {
</div>
{activeView === "blocked" ? (
<BlockedEntriesTable permissions={permissions} onAddClick={() => setShowCreateModal(true)} />
<BlockedEntriesTable
scope="organization"
data={blockedData?.rows ?? []}
totalRowCount={blockedData?.meta?.totalRowCount ?? 0}
isPending={isBlockedPending}
limit={limit}
searchTerm={searchTerm}
permissions={permissions}
onAddClick={() => setShowCreateModal(true)}
onDelete={(entry) => deleteEntry.mutate({ id: entry.id })}
isDeleting={deleteEntry.isPending}
detailsQuery={{ data: entryDetails, isLoading: isDetailsLoading }}
selectedEntryId={selectedEntryId ?? undefined}
onSelectEntry={setSelectedEntryId}
/>
) : (
<PendingReportsTable />
<PendingReportsTable
scope="organization"
data={reportsData?.rows ?? []}
totalRowCount={reportsData?.meta?.totalRowCount ?? 0}
isPending={isReportsPending}
limit={limit}
onAddToBlocklist={(reportIds, type, onSuccess) =>
addToWatchlist.mutate({ reportIds, type }, { onSuccess })
}
onDismiss={(reportId, onSuccess) =>
dismissReport.mutate({ reportId }, { onSuccess })
}
isAddingToBlocklist={addToWatchlist.isPending}
isDismissing={dismissReport.isPending}
/>
)}
<CreateBlocklistEntryModal isOpen={showCreateModal} onClose={() => setShowCreateModal(false)} />
<CreateBlocklistEntryModal
isOpen={showCreateModal}
onClose={() => setShowCreateModal(false)}
scope="organization"
onCreateEntry={(data) => createEntry.mutate(data)}
isPending={createEntry.isPending}
/>
</>
);
}
@@ -1,12 +0,0 @@
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 (
<Badge rounded variant="orange" className="ml-1">
{pendingReportsCount}
</Badge>
);
}
@@ -1,108 +0,0 @@
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<ColumnDef<BlocklistEntry>[]>(
() => [
{
id: "email_slash_domain",
header: t("email_slash_domain"),
accessorKey: "value",
enableHiding: false,
cell: ({ row }) => <span className="text-emphasis">{row.original.value}</span>,
},
{
id: "type",
header: t("type"),
accessorKey: "type",
size: 100,
cell: ({ row }) => (
<Badge variant="blue">{row.original.type === "EMAIL" ? t("email") : t("domain")}</Badge>
),
},
{
id: "createdBy",
header: t("blocked_by"),
size: 180,
cell: ({ row }) => {
const audit = row.original.latestAudit as
| { changedByUserId: number | null }
| {
changedByUser?: { id: number; email: string; name: string | null } | undefined;
changedByUserId: number | null;
}
| null;
const email =
(audit && "changedByUser" in audit ? audit.changedByUser?.email : undefined) ?? undefined;
return <span className="text-default">{email ?? "—"}</span>;
},
},
{
id: "actions",
header: "",
size: 90,
minSize: 90,
maxSize: 90,
enableHiding: false,
enableSorting: false,
enableResizing: false,
cell: ({ row }) => {
const entry = row.original;
return (
<div className="flex items-center justify-end">
<Dropdown modal={false}>
<DropdownMenuTrigger asChild>
<Button type="button" variant="icon" color="secondary" StartIcon="ellipsis" />
</DropdownMenuTrigger>
<DropdownMenuContent>
<DropdownMenuItem>
<DropdownItem type="button" StartIcon="eye" onClick={() => onViewDetails(entry)}>
{t("view_details")}
</DropdownItem>
</DropdownMenuItem>
{canDelete && (
<DropdownMenuItem>
<DropdownItem
type="button"
color="destructive"
StartIcon="trash"
onClick={() => onDelete(entry)}>
{t("remove_from_blocklist")}
</DropdownItem>
</DropdownMenuItem>
)}
</DropdownMenuContent>
</Dropdown>
</div>
);
},
},
],
[t, canDelete, onViewDetails, onDelete]
);
}
@@ -1,166 +0,0 @@
"use client";
import { keepPreviousData } from "@tanstack/react-query";
import { getCoreRowModel, getSortedRowModel, useReactTable } from "@tanstack/react-table";
import { useMemo, useState } from "react";
import { useDataTable } from "@calcom/features/data-table";
import { DataTableWrapper } from "~/data-table/components";
import { IS_CALCOM } from "@calcom/lib/constants";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { trpc } from "@calcom/trpc/react";
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<BlocklistEntry | null>(null);
const [entryToDelete, setEntryToDelete] = useState<BlocklistEntry | null>(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 (
<>
<DataTableWrapper
table={table}
isPending={isPending}
variant="default"
paginationMode="standard"
EmptyView={
<EmptyScreen
customIcon={<img className="mb-6" src="/slash-icon-cards.svg" />}
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={
<div className="flex gap-2">
<Button
StartIcon="plus"
onClick={onAddClick}
color="primary"
disabled={!permissions?.canCreate}>
{t("add")}
</Button>
{IS_CALCOM && (
<Button
StartIcon="book"
color="secondary"
onClick={() =>
window.open("https://cal.com/help/security/blocklist", "_blank", "noopener,noreferrer")
}>
{t("docs")}
</Button>
)}
</div>
}
/>
}
totalRowCount={totalRowCount}
/>
<BlocklistEntryDetailsSheet
entry={selectedEntry}
isOpen={showDetailsSheet}
onClose={() => {
setShowDetailsSheet(false);
setSelectedEntry(null);
}}
handleDeleteBlocklistEntry={handleDelete}
/>
<Dialog open={showDeleteDialog} onOpenChange={setShowDeleteDialog}>
<ConfirmationDialogContent
variety="danger"
title={t("remove_value_from_blocklist", { value: entryToDelete?.value })}
confirmBtn={
<DialogClose color="destructive" onClick={confirmDelete}>
{t("remove")}
</DialogClose>
}>
{t("remove_value_from_blocklist_description")}
</ConfirmationDialogContent>
</Dialog>
</>
);
}
@@ -1,157 +0,0 @@
"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 { 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];
interface BlocklistEntryDetailsSheetProps {
entry: BlocklistEntry | null;
isOpen: boolean;
onClose: () => void;
handleDeleteBlocklistEntry: (entry: BlocklistEntry) => void;
}
export function BlocklistEntryDetailsSheet({
entry,
isOpen,
onClose,
handleDeleteBlocklistEntry,
}: BlocklistEntryDetailsSheetProps) {
const { t } = useLocale();
const { data, isLoading } = trpc.viewer.organizations.getWatchlistEntryDetails.useQuery(
{ id: entry?.id ?? "" },
{
enabled: !!entry?.id && isOpen,
}
);
return (
<Sheet
open={isOpen}
onOpenChange={(open) => {
if (!open) onClose();
}}>
<SheetContent className="px-0 pb-0 sm:max-w-xl sm:px-0 sm:pb-0">
<SheetHeader className="px-6">
<SheetTitle>{entry?.value}</SheetTitle>
</SheetHeader>
<SheetBody className="px-6">
{isLoading ? (
<div className="mt-3 stack-y-3">
<SkeletonText className="h-6 w-32" />
<SkeletonText className="h-40 w-full" />
</div>
) : data?.entry ? (
<div className="mt-3 stack-y-6">
<div className="bg-subtle rounded-xl p-1">
<h2 className="text-default p-5 text-sm font-semibold">{t("details")}</h2>
<div className="bg-default stack-y-3 rounded-xl p-5">
<div>
<label className="text-default block text-sm font-semibold">
{data.entry.type === "EMAIL" ? t("email") : t("domain")}
</label>
<p className="text-subtle text-sm">{data.entry.value}</p>
</div>
<div>
<label className="text-default block text-sm font-semibold">{t("type")}</label>
<p className="text-subtle text-sm">
{data.entry.type === "EMAIL" ? t("email") : t("domain")}
</p>
</div>
<div>
<label className="text-default block text-sm font-semibold">{t("blocked_by")}</label>
<p className="text-subtle text-sm">{data.auditHistory[0]?.changedByUser?.email || "—"}</p>
</div>
<div>
<label className="text-default block text-sm font-semibold">{t("description")}</label>
<p className="text-subtle text-sm">
{data.entry.description || t("no_description_provided")}
</p>
</div>
{data.entry.bookingReports && data.entry.bookingReports.length > 0 && (
<div>
<label className="text-default block text-sm font-semibold">
{t("related_booking")}
</label>
{data.entry.bookingReports.map((report) => {
return (
<Link key={report.booking.uid} href={`/booking/${report.booking.uid}`}>
<div className="text-subtle flex items-center gap-1 text-sm">
{report.booking.title}
<Icon name="external-link" className="h-4 w-4" />
</div>
</Link>
);
})}
</div>
)}
</div>
</div>
<div className="bg-subtle rounded-xl p-1">
<h2 className="text-default p-5 text-sm font-semibold">{t("history")}</h2>
{data.auditHistory.length > 0 ? (
<div className="stack-y-3">
{data.auditHistory.map((audit) => (
<div key={audit.id} className="bg-default border-subtle rounded-xl border p-4">
<div className="flex items-start justify-between">
<div>
<span className="text-default text-sm font-semibold">
{audit.changedByUser?.name || audit.changedByUser?.email || "—"}
</span>
<span className="text-subtle text-sm"> {t("added")}</span>
<div className="text-default mt-1 text-sm font-semibold">{audit.value}</div>
</div>
<span className="text-subtle text-sm">
{format(new Date(audit.changedAt), "MMM d, h:mm a")}
</span>
</div>
</div>
))}
</div>
) : (
<p className="text-subtle text-sm">{t("no_audit_history")}</p>
)}
</div>
</div>
) : (
<div className="text-muted mt-8 text-center">{t("blocklist_entry_not_found")}</div>
)}
</SheetBody>
<SheetFooter className="bg-muted px-6 py-5">
<Button
type="button"
color="secondary"
onClick={() => entry && handleDeleteBlocklistEntry(entry)}
disabled={!entry}>
{t("remove_from_blocklist")}
</Button>
</SheetFooter>
</SheetContent>
</Sheet>
);
}
@@ -1,208 +0,0 @@
"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<FormData>({
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<string, string> = {
SPAM: t("spam"),
DONT_KNOW_PERSON: t("dont_know_person"),
OTHER: t("other"),
};
if (!entry) return null;
return (
<Dialog open={isOpen} onOpenChange={onClose}>
<DialogContent enableOverflow>
<DialogHeader title={t("review_report") + ` - ${entry.bookerEmail}`} />
<form onSubmit={handleSubmit(onSubmit)}>
<div className="stack-y-5">
<div className="bg-subtle rounded-xl p-1">
<h2 className="text-emphasis px-5 py-4 text-base font-semibold">{t("details")}</h2>
<div className="bg-default stack-y-4 rounded-xl p-5">
<div>
<label className="text-emphasis mb-1 block text-sm font-semibold">{t("email")}</label>
<p className="text-subtle text-sm">{entry.bookerEmail}</p>
</div>
<div>
<label className="text-emphasis mb-1 block text-sm font-semibold">{t("reason")}</label>
<p className="text-subtle text-sm">{reasonMap[entry.reason] || entry.reason}</p>
</div>
<div>
<label className="text-emphasis mb-1 block text-sm font-semibold">{t("reported_by")}</label>
<p className="text-subtle text-sm">{entry.reporter?.email || "—"}</p>
</div>
<div>
<label className="text-emphasis mb-1 block text-sm font-semibold">{t("description")}</label>
<p className="text-subtle text-sm">{entry.description || t("no_description_provided")}</p>
</div>
<div>
<label className="text-emphasis mb-1 block text-sm font-semibold">
{t("related_booking")}
</label>
<Link href={`/booking/${entry.booking.uid}`}>
<div className="text-subtle flex items-center gap-1 text-sm">
{entry.booking.title}
<Icon name="external-link" className="h-4 w-4" />
</div>
</Link>
</div>
</div>
</div>
<div>
<h2 className="text-emphasis mb-2 text-base font-semibold">
{t("what_would_you_like_to_block")}
</h2>
<Controller
name="blockType"
control={control}
render={({ field }) => (
<ToggleGroup
value={field.value}
onValueChange={(value) => {
if (value) field.onChange(value);
}}
options={[
{
value: WatchlistType.EMAIL,
label: t("block_this_email"),
iconLeft: <Icon name="mail" className="h-4 w-4" />,
},
{
value: WatchlistType.DOMAIN,
label: t("block_all_from_domain"),
iconLeft: <Icon name="globe" className="h-4 w-4" />,
},
]}
/>
)}
/>
</div>
</div>
<DialogFooter className="mt-6">
<div className="flex w-full items-center justify-between">
<Button
type="button"
color="minimal"
onClick={handleGoBack}
disabled={isSubmitting || addToWatchlist.isPending || dismissBookingReport.isPending}>
{t("go_back")}
</Button>
<div className="flex gap-2">
<Button
type="button"
color="secondary"
onClick={handleDismiss}
loading={dismissBookingReport.isPending}
disabled={isSubmitting || addToWatchlist.isPending || dismissBookingReport.isPending}>
{t("dont_block")}
</Button>
<Button
type="submit"
loading={isSubmitting || addToWatchlist.isPending}
disabled={isSubmitting || addToWatchlist.isPending || dismissBookingReport.isPending}>
{t("add_to_blocklist")}
</Button>
</div>
</div>
</DialogFooter>
</form>
</DialogContent>
</Dialog>
);
}
@@ -1,172 +0,0 @@
"use client";
import { Controller, useForm } from "react-hook-form";
import { domainRegex, emailRegex } from "@calcom/lib/emailSchema";
import { useLocale } from "@calcom/lib/hooks/useLocale";
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, Label, TextArea, ToggleGroup } from "@calcom/ui/components/form";
import { Icon } from "@calcom/ui/components/icon";
import { showToast } from "@calcom/ui/components/toast";
interface CreateBlocklistEntryModalProps {
isOpen: boolean;
onClose: () => void;
}
interface FormData {
type: WatchlistType;
value: string;
description?: string;
}
export function CreateBlocklistEntryModal({ isOpen, onClose }: CreateBlocklistEntryModalProps) {
const { t } = useLocale();
const utils = trpc.useUtils();
const {
control,
handleSubmit,
watch,
setValue,
reset,
formState: { errors, isSubmitting },
} = useForm<FormData>({
defaultValues: {
type: WatchlistType.EMAIL,
value: "",
description: "",
},
});
const watchType = watch("type");
const createWatchlistEntry = trpc.viewer.organizations.createWatchlistEntry.useMutation({
onSuccess: async () => {
await utils.viewer.organizations.listWatchlistEntries.invalidate();
showToast(t("blocklist_entry_created"), "success");
onClose();
reset();
},
onError: (error) => {
showToast(error.message, "error");
},
});
const onSubmit = (data: FormData) => {
createWatchlistEntry.mutate({
type: data.type,
value: data.value,
description: data.description,
});
};
const validateValue = (value: string) => {
if (!value) return t("required");
if (watchType === WatchlistType.EMAIL) {
if (!emailRegex.test(value)) {
return t("invalid_email_address");
}
} else if (watchType === WatchlistType.DOMAIN) {
if (!domainRegex.test(value)) {
return t("invalid_domain_format");
}
}
return true;
};
const typeOptions = [
{ label: t("email"), value: WatchlistType.EMAIL, iconLeft: <Icon name="mail" className="h-4 w-4" /> },
{ label: t("domain"), value: WatchlistType.DOMAIN, iconLeft: <Icon name="globe" className="h-4 w-4" /> },
];
return (
<Dialog open={isOpen} onOpenChange={onClose}>
<DialogContent enableOverflow>
<DialogHeader title={t("add_to_blocklist")} />
<form onSubmit={handleSubmit(onSubmit)}>
<div className="stack-y-4">
<div>
<Label htmlFor="type" className="text-emphasis mb-2 block text-sm font-medium">
{t("what_would_you_like_to_block")}
</Label>
<Controller
name="type"
control={control}
rules={{ required: t("field_required") }}
render={({ field }) => (
<ToggleGroup
value={field.value}
onValueChange={(value) => {
if (value) {
field.onChange(value);
setValue("value", "");
}
}}
options={typeOptions}
/>
)}
/>
{errors.type && <p className="text-destructive mt-1 text-sm">{errors.type.message}</p>}
</div>
<div>
<Label htmlFor="value" className="text-emphasis mb-2 block text-sm font-medium">
{watchType === WatchlistType.EMAIL ? t("email") : t("domain_name")}{" "}
</Label>
<Controller
name="value"
control={control}
rules={{
required: t("field_required"),
validate: validateValue,
}}
render={({ field }) => (
<Input
{...field}
placeholder={watchType === WatchlistType.EMAIL ? "[email protected]" : "spammer.com"}
/>
)}
/>
{errors.value && <p className="text-destructive mt-1 text-sm">{errors.value.message}</p>}
</div>
<div>
<Label htmlFor="description" className="text-emphasis mb-2 block text-sm font-medium">
{t("description")} <span className="text-muted font-normal">{t("optional")}</span>
</Label>
<Controller
name="description"
control={control}
render={({ field }) => (
<TextArea {...field} placeholder={t("reason_for_adding_to_blocklist")} rows={3} />
)}
/>
</div>
</div>
<DialogFooter className="mt-6">
<Button
type="button"
color="secondary"
onClick={onClose}
disabled={isSubmitting || createWatchlistEntry.isPending}>
{t("cancel")}
</Button>
<Button
type="submit"
loading={isSubmitting || createWatchlistEntry.isPending}
disabled={isSubmitting || createWatchlistEntry.isPending}>
{t("add_to_blocklist")}
</Button>
</DialogFooter>
</form>
</DialogContent>
</Dialog>
);
}
@@ -1,90 +0,0 @@
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 BookingReport = RouterOutputs["viewer"]["organizations"]["listBookingReports"]["rows"][number];
interface UsePendingReportsColumnsProps {
t: (key: string) => string;
onViewDetails: (entry: BookingReport) => void;
}
export function usePendingReportsColumns({ t, onViewDetails }: UsePendingReportsColumnsProps) {
return useMemo<ColumnDef<BookingReport>[]>(
() => [
{
id: "emailOrDomain",
header: t("email_slash_domain"),
accessorKey: "bookerEmail",
enableHiding: false,
size: 250,
cell: ({ row }) => {
const email = row.original.bookerEmail;
return (
<div className="flex flex-col">
<span className="text-emphasis font-medium">{email}</span>
</div>
);
},
},
{
id: "reportedBy",
header: t("reported_by"),
accessorFn: (row) => row.reporter?.email ?? "-",
size: 250,
cell: ({ row }) => <span className="text-default">{row.original.reporter?.email ?? "-"}</span>,
},
{
id: "reason",
header: t("reason"),
size: 150,
cell: ({ row }) => {
const reason = t(row.original.reason.toLowerCase());
const capitalizedReason = reason.charAt(0).toUpperCase() + reason.slice(1);
return <Badge variant="blue">{capitalizedReason}</Badge>;
},
},
{
id: "actions",
header: "",
size: 90,
minSize: 90,
maxSize: 90,
enableHiding: false,
enableSorting: false,
enableResizing: false,
cell: ({ row }) => {
const entry = row.original;
return (
<div className="flex items-center justify-end">
<Dropdown modal={false}>
<DropdownMenuTrigger asChild>
<Button type="button" variant="icon" color="secondary" StartIcon="ellipsis" />
</DropdownMenuTrigger>
<DropdownMenuContent>
<DropdownMenuItem>
<DropdownItem type="button" StartIcon="eye" onClick={() => onViewDetails(entry)}>
{t("view_details")}
</DropdownItem>
</DropdownMenuItem>
</DropdownMenuContent>
</Dropdown>
</div>
);
},
},
],
[t, onViewDetails]
);
}
@@ -1,89 +0,0 @@
"use client";
import { keepPreviousData } from "@tanstack/react-query";
import { getCoreRowModel, getSortedRowModel, useReactTable } from "@tanstack/react-table";
import { useMemo, useState } from "react";
import { useDataTable } from "@calcom/features/data-table";
import { DataTableWrapper } from "~/data-table/components";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { trpc } from "@calcom/trpc/react";
import type { RouterOutputs } from "@calcom/trpc/react";
import { EmptyScreen } from "@calcom/ui/components/empty-screen";
import { BookingReportEntryDetailsModal } from "./booking-report-entry-details-modal";
import { usePendingReportsColumns } from "./pending-reports-columns";
type BookingReport = RouterOutputs["viewer"]["organizations"]["listBookingReports"]["rows"][number];
export function PendingReportsTable() {
const { t } = useLocale();
const { limit, offset, searchTerm } = useDataTable();
const [showReviewDialog, setShowReviewDialog] = useState(false);
const [selectedReport, setSelectedReport] = useState<BookingReport | null>(null);
const { data, isPending } = trpc.viewer.organizations.listBookingReports.useQuery(
{
limit,
offset,
searchTerm,
filters: { hasWatchlist: false, status: ["PENDING"] },
},
{
placeholderData: keepPreviousData,
}
);
const handleViewDetails = (entry: BookingReport) => {
setSelectedReport(entry);
setShowReviewDialog(true);
};
const columns = usePendingReportsColumns({
t,
onViewDetails: handleViewDetails,
});
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 (
<>
<DataTableWrapper
table={table}
isPending={isPending}
variant="default"
paginationMode="standard"
EmptyView={
<EmptyScreen
customIcon={<img className="mb-6" src="/slash-icon-cards.svg" />}
headline={t("no_pending_reports")}
className="bg-muted mb-16"
iconWrapperClassName="bg-default"
dashedBorder={false}
/>
}
totalRowCount={totalRowCount}
/>
<BookingReportEntryDetailsModal
entry={selectedReport}
isOpen={showReviewDialog}
onClose={() => {
setShowReviewDialog(false);
setSelectedReport(null);
}}
/>
</>
);
}