"use client"; import React, { useState } from "react"; import { useReactTable, getCoreRowModel, flexRender, } from "@tanstack/react-table"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table"; import { swpDocumentColumns } from "./swp-table-columns"; import { SwpDocumentDetailDialog } from "./swp-document-detail-dialog"; import type { DocumentListItem } from "@/lib/swp/document-service"; interface SwpTableProps { documents: DocumentListItem[]; projNo: string; vendorCode: string; userId: string; } export function SwpTable({ documents, projNo, vendorCode, userId, }: SwpTableProps) { const [dialogOpen, setDialogOpen] = useState(false); const [selectedDocument, setSelectedDocument] = useState(null); const table = useReactTable({ data: documents, columns: swpDocumentColumns, getCoreRowModel: getCoreRowModel(), }); // 문서 클릭 핸들러 - Dialog 열기 const handleDocumentClick = (document: DocumentListItem) => { setSelectedDocument(document); setDialogOpen(true); }; return (
{/* 테이블 */}
{table.getHeaderGroups().map((headerGroup) => ( {headerGroup.headers.map((header) => ( {header.isPlaceholder ? null : flexRender( header.column.columnDef.header, header.getContext() )} ))} ))} {table.getRowModel().rows?.length ? ( table.getRowModel().rows.map((row) => ( handleDocumentClick(row.original)} > {row.getVisibleCells().map((cell) => ( {flexRender(cell.column.columnDef.cell, cell.getContext())} ))} )) ) : ( 데이터 없음 )}
{/* 문서 상세 Dialog */}
); }