From ef4c533ebacc2cdc97e518f30e9a9350004fcdfb Mon Sep 17 00:00:00 2001 From: dujinkim Date: Mon, 28 Apr 2025 02:13:30 +0000 Subject: ~20250428 작업사항 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vendor-cbe-table/cbe-table-columns.tsx | 365 +++++++++++++++++++++ 1 file changed, 365 insertions(+) create mode 100644 lib/vendor-rfq-response/vendor-cbe-table/cbe-table-columns.tsx (limited to 'lib/vendor-rfq-response/vendor-cbe-table/cbe-table-columns.tsx') diff --git a/lib/vendor-rfq-response/vendor-cbe-table/cbe-table-columns.tsx b/lib/vendor-rfq-response/vendor-cbe-table/cbe-table-columns.tsx new file mode 100644 index 00000000..c7be0bf4 --- /dev/null +++ b/lib/vendor-rfq-response/vendor-cbe-table/cbe-table-columns.tsx @@ -0,0 +1,365 @@ +"use client" + +import * as React from "react" +import { type DataTableRowAction } from "@/types/table" +import { type ColumnDef } from "@tanstack/react-table" +import { Download, Loader2, MessageSquare, FileEdit } from "lucide-react" +import { formatDate } from "@/lib/utils" +import { Badge } from "@/components/ui/badge" +import { Button } from "@/components/ui/button" +import { Checkbox } from "@/components/ui/checkbox" +import { DataTableColumnHeaderSimple } from "@/components/data-table/data-table-column-simple-header" +import { useRouter } from "next/navigation" +import { VendorWithCbeFields, vendorResponseCbeColumnsConfig } from "@/config/vendorCbeColumnsConfig" +import { toast } from "sonner" + + +type NextRouter = ReturnType + +interface GetColumnsProps { + setRowAction: React.Dispatch< + React.SetStateAction | null> + > + router: NextRouter + openCommentSheet: (vendorId: number) => void + handleDownloadCbeFiles: (vendorId: number, rfqId: number) => void + loadingVendors: Record + openVendorContactsDialog: (rfqId: number, rfq: VendorWithCbeFields) => void + // New prop for handling commercial response + openCommercialResponseSheet: (responseId: number, rfq: VendorWithCbeFields) => void +} + +/** + * tanstack table 컬럼 정의 (중첩 헤더 버전) + */ +export function getColumns({ + setRowAction, + router, + openCommentSheet, + handleDownloadCbeFiles, + loadingVendors, + openVendorContactsDialog, + openCommercialResponseSheet +}: 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) 그룹화(Nested) 컬럼 구성 + // ---------------------------------------------------------------- + const groupMap: Record[]> = {} + + vendorResponseCbeColumnsConfig.forEach((cfg) => { + const groupName = cfg.group || "_noGroup" + if (!groupMap[groupName]) { + groupMap[groupName] = [] + } + + // childCol: ColumnDef + const childCol: ColumnDef = { + accessorKey: cfg.id, + enableResizing: true, + header: ({ column }) => ( + + ), + meta: { + excelHeader: cfg.excelHeader, + group: cfg.group, + type: cfg.type, + }, + maxSize: 120, + // 셀 렌더링 + cell: ({ row, getValue }) => { + // 1) 필드값 가져오기 + const val = getValue() + + + if (cfg.id === "rfqCode") { + const rfq = row.original; + const rfqId = rfq.rfqId; + + // 협력업체 이름을 클릭할 수 있는 버튼으로 렌더링 + const handleVendorNameClick = () => { + if (rfqId) { + openVendorContactsDialog(rfqId, rfq); // vendor 전체 객체 전달 + } else { + toast.error("협력업체 ID를 찾을 수 없습니다."); + } + }; + + return ( + + ); + } + + // Commercial Response Status에 배지 적용 + if (cfg.id === "commercialResponseStatus") { + const status = val as string; + + if (!status) return -; + + let variant: "default" | "outline" | "secondary" | "destructive" = "outline"; + + switch (status) { + case "SUBMITTED": + variant = "default"; // Green + break; + case "IN_PROGRESS": + variant = "secondary"; // Orange/Yellow + break; + case "PENDING": + variant = "outline"; // Gray + break; + default: + variant = "outline"; + } + + return ( + + {status.toLowerCase().replace("_", " ")} + + ); + } + + // 예) TBE Updated (날짜) + if (cfg.id === "respondedAt" || cfg.id === "rfqDueDate" ) { + const dateVal = val as Date | undefined + if (!dateVal) return null + return formatDate(dateVal) + } + + // 그 외 필드는 기본 값 표시 + return val ?? "" + }, + } + + groupMap[groupName].push(childCol) + }) + + // groupMap → nestedColumns + const nestedColumns: ColumnDef[] = [] + Object.entries(groupMap).forEach(([groupName, colDefs]) => { + if (groupName === "_noGroup") { + nestedColumns.push(...colDefs) + } else { + nestedColumns.push({ + id: groupName, + header: groupName, + columns: colDefs, + }) + } + }) + + // ---------------------------------------------------------------- + // 3) Respond 컬럼 (새로 추가) + // ---------------------------------------------------------------- + const respondColumn: ColumnDef = { + id: "respond", + header: ({ column }) => ( + + ), + cell: ({ row }) => { + const vendor = row.original + const responseId = vendor.responseId + + if (!responseId) { + return
-
+ } + + const handleClick = () => { + openCommercialResponseSheet(responseId, vendor) + } + + // Status에 따라 버튼 variant 변경 + let variant: "default" | "outline" | "ghost" | "secondary" = "default" + let buttonText = "Respond" + + if (vendor.commercialResponseStatus === "SUBMITTED") { + variant = "outline" + buttonText = "Update" + } else if (vendor.commercialResponseStatus === "IN_PROGRESS") { + variant = "secondary" + buttonText = "Continue" + } + + return ( + + ) + }, + enableSorting: false, + maxSize: 200, + minSize: 115, + } + + // ---------------------------------------------------------------- + // 4) Comments 컬럼 + // ---------------------------------------------------------------- + const commentsColumn: ColumnDef = { + id: "comments", + header: ({ column }) => ( + + ), + cell: ({ row }) => { + const vendor = row.original + const commCount = vendor.comments?.length ?? 0 + + function handleClick() { + // rowAction + openCommentSheet + setRowAction({ row, type: "comments" }) + openCommentSheet(vendor.responseId ?? 0) + } + + return ( + + ) + }, + enableSorting: false, + maxSize: 80 + } + + // ---------------------------------------------------------------- + // 5) 파일 다운로드 컬럼 (개별 로딩 상태 적용) + // ---------------------------------------------------------------- + const downloadColumn: ColumnDef = { + id: "attachDownload", + header: ({ column }) => ( + + ), + cell: ({ row }) => { + const vendor = row.original + const vendorId = vendor.vendorId + const rfqId = vendor.rfqId + const files = vendor.files?.length || 0 + + if (!vendorId || !rfqId) { + return
-
+ } + + // 각 행별로 로딩 상태 확인 (vendorId_rfqId 형식의 키 사용) + const rowKey = `${vendorId}_${rfqId}` + const isRowLoading = loadingVendors[rowKey] === true + + // 템플릿 파일이 없으면 다운로드 버튼 비활성화 + const isDisabled = files <= 0 || isRowLoading + + return ( + + ) + }, + enableSorting: false, + maxSize: 80, + } + + // ---------------------------------------------------------------- + // 6) 최종 컬럼 배열 (respondColumn 추가) + // ---------------------------------------------------------------- + return [ + selectColumn, + ...nestedColumns, + respondColumn, // 응답 컬럼 추가 + downloadColumn, + commentsColumn, + ] +} \ No newline at end of file -- cgit v1.2.3