"use client"; import { Dialog, DialogContent, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { FileText, Download, CheckCircle, XCircle, Clock } from "lucide-react"; import { toast } from "sonner"; import type { VendorRegularRegistration } from "@/config/vendorRegularRegistrationsColumnsConfig"; import { documentStatusColumns, contractAgreementColumns, } from "@/config/vendorRegularRegistrationsColumnsConfig"; import { downloadFile } from "@/lib/file-download"; interface DocumentStatusDialogProps { open: boolean; onOpenChange: (open: boolean) => void; registration: VendorRegularRegistration | null; } const StatusIcon = ({ status }: { status: string | boolean }) => { if (typeof status === "boolean") { return status ? ( ) : ( ); } switch (status) { case "completed": return ; case "reviewing": return ; case "not_submitted": default: return ; } }; const StatusBadge = ({ status }: { status: string | boolean }) => { if (typeof status === "boolean") { return ( {status ? "제출완료" : "미제출"} ); } const statusConfig = { completed: { label: "완료", variant: "default" as const }, reviewing: { label: "검토중", variant: "secondary" as const }, not_submitted: { label: "미제출", variant: "destructive" as const }, }; const config = statusConfig[status as keyof typeof statusConfig] || statusConfig.not_submitted; return {config.label}; }; export function DocumentStatusDialog({ open, onOpenChange, registration, }: DocumentStatusDialogProps) { if (!registration) return null; // 파일 다운로드 핸들러 const handleFileDownload = async (docKey: string, fileIndex: number = 0) => { try { const files = registration.documentFiles[docKey as keyof typeof registration.documentFiles]; if (!files || files.length === 0) { toast.error("다운로드할 파일이 없습니다."); return; } const file = files[fileIndex]; if (!file) { toast.error("파일을 찾을 수 없습니다."); return; } // filePath와 fileName 추출 const filePath = file.filePath || file.path; const fileName = file.originalFileName || file.fileName || file.name; if (!filePath || !fileName) { toast.error("파일 정보가 올바르지 않습니다."); return; } console.log(`📥 파일 다운로드 시작:`, { filePath, fileName, docKey }); // downloadFile 함수를 사용하여 파일 다운로드 const result = await downloadFile(filePath, fileName, { showToast: true, onError: (error) => { console.error("파일 다운로드 오류:", error); toast.error(`파일 다운로드 실패: ${error}`); }, onSuccess: (fileName, fileSize) => { console.log(`✅ 파일 다운로드 성공:`, { fileName, fileSize }); } }); if (!result.success) { console.error("파일 다운로드 실패:", result.error); } } catch (error) { console.error("파일 다운로드 중 오류 발생:", error); toast.error("파일 다운로드 중 오류가 발생했습니다."); } }; return ( 문서/자료 접수 현황 - {registration.companyName} {/* 기본 정보 */} 업체명: {registration.companyName} 사업자번호: {registration.businessNumber} 대표자: {registration.representative || "-"} 현재상태: {registration.status} {/* 문서 제출 현황 */} 문서 제출 현황 문서유형 상태 제출일자 액션 {documentStatusColumns.map((doc) => { const isSubmitted = registration.documentSubmissions[ doc.key as keyof typeof registration.documentSubmissions ] as boolean; return ( {doc.label} {isSubmitted ? "2024.01.01" : "-"} {isSubmitted && ( handleFileDownload(doc.key)} > 다운로드 )} ); })} {/* 계약 동의 현황 */} 계약 동의 현황 계약유형 상태 서약일자 액션 {contractAgreementColumns.map((agreement) => { const status = registration.contractAgreements[ agreement.key as keyof typeof registration.contractAgreements ] as string; return ( {agreement.label} {status === "completed" ? "2024.01.01" : "-"} {status === "completed" && ( 다운로드 )} ); })} {/* 추가 정보 */} 추가 정보 추가 정보 등록 ); }