"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 { Info, Paperclip } from "lucide-react" import { Button } from "@/components/ui/button" // 기본적인 RFQ 타입 정의 (rfq-table.tsx 파일과 일치해야 함) type TechSalesRfq = { id: number rfqCode: string | null itemId: number itemName: string | null materialCode: string | null dueDate: Date rfqSendDate: Date | null status: "RFQ Created" | "RFQ Vendor Assignned" | "RFQ Sent" | "Quotation Analysis" | "Closed" picCode: string | null remark: string | null cancelReason: string | null createdAt: Date updatedAt: Date createdBy: number | null createdByName: string updatedBy: number | null updatedByName: string sentBy: number | null sentByName: string | null projectSnapshot: Record seriesSnapshot: Record pspid: string projNm: string sector: string projMsrm: number ptypeNm: string attachmentCount: number quotationCount: number // 나머지 필드는 사용할 때마다 추가 [key: string]: unknown } // 프로젝트 상세정보 타입 추가를 위한 확장 // interface ExtendedDataTableRowAction extends DataTableRowAction { // type: DataTableRowAction["type"] | "project-detail" // } interface GetColumnsProps { setRowAction: React.Dispatch | null>>; openAttachmentsSheet: (rfqId: number) => void; } export function getColumns({ setRowAction, openAttachmentsSheet, }: GetColumnsProps): ColumnDef[] { return [ { id: "select", // Remove the "Select all" checkbox in header since we're doing single-select header: () => Select, cell: ({ row, table }) => ( { // If selecting this row if (value) { // First deselect all rows (to ensure single selection) table.toggleAllRowsSelected(false) // Then select just this row row.toggleSelected(true) // Trigger the same action that was in the "Select" button setRowAction({ row, type: "select" as const }) } else { // Just deselect this row row.toggleSelected(false) } }} aria-label="Select row" className="translate-y-0.5" /> ), enableSorting: false, enableHiding: false, enableResizing: false, size: 40, minSize: 40, maxSize: 40, }, { accessorKey: "status", header: ({ column }) => ( ), cell: ({ row }) =>
{row.getValue("status")}
, meta: { excelHeader: "진행상태" }, enableResizing: true, minSize: 80, size: 100, }, { accessorKey: "rfqCode", header: ({ column }) => ( ), cell: ({ row }) =>
{row.getValue("rfqCode")}
, meta: { excelHeader: "RFQ No." }, enableResizing: true, size: 120, }, { accessorKey: "materialCode", header: ({ column }) => ( ), cell: ({ row }) =>
{row.getValue("materialCode")}
, meta: { excelHeader: "자재코드" }, enableResizing: true, minSize: 80, size: 120, }, { accessorKey: "itemName", header: ({ column }) => ( ), cell: ({ row }) => { const itemName = row.getValue("itemName"); return
{itemName || "자재명 없음"}
; }, meta: { excelHeader: "자재명" }, enableResizing: true, size: 180, }, { accessorKey: "pspid", header: ({ column }) => ( ), cell: ({ row }) =>
{row.getValue("pspid")}
, meta: { excelHeader: "프로젝트 번호" }, enableResizing: true, size: 120, }, { accessorKey: "projNm", header: ({ column }) => ( ), cell: ({ row }) =>
{row.getValue("projNm")}
, meta: { excelHeader: "프로젝트명" }, enableResizing: true, size: 160, }, { accessorKey: "projMsrm", header: ({ column }) => ( ), cell: ({ row }) =>
{row.getValue("projMsrm")}
, meta: { excelHeader: "척수" }, enableResizing: true, minSize: 60, size: 80, }, { accessorKey: "ptypeNm", header: ({ column }) => ( ), cell: ({ row }) =>
{row.getValue("ptypeNm")}
, meta: { excelHeader: "선종" }, enableResizing: true, size: 120, }, { accessorKey: "quotationCount", header: ({ column }) => ( ), cell: ({ row }) =>
{row.getValue("quotationCount")}
, meta: { excelHeader: "견적수" }, enableResizing: true, size: 80, }, { id: "attachments", header: ({ column }) => ( ), cell: ({ row }) => { const rfq = row.original const attachmentCount = rfq.attachmentCount || 0 const handleClick = () => { openAttachmentsSheet(rfq.id) } return ( ) }, enableSorting: false, enableResizing: true, size: 80, meta: { excelHeader: "첨부파일" }, }, { accessorKey: "rfqSendDate", header: ({ column }) => ( ), cell: ({ cell }) => { const value = cell.getValue(); return value ? formatDate(value as Date, "KR") : ""; }, meta: { excelHeader: "최초 전송일" }, enableResizing: true, size: 120, }, { accessorKey: "dueDate", header: ({ column }) => ( ), cell: ({ cell }) => { const value = cell.getValue(); return value ? formatDate(value as Date, "KR") : ""; }, meta: { excelHeader: "RFQ 마감일" }, enableResizing: true, minSize: 80, size: 120, }, { accessorKey: "createdByName", header: ({ column }) => ( ), cell: ({ row }) =>
{row.getValue("createdByName")}
, meta: { excelHeader: "요청자" }, enableResizing: true, size: 120, }, { accessorKey: "createdAt", header: ({ column }) => ( ), cell: ({ cell }) => { const value = cell.getValue(); return value ? formatDateTime(value as Date) : ""; }, meta: { excelHeader: "등록일" }, enableResizing: true, size: 160, }, { accessorKey: "updatedAt", header: ({ column }) => ( ), cell: ({ cell }) => { const value = cell.getValue(); return value ? formatDateTime(value as Date) : ""; }, meta: { excelHeader: "수정일" }, enableResizing: true, size: 160, }, { id: "actions", header: ({ column }) => ( ), cell: ({ row }) => { return ( ); }, enableSorting: false, enableHiding: false, enableResizing: false, size: 120, minSize: 120, maxSize: 120, }, ] }