"use client" import * as React from "react" import { ColumnDef } from "@tanstack/react-table" import { formatDate, formatDateTime } from "@/lib/utils" import { Checkbox } from "@/components/ui/checkbox" import { DataTableColumnHeaderSimple } from "@/components/data-table/data-table-column-simple-header" import { DataTableRowAction } from "@/types/table" import { DocumentStagesView } from "@/db/schema/vendorDocu" import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu" import { Button } from "@/components/ui/button" import { Ellipsis } from "lucide-react" import { Badge } from "@/components/ui/badge" interface GetColumnsProps { setRowAction: React.Dispatch | null>> } export function getColumns({ setRowAction, }: GetColumnsProps): ColumnDef[] { return [ { id: "select", header: ({ table }) => ( table.toggleAllPageRowsSelected(!!value)} aria-label="Select all" className="translate-y-0.5" /> ), cell: ({ row }) => ( row.toggleSelected(!!value)} aria-label="Select row" className="translate-y-0.5" /> ), size:40, enableSorting: false, enableHiding: false, }, { accessorKey: "docNumber", header: ({ column }) => ( ), cell: ({ row }) =>
{row.getValue("docNumber")}
, meta: { excelHeader: "Doc Number" }, enableResizing: true, minSize: 50, size: 100, }, { accessorKey: "title", header: ({ column }) => ( ), cell: ({ row }) =>
{row.getValue("title")}
, meta: { excelHeader: "Doc title" }, enableResizing: true, minSize: 100, size: 160, }, { accessorKey: "stageCount", header: ({ column }) => ( ), cell: ({ row }) =>
{row.getValue("stageCount")}
, meta: { excelHeader: "Stage Count" }, enableResizing: true, minSize: 50, size: 50, }, { accessorKey: "stageList", header: ({ column }) => ( ), cell: ({ row }) => { const stageNames = row.getValue("stageList") as string[] | null if (!stageNames || stageNames.length === 0) { return No stages } return (
{stageNames.map((stageName, idx) => ( {stageName} ))}
) }, enableResizing: true, minSize: 120, size: 120, }, { accessorKey: "status", header: ({ column }) => ( ), cell: ({ row }) =>
{row.getValue("status")}
, meta: { excelHeader: "status" }, enableResizing: true, minSize: 60, size: 60, }, { accessorKey: "createdAt", header: ({ column }) => ( ), cell: ({ cell }) => formatDateTime(cell.getValue() as Date), meta: { excelHeader: "created At" }, enableResizing: true, minSize: 120, size: 120, }, { accessorKey: "updatedAt", header: ({ column }) => ( ), cell: ({ cell }) => formatDateTime(cell.getValue() as Date), meta: { excelHeader: "updated At" }, enableResizing: true, minSize: 120, size: 120, }, { id: "actions", enableHiding: false, cell: function Cell({ row }) { const [isUpdatePending, startUpdateTransition] = React.useTransition() return ( setRowAction({ row, type: "update" })} > Edit setRowAction({ row, type: "delete" })} > Delete ⌘⌫ ) }, size: 40, } ] }