"use client" import { z } from "zod" import { Button } from "@/components/ui/button" import { useSortable } from "@dnd-kit/sortable" import { ColumnDef, flexRender, Row } from "@tanstack/react-table" import { TableCell, TableRow } from "@/components/ui/table" import { CSS } from "@dnd-kit/utilities" import { schema, schemaType } from "./schema" import { dateToLocaleString } from "@/lib/utils" import { Pencil, Trash } from "lucide-react" export function DraggableRow({ row }: { row: Row> }) { const { transform, transition, setNodeRef, isDragging } = useSortable({ id: row.original._id }) return ( {row.getVisibleCells().map((cell) => ( {flexRender(cell.column.columnDef.cell, cell.getContext())} ))} ) } function getColumns(deleteHandler: (id: string) => void): ColumnDef[] { return [ { accessorKey: "uuid", header: "UUID", cell: ({ getValue }) => (
{String(getValue())}
), }, { accessorKey: "email", header: "Email", }, { accessorKey: "phone", header: "Phone", }, { accessorKey: "tag", header: "Tag", }, { accessorKey: "isNotificationSend", header: "Notificated?", cell: ({ getValue }) => getValue() ? (
Yes
) : (
No
), }, { accessorKey: "isEmailSend", header: "Email Send?", cell: ({ getValue }) => getValue() ? (
Yes
) : (
No
), }, { accessorKey: "active", header: "Active", cell: ({ getValue }) => getValue() ? (
Yes
) : (
No
), }, { accessorKey: "isConfirmed", header: "Confirmed", cell: ({ getValue }) => getValue() ? (
Yes
) : (
No
), }, { accessorKey: "deleted", header: "Deleted", cell: ({ getValue }) => getValue() ? (
Yes
) : (
No
), }, { accessorKey: "createdAt", header: "Created", cell: ({ getValue }) => dateToLocaleString(getValue() as string), }, { accessorKey: "updatedAt", header: "Updated", cell: ({ getValue }) => dateToLocaleString(getValue() as string), }, { accessorKey: "expiryStarts", header: "Expiry Starts", cell: ({ getValue }) => getValue() ? dateToLocaleString(getValue() as string) : "-", }, { accessorKey: "expiryEnds", header: "Expiry Ends", cell: ({ getValue }) => getValue() ? dateToLocaleString(getValue() as string) : "-", }, { accessorKey: "collectionTokens.tokens", header: "Default Token", cell: ({ row }) => { const defaultToken = row.original.collectionTokens?.defaultSelection; return defaultToken ?
{defaultToken}
:
No Default Token
; }, }, { accessorKey: "collectionTokens.selectedBuildIDS", header: "Selected Build IDS", cell: ({ row }) => { const selectedBuildIDS = row.original.collectionTokens?.selectedBuildIDS; return selectedBuildIDS &&
{selectedBuildIDS.length}
; }, }, { accessorKey: "collectionTokens.selectedCompanyIDS", header: "Selected Company IDS", cell: ({ row }) => { const selectedCompanyIDS = row.original.collectionTokens?.selectedCompanyIDS; return selectedCompanyIDS &&
{selectedCompanyIDS.length}
; }, }, { id: "actions", header: "Actions", cell: ({ row }) => { return (
); }, } ] } export { getColumns };