131 lines
5.5 KiB
TypeScript
131 lines
5.5 KiB
TypeScript
"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<z.infer<typeof schema>> }) {
|
|
const { transform, transition, setNodeRef, isDragging } = useSortable({ id: row.original._id })
|
|
return (
|
|
<TableRow data-state={row.getIsSelected() && "selected"} data-dragging={isDragging} ref={setNodeRef}
|
|
className="relative z-0 data-[dragging=true]:z-10 data-[dragging=true]:opacity-80"
|
|
style={{ transform: CSS.Transform.toString(transform), transition: transition }}
|
|
>
|
|
{row.getVisibleCells().map((cell) => (
|
|
<TableCell key={cell.id}>{flexRender(cell.column.columnDef.cell, cell.getContext())}</TableCell>
|
|
))}
|
|
</TableRow>
|
|
)
|
|
}
|
|
|
|
function getColumns(deleteHandler: (id: string) => void): ColumnDef<schemaType>[] {
|
|
return [
|
|
{
|
|
accessorKey: "uuid",
|
|
header: "UUID",
|
|
cell: ({ getValue }) => (<div className="font-mono text-xs bg-muted px-2 py-1 rounded break-all">{String(getValue())}</div>),
|
|
},
|
|
{
|
|
accessorKey: "email",
|
|
header: "Email",
|
|
},
|
|
{
|
|
accessorKey: "phone",
|
|
header: "Phone",
|
|
},
|
|
{
|
|
accessorKey: "tag",
|
|
header: "Tag",
|
|
},
|
|
{
|
|
accessorKey: "isNotificationSend",
|
|
header: "Notificated?",
|
|
cell: ({ getValue }) => getValue() ? (<div className="text-green-600 font-medium">Yes</div>) : (<div className="text-red-600 font-medium">No</div>),
|
|
},
|
|
{
|
|
accessorKey: "isEmailSend",
|
|
header: "Email Send?",
|
|
cell: ({ getValue }) => getValue() ? (<div className="text-green-600 font-medium">Yes</div>) : (<div className="text-red-600 font-medium">No</div>),
|
|
},
|
|
{
|
|
accessorKey: "active",
|
|
header: "Active",
|
|
cell: ({ getValue }) => getValue() ? (<div className="text-green-600 font-medium">Yes</div>) : (<div className="text-red-600 font-medium">No</div>),
|
|
},
|
|
{
|
|
accessorKey: "isConfirmed",
|
|
header: "Confirmed",
|
|
cell: ({ getValue }) => getValue() ? (<div className="text-green-600 font-medium">Yes</div>) : (<div className="text-red-600 font-medium">No</div>),
|
|
},
|
|
{
|
|
accessorKey: "deleted",
|
|
header: "Deleted",
|
|
cell: ({ getValue }) => getValue() ? (<div className="text-red-600 font-medium">Yes</div>) : (<div className="text-green-600 font-medium">No</div>),
|
|
},
|
|
{
|
|
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 ? <div><div className="flex flex-col w-full"><span className="font-mono text-xs text-muted-foreground break-all">{defaultToken}</span></div></div> : <div>No Default Token</div>;
|
|
},
|
|
},
|
|
{
|
|
accessorKey: "collectionTokens.selectedBuildIDS",
|
|
header: "Selected Build IDS",
|
|
cell: ({ row }) => {
|
|
const selectedBuildIDS = row.original.collectionTokens?.selectedBuildIDS;
|
|
return selectedBuildIDS && <div><div className="flex flex-col w-full"><span className="font-mono text-xs text-muted-foreground break-all">{selectedBuildIDS.length}</span></div></div>;
|
|
},
|
|
},
|
|
{
|
|
accessorKey: "collectionTokens.selectedCompanyIDS",
|
|
header: "Selected Company IDS",
|
|
cell: ({ row }) => {
|
|
const selectedCompanyIDS = row.original.collectionTokens?.selectedCompanyIDS;
|
|
return selectedCompanyIDS && <div><div className="flex flex-col w-full"><span className="font-mono text-xs text-muted-foreground break-all">{selectedCompanyIDS.length}</span></div></div>;
|
|
},
|
|
},
|
|
{
|
|
id: "actions",
|
|
header: "Actions",
|
|
cell: ({ row }) => {
|
|
return (
|
|
<div>
|
|
<Button className="bg-red-700 text-white border-red-700 mx-4" variant="outline" size="sm" onClick={() => { deleteHandler(row.original.uuid || "") }}>
|
|
<Trash />
|
|
</Button>
|
|
</div>
|
|
);
|
|
},
|
|
}
|
|
]
|
|
}
|
|
|
|
export { getColumns }; |