import { type ColumnDef, type Row } from "@tanstack/react-table"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { Ellipsis } from "lucide-react"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { paymentTerms } from "@/db/schema/procurementRFQ"; import { toast } from "sonner"; import { deletePaymentTerm } from "../service"; type PaymentTerm = typeof paymentTerms.$inferSelect; interface GetColumnsProps { setRowAction: (action: { type: string; row: Row }) => void; onSuccess: () => void; } const handleDelete = async (code: string, onSuccess: () => void) => { const result = await deletePaymentTerm(code); if (result.success) { toast.success("삭제 완료"); onSuccess(); } else { toast.error(result.error || "삭제 실패"); } }; export function getColumns({ setRowAction, onSuccess }: GetColumnsProps): ColumnDef[] { return [ { id: "code", header: () =>
코드
, cell: ({ row }) =>
{row.original.code}
, enableSorting: true, enableHiding: false, }, { id: "description", header: () =>
설명
, cell: ({ row }) =>
{row.original.description}
, enableSorting: true, enableHiding: false, }, { id: "isActive", header: () =>
상태
, cell: ({ row }) => ( {row.original.isActive ? "활성" : "비활성"} ), enableSorting: true, enableHiding: false, }, { id: "createdAt", header: () =>
생성일
, cell: ({ row }) => { const value = row.original.createdAt; const date = value ? new Date(value) : null; return date ? date.toLocaleDateString() : ""; }, enableSorting: true, enableHiding: false, }, { id: "actions", cell: ({ row }) => ( setRowAction({ type: "edit", row })} > 수정 handleDelete(row.original.code, onSuccess)} className="text-destructive" > 삭제 ), }, ]; }