"use client" import React, { useEffect, useState } from "react" import { ScrollArea } from "@/components/ui/scroll-area" import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table" import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip" import { FileIcon, Building } from "lucide-react" import { Button } from "@/components/ui/button" import { getDocumentVersionsByDocId } from "@/lib/vendor-document/service" import { Badge } from "@/components/ui/badge" type StageListProps = { document: { id: number docNumber: string title: string // ... } } // 인터페이스 interface Attachment { id: number fileName: string filePath: string fileType?: string } interface Version { id: number stage: string revision: string uploaderType: string uploaderName: string | null comment: string | null status: string | null planDate: string | null actualDate: string | null approvedDate: string | null attachments: Attachment[] } export default function StageSHIList({ document }: StageListProps) { const [versions, setVersions] = useState([]) useEffect(() => { if (!document?.id) return // shi 업로더 타입만 필터링 getDocumentVersionsByDocId(document.id, ['shi']).then((data) => { setVersions(data) }) }, [document]) // 스테이지 옵션 추출 const stageOptions = React.useMemo(() => { const stageSet = new Set() for (const v of versions) { if (v.stage) { stageSet.add(v.stage) } } return Array.from(stageSet) }, [versions]) // Handle file download with original filename const handleDownload = (attachmentPath: string, fileName: string) => { if (attachmentPath) { // Use window.document to avoid collision with the document prop const link = window.document.createElement('a'); link.href = attachmentPath; link.download = fileName || 'download'; // Use the original filename or a default window.document.body.appendChild(link); link.click(); window.document.body.removeChild(link); } } // 파일 확장자에 따른 아이콘 색상 반환 const getFileIconColor = (fileName: string) => { const ext = fileName.split('.').pop()?.toLowerCase(); switch(ext) { case 'pdf': return 'text-red-500'; case 'doc': case 'docx': return 'text-blue-500'; case 'xls': case 'xlsx': return 'text-green-500'; case 'dwg': return 'text-amber-500'; default: return 'text-gray-500'; } } return ( <>

{/* */} From 삼성중공업 ({document.docNumber} {document.title})

Stage Revision 첨부파일 상태 코멘트 {versions.length ? ( versions.map((ver) => ( {ver.stage} {ver.revision}
{ver.attachments && ver.attachments.length > 0 ? ( ver.attachments.map((file) => (

{file.fileName || "Download file"}

)) ) : ( 파일 없음 )}
{ver.status && ( {ver.status} )} {ver.comment || "-"}
)) ) : ( 삼성중공업 문서가 없습니다. )}
) }