"use client" import * as React from "react" import { type DataTableRowAction } from "@/types/table" import { type ColumnDef } from "@tanstack/react-table" import { Ellipsis } from "lucide-react" import Link from "next/link" import { formatDate } from "@/lib/utils" import { Button } from "@/components/ui/button" import { Checkbox } from "@/components/ui/checkbox" import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu" import { DataTableColumnHeaderSimple } from "@/components/data-table/data-table-column-simple-header" import { techVendorRfqHistoryColumnsConfig } from "@/config/techVendorRfqHistoryColumnsConfig" import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip" export interface TechVendorRfqHistoryRow { id: number; rfqCode: string | null; description: string | null; projectCode: string | null; projectName: string | null; projectType: string | null; // 프로젝트 타입 추가 status: string; totalAmount: string | null; currency: string | null; dueDate: Date | null; createdAt: Date; quotationCode: string | null; submittedAt: Date | null; } // 프로젝트 타입에 따른 RFQ 페이지 URL 생성 함수 function getRfqPageUrl(projectType: string | null, description: string | null): string { const baseUrls = { 'SHIP': '/evcp/budgetary-tech-sales-ship', 'TOP': '/evcp/budgetary-tech-sales-top', 'HULL': '/evcp/budgetary-tech-sales-hull' }; const url = baseUrls[projectType as keyof typeof baseUrls] || '/evcp/budgetary-tech-sales-ship'; // description이 있으면 search 파라미터로 추가 if (description) { return `${url}?search=${encodeURIComponent(description)}`; } return url; } // 프로젝트 타입 표시 함수 function getProjectTypeDisplay(projectType: string | null): string { const typeMap = { 'SHIP': '조선', 'TOP': '해양TOP', 'HULL': '해양HULL' }; return typeMap[projectType as keyof typeof typeMap] || projectType || '-'; } interface GetColumnsProps { setRowAction: React.Dispatch | null>>; } export function getColumns({ setRowAction }: GetColumnsProps): ColumnDef[] { // ---------------------------------------------------------------- // 1) select 컬럼 (체크박스) // ---------------------------------------------------------------- const selectColumn: ColumnDef = { 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, } // ---------------------------------------------------------------- // 2) actions 컬럼 (Dropdown 메뉴) // ---------------------------------------------------------------- // const actionsColumn: ColumnDef = { // id: "actions", // enableHiding: false, // cell: function Cell({ row }) { // return ( // // // // // // setRowAction({ row, type: "update" })} // > // View Details // // // // ) // }, // size: 40, // } // ---------------------------------------------------------------- // 3) 일반 컬럼들 // ---------------------------------------------------------------- const basicColumns: ColumnDef[] = techVendorRfqHistoryColumnsConfig.map((cfg) => { const column: ColumnDef = { accessorKey: cfg.id, header: ({ column }) => ( ), size: cfg.size, } if (cfg.id === "rfqCode") { column.cell = ({ row }) => { const rfqCode = row.original.rfqCode const projectType = row.original.projectType if (!rfqCode) return null const rfqUrl = getRfqPageUrl(projectType, rfqCode); return ( {rfqCode}
{rfqCode}
클릭하여 RFQ 페이지로 이동
) } } if (cfg.id === "projectType") { column.cell = ({ row }) => { const projectType = row.original.projectType return (
{getProjectTypeDisplay(projectType)}
) } } if (cfg.id === "status") { column.cell = ({ row }) => { const statusVal = row.original.status if (!statusVal) return null return (
{statusVal}
) } } if (cfg.id === "totalAmount") { column.cell = ({ row }) => { const amount = row.original.totalAmount const currency = row.original.currency if (!amount || !currency) return - return (
{`${currency} ${Number(amount).toLocaleString()}`}
) } } if (cfg.id === "dueDate" || cfg.id === "createdAt") { column.cell = ({ row }) => { const dateValue = row.getValue(cfg.id) as Date if (!dateValue) return - return (
{formatDate(dateValue)}
) } } if (cfg.id === "projectCode" || cfg.id === "projectName") { column.cell = ({ row }) => { const value = row.getValue(cfg.id) as string | null if (!value) return - return value } column.size = 100; } return column }) // ---------------------------------------------------------------- // 4) 최종 컬럼 배열 // ---------------------------------------------------------------- return [ selectColumn, ...basicColumns, // actionsColumn, ] }