refactor: remove 3 @calcom/web imports from @calcom/features by relocating blocklist UI and useEvent hook (#27775)
* migrate blocklist components to web * migrate useEvent * fix * fix * rm barrel file * dead code
This commit is contained in:
1 parent
cdf901fee3
commit
29bb4fd497
19 files changed
+18
-23
No files matched your search
@@ -1,167 +0,0 @@
|
||||
"use client";
|
||||
|
||||
import type { ColumnDef } from "@tanstack/react-table";
|
||||
import { useMemo } from "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";
|
||||
import { Checkbox } from "@calcom/ui/components/form";
|
||||
|
||||
import type { BlocklistEntry, BlocklistScope } from "../types";
|
||||
|
||||
interface UseBlockedEntriesColumnsProps<T extends BlocklistEntry> {
|
||||
t: (key: string) => string;
|
||||
scope: BlocklistScope;
|
||||
canDelete?: boolean;
|
||||
enableRowSelection?: boolean;
|
||||
onViewDetails: (entry: T) => void;
|
||||
onDelete: (entry: T) => void;
|
||||
}
|
||||
|
||||
export function useBlockedEntriesColumns<T extends BlocklistEntry>({
|
||||
t,
|
||||
scope,
|
||||
canDelete = true,
|
||||
enableRowSelection = false,
|
||||
onViewDetails,
|
||||
onDelete,
|
||||
}: UseBlockedEntriesColumnsProps<T>) {
|
||||
const isSystem = scope === "system";
|
||||
|
||||
return useMemo<ColumnDef<T>[]>(() => {
|
||||
const columns: ColumnDef<T>[] = [];
|
||||
|
||||
if (enableRowSelection) {
|
||||
columns.push({
|
||||
id: "select",
|
||||
header: ({ table }) => (
|
||||
<Checkbox
|
||||
checked={table.getIsAllPageRowsSelected()}
|
||||
onCheckedChange={(value) => table.toggleAllPageRowsSelected(!!value)}
|
||||
aria-label={t("select_all")}
|
||||
/>
|
||||
),
|
||||
cell: ({ row }) => (
|
||||
<Checkbox
|
||||
checked={row.getIsSelected()}
|
||||
onCheckedChange={(value) => row.toggleSelected(!!value)}
|
||||
aria-label={t("select_row")}
|
||||
/>
|
||||
),
|
||||
enableSorting: false,
|
||||
enableHiding: false,
|
||||
size: 24,
|
||||
minSize: 24,
|
||||
maxSize: 24,
|
||||
});
|
||||
}
|
||||
|
||||
columns.push(
|
||||
{
|
||||
id: "email_slash_domain",
|
||||
header: t("email_slash_domain"),
|
||||
accessorKey: "value",
|
||||
enableHiding: false,
|
||||
cell: ({ row }) => (
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-emphasis">{row.original.value}</span>
|
||||
{row.original.isGlobal && !isSystem && (
|
||||
<Badge variant="gray" className="text-xs">
|
||||
{t("system_blocked")}
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: "type",
|
||||
header: t("type"),
|
||||
accessorKey: "type",
|
||||
size: 100,
|
||||
cell: ({ row }) => (
|
||||
<Badge variant="blue">{row.original.type === "EMAIL" ? t("email") : t("domain")}</Badge>
|
||||
),
|
||||
}
|
||||
);
|
||||
|
||||
if (isSystem) {
|
||||
columns.push({
|
||||
id: "source",
|
||||
header: t("source"),
|
||||
accessorKey: "source",
|
||||
size: 120,
|
||||
cell: ({ row }) => {
|
||||
const source = row.original.source;
|
||||
let label = t("manual");
|
||||
if (source === "FREE_DOMAIN_POLICY") {
|
||||
label = t("free_domain_policy");
|
||||
}
|
||||
return <span className="text-default">{label}</span>;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
columns.push({
|
||||
id: "createdBy",
|
||||
header: t("blocked_by"),
|
||||
size: 180,
|
||||
cell: ({ row }) => {
|
||||
const audit = row.original.latestAudit;
|
||||
const email = audit && "changedByUser" in audit ? audit.changedByUser?.email : undefined;
|
||||
return <span className="text-default">{email ?? "—"}</span>;
|
||||
},
|
||||
});
|
||||
|
||||
columns.push({
|
||||
id: "actions",
|
||||
header: "",
|
||||
size: 90,
|
||||
minSize: 90,
|
||||
maxSize: 90,
|
||||
enableHiding: false,
|
||||
enableSorting: false,
|
||||
enableResizing: false,
|
||||
cell: ({ row }) => {
|
||||
const entry = row.original;
|
||||
const isEntryReadOnly = entry.isReadOnly === true;
|
||||
const showDeleteOption = canDelete && !isEntryReadOnly;
|
||||
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>
|
||||
{showDeleteOption && (
|
||||
<DropdownMenuItem>
|
||||
<DropdownItem
|
||||
type="button"
|
||||
color="destructive"
|
||||
StartIcon="trash"
|
||||
onClick={() => onDelete(entry)}>
|
||||
{t("remove_from_blocklist")}
|
||||
</DropdownItem>
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</Dropdown>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
return columns;
|
||||
}, [t, scope, isSystem, canDelete, enableRowSelection, onViewDetails, onDelete]);
|
||||
}
|
||||
@@ -1,217 +0,0 @@
|
||||
"use client";
|
||||
|
||||
import type { RowSelectionState } from "@tanstack/react-table";
|
||||
import { getCoreRowModel, getSortedRowModel, useReactTable } from "@tanstack/react-table";
|
||||
import type { ReactNode } from "react";
|
||||
import { useMemo, useState } from "react";
|
||||
|
||||
import { DataTableSelectionBar, DataTableWrapper } from "~/data-table/components";
|
||||
import { IS_CALCOM } from "@calcom/lib/constants";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { Button } from "@calcom/ui/components/button";
|
||||
import { ConfirmationDialogContent, Dialog } from "@calcom/ui/components/dialog";
|
||||
import { EmptyScreen } from "@calcom/ui/components/empty-screen";
|
||||
|
||||
import type { BlocklistEntry, BlocklistPermissions, BlocklistScope } from "../types";
|
||||
import { useBlockedEntriesColumns } from "./BlockedEntriesColumns";
|
||||
import { BlocklistEntryDetailsSheet } from "./BlocklistEntryDetailsSheet";
|
||||
|
||||
export interface BlockedEntriesTableProps<T extends BlocklistEntry> {
|
||||
scope: BlocklistScope;
|
||||
data: T[];
|
||||
totalRowCount: number;
|
||||
isPending: boolean;
|
||||
limit: number;
|
||||
searchTerm?: string;
|
||||
permissions?: BlocklistPermissions;
|
||||
onAddClick: () => void;
|
||||
onDelete: (entry: T) => void;
|
||||
isDeleting?: boolean;
|
||||
detailsQuery?: {
|
||||
data?: {
|
||||
entry: {
|
||||
id: string;
|
||||
value: string;
|
||||
type: import("@calcom/prisma/enums").WatchlistType;
|
||||
description: string | null;
|
||||
source?: string;
|
||||
bookingReports?: Array<{ booking: { uid: string; title: string | null } }>;
|
||||
};
|
||||
auditHistory: Array<{
|
||||
id: string;
|
||||
value: string;
|
||||
changedAt: Date | string;
|
||||
changedByUser?: { name: string | null; email: string } | null;
|
||||
}>;
|
||||
};
|
||||
isLoading: boolean;
|
||||
};
|
||||
selectedEntryId?: string;
|
||||
onSelectEntry?: (id: string | null) => void;
|
||||
enableRowSelection?: boolean;
|
||||
renderBulkActions?: (selectedEntries: T[], clearSelection: () => void) => ReactNode;
|
||||
}
|
||||
|
||||
export function BlockedEntriesTable<T extends BlocklistEntry>({
|
||||
scope,
|
||||
data,
|
||||
totalRowCount,
|
||||
isPending,
|
||||
limit,
|
||||
searchTerm,
|
||||
permissions,
|
||||
onAddClick,
|
||||
onDelete,
|
||||
isDeleting = false,
|
||||
detailsQuery,
|
||||
selectedEntryId,
|
||||
onSelectEntry,
|
||||
enableRowSelection = false,
|
||||
renderBulkActions,
|
||||
}: BlockedEntriesTableProps<T>) {
|
||||
const { t } = useLocale();
|
||||
const isSystem = scope === "system";
|
||||
|
||||
const [rowSelection, setRowSelection] = useState<RowSelectionState>({});
|
||||
const [showDetailsSheet, setShowDetailsSheet] = useState(false);
|
||||
const [selectedEntry, setSelectedEntry] = useState<T | null>(null);
|
||||
const [entryToDelete, setEntryToDelete] = useState<T | null>(null);
|
||||
const [showDeleteDialog, setShowDeleteDialog] = useState(false);
|
||||
|
||||
const handleViewDetails = (entry: T) => {
|
||||
setSelectedEntry(entry);
|
||||
setShowDetailsSheet(true);
|
||||
onSelectEntry?.(entry.id);
|
||||
};
|
||||
|
||||
const handleDelete = (entry: T) => {
|
||||
setEntryToDelete(entry);
|
||||
setShowDeleteDialog(true);
|
||||
};
|
||||
|
||||
const confirmDelete = () => {
|
||||
if (entryToDelete) {
|
||||
onDelete(entryToDelete);
|
||||
setShowDeleteDialog(false);
|
||||
setEntryToDelete(null);
|
||||
}
|
||||
};
|
||||
|
||||
const handleCloseDetailsSheet = () => {
|
||||
setShowDetailsSheet(false);
|
||||
setSelectedEntry(null);
|
||||
onSelectEntry?.(null);
|
||||
};
|
||||
|
||||
const canDelete = isSystem || permissions?.canDelete;
|
||||
|
||||
const columns = useBlockedEntriesColumns<T>({
|
||||
t,
|
||||
scope,
|
||||
canDelete,
|
||||
enableRowSelection,
|
||||
onViewDetails: handleViewDetails,
|
||||
onDelete: handleDelete,
|
||||
});
|
||||
|
||||
const flatData = useMemo(() => data ?? [], [data]);
|
||||
|
||||
const table = useReactTable({
|
||||
data: flatData,
|
||||
columns,
|
||||
getCoreRowModel: getCoreRowModel(),
|
||||
getSortedRowModel: getSortedRowModel(),
|
||||
manualPagination: true,
|
||||
pageCount: Math.ceil(totalRowCount / limit),
|
||||
enableRowSelection,
|
||||
onRowSelectionChange: setRowSelection,
|
||||
state: {
|
||||
rowSelection,
|
||||
},
|
||||
getRowId: (row) => row.id,
|
||||
});
|
||||
|
||||
const numberOfSelectedRows = table.getFilteredSelectedRowModel().rows.length;
|
||||
const selectedEntries = table.getSelectedRowModel().flatRows.map((row) => row.original);
|
||||
const clearSelection = () => table.toggleAllPageRowsSelected(false);
|
||||
|
||||
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(isSystem ? "system_blocklist" : "pbac_resource_blocklist")
|
||||
}
|
||||
description={t(isSystem ? "add_people_to_system_blocklist" : "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={!isSystem && !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}>
|
||||
{enableRowSelection && numberOfSelectedRows > 0 && renderBulkActions && (
|
||||
<DataTableSelectionBar.Root className="bottom-16! justify-center md:w-max">
|
||||
<p className="text-brand-subtle px-2 text-center text-xs leading-none sm:text-sm sm:font-medium">
|
||||
{t("number_selected", { count: numberOfSelectedRows })}
|
||||
</p>
|
||||
{renderBulkActions(selectedEntries, clearSelection)}
|
||||
</DataTableSelectionBar.Root>
|
||||
)}
|
||||
</DataTableWrapper>
|
||||
|
||||
<BlocklistEntryDetailsSheet
|
||||
scope={scope}
|
||||
entry={selectedEntry}
|
||||
isOpen={showDetailsSheet}
|
||||
onClose={handleCloseDetailsSheet}
|
||||
handleDeleteBlocklistEntry={handleDelete}
|
||||
detailsData={detailsQuery?.data}
|
||||
isLoading={detailsQuery?.isLoading ?? false}
|
||||
/>
|
||||
|
||||
<Dialog open={showDeleteDialog} onOpenChange={setShowDeleteDialog}>
|
||||
<ConfirmationDialogContent
|
||||
variety="danger"
|
||||
title={t(isSystem ? "remove_value_from_system_blocklist" : "remove_value_from_blocklist", {
|
||||
value: entryToDelete?.value,
|
||||
})}
|
||||
confirmBtnText={t("remove")}
|
||||
isPending={isDeleting}
|
||||
onConfirm={confirmDelete}>
|
||||
{t(
|
||||
isSystem ? "remove_value_from_system_blocklist_description" : "remove_value_from_blocklist_description"
|
||||
)}
|
||||
</ConfirmationDialogContent>
|
||||
</Dialog>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -1,187 +0,0 @@
|
||||
"use client";
|
||||
|
||||
import { format } from "date-fns";
|
||||
import Link from "next/link";
|
||||
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { Badge } from "@calcom/ui/components/badge";
|
||||
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";
|
||||
|
||||
import type { BlocklistEntry, BlocklistEntryDetails, BlocklistScope } from "../types";
|
||||
|
||||
export interface BlocklistEntryDetailsSheetProps<T extends BlocklistEntry> {
|
||||
scope: BlocklistScope;
|
||||
entry: T | null;
|
||||
isOpen: boolean;
|
||||
onClose: () => void;
|
||||
handleDeleteBlocklistEntry: (entry: T) => void;
|
||||
detailsData?: BlocklistEntryDetails;
|
||||
isLoading: boolean;
|
||||
}
|
||||
|
||||
export function BlocklistEntryDetailsSheet<T extends BlocklistEntry>({
|
||||
scope,
|
||||
entry,
|
||||
isOpen,
|
||||
onClose,
|
||||
handleDeleteBlocklistEntry,
|
||||
detailsData,
|
||||
isLoading,
|
||||
}: BlocklistEntryDetailsSheetProps<T>) {
|
||||
const { t } = useLocale();
|
||||
const isSystem = scope === "system";
|
||||
|
||||
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">
|
||||
{isSystem ? (
|
||||
<div className="flex items-center gap-2">
|
||||
<SheetTitle>{entry?.value}</SheetTitle>
|
||||
<Badge variant="gray">{t("system_wide")}</Badge>
|
||||
</div>
|
||||
) : (
|
||||
<SheetTitle>{entry?.value}</SheetTitle>
|
||||
)}
|
||||
</SheetHeader>
|
||||
|
||||
<SheetBody className="px-6">
|
||||
{isLoading ? (
|
||||
<div className="mt-3 space-y-3">
|
||||
<SkeletonText className="h-6 w-32" />
|
||||
<SkeletonText className="h-40 w-full" />
|
||||
</div>
|
||||
) : detailsData?.entry ? (
|
||||
<div className="mt-3 space-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 space-y-3 rounded-xl p-5">
|
||||
<div>
|
||||
<label className="text-default block text-sm font-semibold">
|
||||
{detailsData.entry.type === "EMAIL" ? t("email") : t("domain")}
|
||||
</label>
|
||||
<p className="text-subtle text-sm">{detailsData.entry.value}</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="text-default block text-sm font-semibold">{t("type")}</label>
|
||||
<p className="text-subtle text-sm">
|
||||
{detailsData.entry.type === "EMAIL" ? t("email") : t("domain")}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{isSystem && (
|
||||
<>
|
||||
<div>
|
||||
<label className="text-default block text-sm font-semibold">{t("scope")}</label>
|
||||
<Badge variant="gray">{t("system_wide_all_organizations")}</Badge>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="text-default block text-sm font-semibold">{t("source")}</label>
|
||||
<p className="text-subtle text-sm">
|
||||
{detailsData.entry.source === "MANUAL"
|
||||
? t("manual")
|
||||
: detailsData.entry.source === "FREE_DOMAIN_POLICY"
|
||||
? t("free_domain_policy")
|
||||
: t("automatic")}
|
||||
</p>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
<div>
|
||||
<label className="text-default block text-sm font-semibold">
|
||||
{t(isSystem ? "blocked_by_system_admin" : "blocked_by")}
|
||||
</label>
|
||||
<p className="text-subtle text-sm">
|
||||
{detailsData.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">
|
||||
{detailsData.entry.description || t("no_description_provided")}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{detailsData.entry.bookingReports && detailsData.entry.bookingReports.length > 0 && (
|
||||
<div>
|
||||
<label className="text-default block text-sm font-semibold">
|
||||
{t("related_booking")}
|
||||
</label>
|
||||
|
||||
{detailsData.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>
|
||||
{detailsData.auditHistory.length > 0 ? (
|
||||
<div className="space-y-3">
|
||||
{detailsData.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(isSystem ? "remove_from_system_blocklist" : "remove_from_blocklist")}
|
||||
</Button>
|
||||
</SheetFooter>
|
||||
</SheetContent>
|
||||
</Sheet>
|
||||
);
|
||||
}
|
||||
@@ -1,206 +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 { 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 type { GroupedBookingReport, BlocklistScope } from "../types";
|
||||
|
||||
interface FormData {
|
||||
blockType: WatchlistType;
|
||||
}
|
||||
|
||||
export interface BookingReportDetailsModalProps<T extends GroupedBookingReport> {
|
||||
scope: BlocklistScope;
|
||||
entry: T | null;
|
||||
isOpen: boolean;
|
||||
onClose: () => void;
|
||||
onAddToBlocklist: (email: string, type: WatchlistType) => void;
|
||||
onDismiss: (email: string) => void;
|
||||
isAddingToBlocklist?: boolean;
|
||||
isDismissing?: boolean;
|
||||
}
|
||||
|
||||
export function BookingReportDetailsModal<T extends GroupedBookingReport>({
|
||||
scope,
|
||||
entry,
|
||||
isOpen,
|
||||
onClose,
|
||||
onAddToBlocklist,
|
||||
onDismiss,
|
||||
isAddingToBlocklist = false,
|
||||
isDismissing = false,
|
||||
}: BookingReportDetailsModalProps<T>) {
|
||||
const { t } = useLocale();
|
||||
const isSystem = scope === "system";
|
||||
|
||||
const {
|
||||
control,
|
||||
handleSubmit,
|
||||
reset,
|
||||
formState: { isSubmitting },
|
||||
} = useForm<FormData>({
|
||||
defaultValues: {
|
||||
blockType: WatchlistType.EMAIL,
|
||||
},
|
||||
});
|
||||
|
||||
const onSubmit = (data: FormData) => {
|
||||
if (!entry) return;
|
||||
onAddToBlocklist(entry.bookerEmail, data.blockType);
|
||||
};
|
||||
|
||||
const handleDismiss = () => {
|
||||
if (!entry) return;
|
||||
onDismiss(entry.bookerEmail);
|
||||
};
|
||||
|
||||
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="space-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 space-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>
|
||||
|
||||
{isSystem && entry.organization && (
|
||||
<div>
|
||||
<label className="text-emphasis mb-1 block text-sm font-semibold">
|
||||
{t("organization")}
|
||||
</label>
|
||||
<p className="text-subtle text-sm">{entry.organization.name}</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{isSystem && !entry.organization && (
|
||||
<div>
|
||||
<label className="text-emphasis mb-1 block text-sm font-semibold">
|
||||
{t("organization")}
|
||||
</label>
|
||||
<p className="text-subtle text-sm">{t("individual")}</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_bookings")} ({entry.reports.length})
|
||||
</label>
|
||||
<div className="max-h-32 space-y-1 overflow-y-auto">
|
||||
{entry.reports.map((report) => (
|
||||
<Link key={report.id} href={`/booking/${report.booking.uid}`}>
|
||||
<div className="text-subtle hover:text-emphasis flex items-center gap-1 text-sm">
|
||||
{report.booking.title || t("untitled")}
|
||||
<Icon name="external-link" className="h-3 w-3" />
|
||||
</div>
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<h2 className="text-emphasis mb-2 text-base font-semibold">
|
||||
{t("what_would_you_like_to_block")}
|
||||
</h2>
|
||||
{isSystem && <p className="text-subtle mb-3 text-sm">{t("system_wide_blocklist_warning")}</p>}
|
||||
<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 || isAddingToBlocklist || isDismissing}>
|
||||
{t("go_back")}
|
||||
</Button>
|
||||
|
||||
<div className="flex gap-2">
|
||||
<Button
|
||||
type="button"
|
||||
color="secondary"
|
||||
onClick={handleDismiss}
|
||||
loading={isDismissing}
|
||||
disabled={isSubmitting || isAddingToBlocklist || isDismissing}>
|
||||
{t("dont_block")}
|
||||
</Button>
|
||||
<Button
|
||||
type="submit"
|
||||
loading={isSubmitting || isAddingToBlocklist}
|
||||
disabled={isSubmitting || isAddingToBlocklist || isDismissing}>
|
||||
{t(isSystem ? "add_to_system_blocklist" : "add_to_blocklist")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</DialogFooter>
|
||||
</form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -1,174 +0,0 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect } from "react";
|
||||
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 { Alert } from "@calcom/ui/components/alert";
|
||||
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 type { BlocklistScope, CreateBlocklistEntryFormData } from "../types";
|
||||
|
||||
export interface CreateBlocklistEntryModalProps {
|
||||
isOpen: boolean;
|
||||
onClose: () => void;
|
||||
scope: BlocklistScope;
|
||||
onCreateEntry: (data: CreateBlocklistEntryFormData) => void;
|
||||
isPending: boolean;
|
||||
}
|
||||
|
||||
export function CreateBlocklistEntryModal({
|
||||
isOpen,
|
||||
onClose,
|
||||
scope,
|
||||
onCreateEntry,
|
||||
isPending,
|
||||
}: CreateBlocklistEntryModalProps) {
|
||||
const { t } = useLocale();
|
||||
const isSystem = scope === "system";
|
||||
|
||||
const {
|
||||
control,
|
||||
handleSubmit,
|
||||
watch,
|
||||
setValue,
|
||||
reset,
|
||||
formState: { errors, isSubmitting },
|
||||
} = useForm<CreateBlocklistEntryFormData>({
|
||||
defaultValues: {
|
||||
type: WatchlistType.EMAIL,
|
||||
value: "",
|
||||
description: "",
|
||||
},
|
||||
});
|
||||
|
||||
const watchType = watch("type");
|
||||
|
||||
useEffect(() => {
|
||||
if (isOpen) {
|
||||
reset();
|
||||
}
|
||||
}, [isOpen, reset]);
|
||||
|
||||
const onSubmit = (data: CreateBlocklistEntryFormData) => {
|
||||
onCreateEntry(data);
|
||||
};
|
||||
|
||||
const handleClose = () => {
|
||||
onClose();
|
||||
reset();
|
||||
};
|
||||
|
||||
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) {
|
||||
const domainToValidate = value.startsWith("*.") ? value.slice(2) : value;
|
||||
if (!domainRegex.test(domainToValidate)) {
|
||||
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={handleClose}>
|
||||
<DialogContent enableOverflow>
|
||||
<DialogHeader title={t(isSystem ? "add_to_system_blocklist" : "add_to_blocklist")} />
|
||||
<form onSubmit={handleSubmit(onSubmit)}>
|
||||
<div className="space-y-4">
|
||||
{isSystem && (
|
||||
<Alert
|
||||
severity="warning"
|
||||
title={t("system_wide_blocklist_warning")}
|
||||
message={t("system_wide_blocklist_warning_description")}
|
||||
/>
|
||||
)}
|
||||
|
||||
<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={handleClose} disabled={isSubmitting || isPending}>
|
||||
{t("cancel")}
|
||||
</Button>
|
||||
<Button type="submit" loading={isSubmitting || isPending} disabled={isSubmitting || isPending}>
|
||||
{t(isSystem ? "add_to_system_blocklist" : "add_to_blocklist")}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
"use client";
|
||||
|
||||
import { Badge } from "@calcom/ui/components/badge";
|
||||
|
||||
export interface PendingReportsBadgeProps {
|
||||
count: number | undefined;
|
||||
}
|
||||
|
||||
export function PendingReportsBadge({ count }: PendingReportsBadgeProps) {
|
||||
if (!count) return null;
|
||||
return (
|
||||
<Badge variant="orange" className="ml-1 min-h-5 min-w-5 rounded-full px-1.5">
|
||||
{count}
|
||||
</Badge>
|
||||
);
|
||||
}
|
||||
@@ -1,160 +0,0 @@
|
||||
"use client";
|
||||
|
||||
import type { ColumnDef } from "@tanstack/react-table";
|
||||
import { useMemo } from "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";
|
||||
import { Checkbox } from "@calcom/ui/components/form";
|
||||
|
||||
import type { GroupedBookingReport, BlocklistScope } from "../types";
|
||||
|
||||
interface UsePendingReportsColumnsProps<T extends GroupedBookingReport> {
|
||||
t: (key: string) => string;
|
||||
scope: BlocklistScope;
|
||||
enableRowSelection?: boolean;
|
||||
onViewDetails: (entry: T) => void;
|
||||
}
|
||||
|
||||
export function usePendingReportsColumns<T extends GroupedBookingReport>({
|
||||
t,
|
||||
scope,
|
||||
enableRowSelection = false,
|
||||
onViewDetails,
|
||||
}: UsePendingReportsColumnsProps<T>) {
|
||||
const isSystem = scope === "system";
|
||||
|
||||
return useMemo<ColumnDef<T>[]>(() => {
|
||||
const columns: ColumnDef<T>[] = [];
|
||||
|
||||
if (enableRowSelection) {
|
||||
columns.push({
|
||||
id: "select",
|
||||
header: ({ table }) => (
|
||||
<Checkbox
|
||||
checked={table.getIsAllPageRowsSelected()}
|
||||
onCheckedChange={(value) => table.toggleAllPageRowsSelected(!!value)}
|
||||
aria-label="Select all"
|
||||
/>
|
||||
),
|
||||
cell: ({ row }) => (
|
||||
<Checkbox
|
||||
checked={row.getIsSelected()}
|
||||
onCheckedChange={(value) => row.toggleSelected(!!value)}
|
||||
aria-label="Select row"
|
||||
/>
|
||||
),
|
||||
enableSorting: false,
|
||||
enableHiding: false,
|
||||
size: 24,
|
||||
minSize: 24,
|
||||
maxSize: 24,
|
||||
});
|
||||
}
|
||||
|
||||
columns.push({
|
||||
id: "emailOrDomain",
|
||||
header: t("email_slash_domain"),
|
||||
accessorKey: "bookerEmail",
|
||||
enableHiding: false,
|
||||
size: isSystem ? 200 : 250,
|
||||
cell: ({ row }) => {
|
||||
const { bookerEmail, reportCount } = row.original;
|
||||
return (
|
||||
<div className="flex items-center gap-2">
|
||||
<span className={`text-emphasis ${isSystem ? "break-words text-sm" : ""} font-medium`}>
|
||||
{bookerEmail}
|
||||
</span>
|
||||
{reportCount > 1 && (
|
||||
<Badge variant="gray" size="sm">
|
||||
{reportCount}
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
if (isSystem) {
|
||||
columns.push({
|
||||
id: "organization",
|
||||
header: t("org"),
|
||||
size: 140,
|
||||
cell: ({ row }) => {
|
||||
const org = row.original.organization;
|
||||
if (!org) {
|
||||
return <span className="text-subtle text-sm">{t("individual")}</span>;
|
||||
}
|
||||
return <span className="text-default block truncate text-sm">{org.name}</span>;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
columns.push({
|
||||
id: "reportedBy",
|
||||
header: t("reported_by"),
|
||||
accessorFn: (row) => row.reporter?.email ?? "-",
|
||||
size: isSystem ? 180 : 250,
|
||||
cell: ({ row }) => (
|
||||
<span className={`text-default ${isSystem ? "wrap-break-word block text-sm" : ""}`}>
|
||||
{row.original.reporter?.email ?? "-"}
|
||||
</span>
|
||||
),
|
||||
});
|
||||
|
||||
columns.push({
|
||||
id: "reason",
|
||||
header: t("reason"),
|
||||
size: isSystem ? 120 : 150,
|
||||
cell: ({ row }) => {
|
||||
const reason = t(row.original.reason.toLowerCase());
|
||||
const capitalizedReason = reason.charAt(0).toUpperCase() + reason.slice(1);
|
||||
|
||||
return (
|
||||
<Badge variant="blue" className={isSystem ? "text-xs" : ""}>
|
||||
{capitalizedReason}
|
||||
</Badge>
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
columns.push({
|
||||
id: "actions",
|
||||
header: "",
|
||||
size: isSystem ? 60 : 90,
|
||||
minSize: isSystem ? 60 : 90,
|
||||
maxSize: isSystem ? 60 : 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>
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
return columns;
|
||||
}, [t, scope, isSystem, enableRowSelection, onViewDetails]);
|
||||
}
|
||||
@@ -1,129 +0,0 @@
|
||||
"use client";
|
||||
|
||||
import type { RowSelectionState } from "@tanstack/react-table";
|
||||
import { getCoreRowModel, getSortedRowModel, useReactTable } from "@tanstack/react-table";
|
||||
import type { ReactNode } from "react";
|
||||
import { useMemo, useState } from "react";
|
||||
|
||||
import { DataTableSelectionBar, DataTableWrapper } from "~/data-table/components";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import type { WatchlistType } from "@calcom/prisma/enums";
|
||||
import { EmptyScreen } from "@calcom/ui/components/empty-screen";
|
||||
|
||||
import type { GroupedBookingReport, BlocklistScope } from "../types";
|
||||
import { BookingReportDetailsModal } from "./BookingReportDetailsModal";
|
||||
import { usePendingReportsColumns } from "./PendingReportsColumns";
|
||||
|
||||
export type SortByOption = "createdAt" | "reportCount";
|
||||
|
||||
export interface PendingReportsTableProps<T extends GroupedBookingReport> {
|
||||
scope: BlocklistScope;
|
||||
data: T[];
|
||||
totalRowCount: number;
|
||||
isPending: boolean;
|
||||
limit: number;
|
||||
onAddToBlocklist: (email: string, type: WatchlistType, onSuccess: () => void) => void;
|
||||
onDismiss: (email: string, onSuccess: () => void) => void;
|
||||
isAddingToBlocklist?: boolean;
|
||||
isDismissing?: boolean;
|
||||
enableRowSelection?: boolean;
|
||||
renderBulkActions?: (selectedReports: T[], clearSelection: () => void) => ReactNode;
|
||||
}
|
||||
|
||||
export function PendingReportsTable<T extends GroupedBookingReport>({
|
||||
scope,
|
||||
data,
|
||||
totalRowCount,
|
||||
isPending,
|
||||
limit,
|
||||
onAddToBlocklist,
|
||||
onDismiss,
|
||||
isAddingToBlocklist = false,
|
||||
isDismissing = false,
|
||||
enableRowSelection = false,
|
||||
renderBulkActions,
|
||||
}: PendingReportsTableProps<T>) {
|
||||
const { t } = useLocale();
|
||||
|
||||
const [rowSelection, setRowSelection] = useState<RowSelectionState>({});
|
||||
const [showReviewDialog, setShowReviewDialog] = useState(false);
|
||||
const [selectedReport, setSelectedReport] = useState<T | null>(null);
|
||||
|
||||
const handleViewDetails = (entry: T) => {
|
||||
setSelectedReport(entry);
|
||||
setShowReviewDialog(true);
|
||||
};
|
||||
|
||||
const handleCloseModal = () => {
|
||||
setShowReviewDialog(false);
|
||||
setSelectedReport(null);
|
||||
};
|
||||
|
||||
const columns = usePendingReportsColumns<T>({
|
||||
t,
|
||||
scope,
|
||||
enableRowSelection,
|
||||
onViewDetails: handleViewDetails,
|
||||
});
|
||||
|
||||
const flatData = useMemo(() => data ?? [], [data]);
|
||||
|
||||
const table = useReactTable({
|
||||
data: flatData,
|
||||
columns,
|
||||
getCoreRowModel: getCoreRowModel(),
|
||||
getSortedRowModel: getSortedRowModel(),
|
||||
manualPagination: true,
|
||||
pageCount: Math.ceil(totalRowCount / limit),
|
||||
enableRowSelection,
|
||||
onRowSelectionChange: setRowSelection,
|
||||
state: {
|
||||
rowSelection,
|
||||
},
|
||||
getRowId: (row) => row.bookerEmail,
|
||||
});
|
||||
|
||||
const numberOfSelectedRows = table.getFilteredSelectedRowModel().rows.length;
|
||||
const selectedReports = table.getSelectedRowModel().flatRows.map((row) => row.original);
|
||||
const clearSelection = () => table.toggleAllPageRowsSelected(false);
|
||||
|
||||
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}>
|
||||
{enableRowSelection && numberOfSelectedRows > 0 && renderBulkActions && (
|
||||
<DataTableSelectionBar.Root className="bottom-16! justify-center md:w-max">
|
||||
<p className="text-brand-subtle px-2 text-center text-xs leading-none sm:text-sm sm:font-medium">
|
||||
{t("number_selected", { count: numberOfSelectedRows })}
|
||||
</p>
|
||||
{renderBulkActions(selectedReports, clearSelection)}
|
||||
</DataTableSelectionBar.Root>
|
||||
)}
|
||||
</DataTableWrapper>
|
||||
|
||||
<BookingReportDetailsModal
|
||||
scope={scope}
|
||||
entry={selectedReport}
|
||||
isOpen={showReviewDialog}
|
||||
onClose={handleCloseModal}
|
||||
onAddToBlocklist={(email, type) => onAddToBlocklist(email, type, handleCloseModal)}
|
||||
onDismiss={(email) => onDismiss(email, handleCloseModal)}
|
||||
isAddingToBlocklist={isAddingToBlocklist}
|
||||
isDismissing={isDismissing}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
export * from "./types";
|
||||
export * from "./components/CreateBlocklistEntryModal";
|
||||
export * from "./components/BlockedEntriesTable";
|
||||
export * from "./components/BlockedEntriesColumns";
|
||||
export * from "./components/BlocklistEntryDetailsSheet";
|
||||
export * from "./components/PendingReportsTable";
|
||||
export * from "./components/PendingReportsColumns";
|
||||
export * from "./components/BookingReportDetailsModal";
|
||||
export * from "./components/PendingReportsBadge";
|
||||
@@ -1,8 +1,4 @@
|
||||
import type { useScheduleForEventReturnType } from "@calcom/features/bookings/Booker/utils/event";
|
||||
import type { BookerEventQuery } from "@calcom/features/bookings/types";
|
||||
import type { IntlSupportedTimeZones } from "@calcom/lib/timeZones";
|
||||
import type { EventBusyDate } from "@calcom/types/Calendar";
|
||||
import type { TIsAvailableOutputSchema } from "@calcom/trpc/server/routers/viewer/slots/isAvailable.schema";
|
||||
import type React from "react";
|
||||
import type { GetBookingType } from "../lib/get-booking";
|
||||
|
||||
|
||||
@@ -1,131 +0,0 @@
|
||||
import { shallow } from "zustand/shallow";
|
||||
|
||||
import { useBookerStoreContext } from "@calcom/features/bookings/Booker/BookerStoreProvider";
|
||||
import { useSchedule } from "~/schedules/hooks/useSchedule";
|
||||
import { useCompatSearchParams } from "@calcom/lib/hooks/useCompatSearchParams";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
|
||||
import { useBookerTime } from "@calcom/features/bookings/Booker/hooks/useBookerTime";
|
||||
|
||||
export type useEventReturnType = ReturnType<typeof useEvent>;
|
||||
export type useScheduleForEventReturnType = ReturnType<typeof useScheduleForEvent>;
|
||||
|
||||
/**
|
||||
* Wrapper hook around the trpc query that fetches
|
||||
* the event currently viewed in the booker. It will get
|
||||
* the current event slug and username from the booker store.
|
||||
*
|
||||
* Using this hook means you only need to use one hook, instead
|
||||
* of combining multiple conditional hooks.
|
||||
*/
|
||||
export const useEvent = (props?: { fromRedirectOfNonOrgLink?: boolean; disabled?: boolean }) => {
|
||||
const [username, eventSlug, isTeamEvent, org] = useBookerStoreContext(
|
||||
(state) => [state.username, state.eventSlug, state.isTeamEvent, state.org],
|
||||
shallow
|
||||
);
|
||||
|
||||
const event = trpc.viewer.public.event.useQuery(
|
||||
{
|
||||
username: username ?? "",
|
||||
eventSlug: eventSlug ?? "",
|
||||
isTeamEvent,
|
||||
org: org ?? null,
|
||||
fromRedirectOfNonOrgLink: props?.fromRedirectOfNonOrgLink,
|
||||
},
|
||||
{
|
||||
refetchOnWindowFocus: false,
|
||||
enabled: !props?.disabled && Boolean(username) && Boolean(eventSlug),
|
||||
}
|
||||
);
|
||||
|
||||
return {
|
||||
data: event?.data,
|
||||
isSuccess: event?.isSuccess,
|
||||
isError: event?.isError,
|
||||
isPending: event?.isPending,
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets schedule for the current event and current month.
|
||||
* Gets all values right away and not the store because it increases network timing, only for the first render.
|
||||
* We can read from the store if we want to get the latest values.
|
||||
*
|
||||
* Using this hook means you only need to use one hook, instead
|
||||
* of combining multiple conditional hooks.
|
||||
*
|
||||
* The prefetchNextMonth argument can be used to prefetch two months at once,
|
||||
* useful when the user is viewing dates near the end of the month,
|
||||
* this way the multi day view will show data of both months.
|
||||
*/
|
||||
export const useScheduleForEvent = ({
|
||||
username,
|
||||
eventSlug,
|
||||
eventId,
|
||||
month,
|
||||
duration,
|
||||
dayCount,
|
||||
selectedDate,
|
||||
orgSlug,
|
||||
teamMemberEmail,
|
||||
isTeamEvent,
|
||||
useApiV2 = true,
|
||||
bookerLayout,
|
||||
}: {
|
||||
username?: string | null;
|
||||
eventSlug?: string | null;
|
||||
eventId?: number | null;
|
||||
month?: string | null;
|
||||
duration?: number | null;
|
||||
dayCount?: number | null;
|
||||
selectedDate?: string | null;
|
||||
orgSlug?: string;
|
||||
teamMemberEmail?: string | null;
|
||||
fromRedirectOfNonOrgLink?: boolean;
|
||||
isTeamEvent?: boolean;
|
||||
useApiV2?: boolean;
|
||||
/**
|
||||
* Required when prefetching is needed
|
||||
*/
|
||||
bookerLayout?: {
|
||||
layout: string;
|
||||
extraDays: number;
|
||||
columnViewExtraDays: { current: number };
|
||||
};
|
||||
}) => {
|
||||
const { timezone } = useBookerTime();
|
||||
const [usernameFromStore, eventSlugFromStore, monthFromStore, durationFromStore] = useBookerStoreContext(
|
||||
(state) => [state.username, state.eventSlug, state.month, state.selectedDuration],
|
||||
shallow
|
||||
);
|
||||
|
||||
const searchParams = useCompatSearchParams();
|
||||
const rescheduleUid = searchParams?.get("rescheduleUid");
|
||||
|
||||
const schedule = useSchedule({
|
||||
username: usernameFromStore ?? username,
|
||||
eventSlug: eventSlugFromStore ?? eventSlug,
|
||||
eventId,
|
||||
timezone,
|
||||
selectedDate,
|
||||
dayCount,
|
||||
rescheduleUid,
|
||||
month: monthFromStore ?? month,
|
||||
duration: durationFromStore ?? duration,
|
||||
isTeamEvent,
|
||||
orgSlug,
|
||||
teamMemberEmail,
|
||||
useApiV2: useApiV2,
|
||||
bookerLayout,
|
||||
});
|
||||
|
||||
return {
|
||||
data: schedule?.data,
|
||||
isPending: schedule?.isPending,
|
||||
isError: schedule?.isError,
|
||||
isSuccess: schedule?.isSuccess,
|
||||
isLoading: schedule?.isLoading,
|
||||
invalidate: schedule?.invalidate,
|
||||
dataUpdatedAt: schedule?.dataUpdatedAt,
|
||||
};
|
||||
};
|
||||
Reference in new issue
Block a user