"use client" import { ColumnDef } from "@tanstack/react-table" import { Badge } from "@/components/ui/badge" // import { DataTableColumnHeader } from "@/components/data-table/data-table-column-header" import { DataTableRowAction } from "@/types/table" import { Ellipsis } from "lucide-react" import { formatDate } from "@/lib/utils" import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu" import { Button } from "@/components/ui/button" import React from "react" import { DataTableColumnHeaderSimple } from "@/components/data-table/data-table-column-simple-header" import { Checkbox } from "@/components/ui/checkbox" export interface PQList { id: number name: string type: "GENERAL" | "PROJECT" | "NON_INSPECTION" projectId?: number | null projectCode?: string | null projectName?: string | null isDeleted: boolean validTo?: Date | null createdBy?: string | null // 이제 사용자 이름(users.name) createdAt: Date updatedAt: Date updatedBy?: string | null criteriaCount?: number } const typeLabels = { GENERAL: "일반 PQ", PROJECT: "프로젝트 PQ", NON_INSPECTION: "미실사 PQ" } const typeColors = { GENERAL: "bg-blue-100 text-blue-800", PROJECT: "bg-green-100 text-green-800", NON_INSPECTION: "bg-orange-100 text-orange-800" } interface GetColumnsProps { setRowAction: React.Dispatch | null>> } export function createPQListsColumns({ 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: "name", header: ({ column }) => ( ), cell: ({ row }) => (
{row.getValue("name")}
), }, { accessorKey: "type", header: ({ column }) => ( ), cell: ({ row }) => { const type = row.getValue("type") as keyof typeof typeLabels return ( {typeLabels[type]} ) }, filterFn: (row, id, value) => { return value.includes(row.getValue(id)) }, }, { accessorKey: "projectCode", header: "프로젝트", cell: ({ row }) => row.original.projectCode ?? "-", }, { accessorKey: "projectName", header: "프로젝트명", cell: ({ row }) => row.original.projectName ?? "-", }, { accessorKey: "validTo", header: ({ column }) => ( ), cell: ({ row }) => { const validTo = row.getValue("validTo") as Date | null const now = new Date() const isExpired = validTo && validTo < now const formattedDate = validTo ? formatDate(validTo, "ko-KR") : "-" return (
{formattedDate} {isExpired && ( 만료 )}
) }, }, { accessorKey: "isDeleted", header: "상태", cell: ({ row }) => { const isDeleted = row.getValue("isDeleted") as boolean; return ( {isDeleted ? "비활성" : "활성"} ); }, }, { accessorKey: "createdBy", header: "생성자", cell: ({ row }) => row.original.createdBy ?? "-", }, { accessorKey: "updatedBy", header: "변경자", cell: ({ row }) => row.original.updatedBy ?? "-", }, { accessorKey: "createdAt", header: ({ column }) => ( ), cell: ({ row }) => formatDate(row.getValue("createdAt"), "ko-KR"), }, { accessorKey: "updatedAt", header: ({ column }) => ( ), cell: ({ row }) => formatDate(row.getValue("updatedAt"), "ko-KR"), }, { id: "actions", cell: ({ row }) => ( setRowAction({ row, type: "view" })} > 상세보기 {/* setRowAction({ row, type: "delete" })} className="text-destructive" > 삭제 ⌘⌫ */} ), size: 40, enableSorting: false, enableHiding: false, } ] }