"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 "@calcom/features/blocklist/types"; interface UseBlockedEntriesColumnsProps { t: (key: string) => string; scope: BlocklistScope; canDelete?: boolean; enableRowSelection?: boolean; onViewDetails: (entry: T) => void; onDelete: (entry: T) => void; } export function useBlockedEntriesColumns({ t, scope, canDelete = true, enableRowSelection = false, onViewDetails, onDelete, }: UseBlockedEntriesColumnsProps) { const isSystem = scope === "system"; return useMemo[]>(() => { const columns: ColumnDef[] = []; if (enableRowSelection) { columns.push({ id: "select", header: ({ table }) => ( table.toggleAllPageRowsSelected(!!value)} aria-label={t("select_all")} /> ), cell: ({ row }) => ( 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 }) => (
{row.original.value} {row.original.isGlobal && !isSystem && ( {t("system_blocked")} )}
), }, { id: "type", header: t("type"), accessorKey: "type", size: 100, cell: ({ row }) => ( {row.original.type === "EMAIL" ? t("email") : t("domain")} ), } ); 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 {label}; }, }); } 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 {email ?? "—"}; }, }); 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 (
); }, }); return columns; }, [t, scope, isSystem, canDelete, enableRowSelection, onViewDetails, onDelete]); }