From 7dd2b9fc1856306652f311d19697d9880955bfab Mon Sep 17 00:00:00 2001 From: dujinkim Date: Fri, 22 Aug 2025 02:12:15 +0000 Subject: (최겸) 공지사항, 인포메이션 기능 수정 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../document-status-dialog.tsx | 203 ++++++++++++++++----- 1 file changed, 154 insertions(+), 49 deletions(-) (limited to 'components/vendor-regular-registrations/document-status-dialog.tsx') diff --git a/components/vendor-regular-registrations/document-status-dialog.tsx b/components/vendor-regular-registrations/document-status-dialog.tsx index 1b10760a..848e4977 100644 --- a/components/vendor-regular-registrations/document-status-dialog.tsx +++ b/components/vendor-regular-registrations/document-status-dialog.tsx @@ -15,7 +15,6 @@ import type { VendorRegularRegistration } from "@/config/vendorRegularRegistrati import { documentStatusColumns, } from "@/config/vendorRegularRegistrationsColumnsConfig"; -import { downloadFile } from "@/lib/file-download"; interface DocumentStatusDialogProps { open: boolean; @@ -73,51 +72,153 @@ export function DocumentStatusDialog({ 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("파일 다운로드 중 오류가 발생했습니다."); - // } - // }; + const handleFileDownload = async (docKey: string, fileIndex: number = 0) => { + try { + console.log(`🔍 파일 다운로드 시도:`, { + docKey, + fileIndex, + allDocumentFiles: registration.documentFiles, + registrationId: registration.id, + registrationKeys: Object.keys(registration), + fullRegistration: registration + }); + + // documentFiles가 없는 경우 처리 + if (!registration.documentFiles) { + console.error(`❌ documentFiles가 없음:`, { + registration, + hasDocumentFiles: !!registration.documentFiles, + registrationKeys: Object.keys(registration) + }); + toast.error("문서 파일 정보를 찾을 수 없습니다. 페이지를 새로고침 해주세요."); + return; + } + + const files = registration.documentFiles[docKey as keyof typeof registration.documentFiles]; + console.log(`📂 ${docKey} 파일 목록:`, files); + + if (!files || files.length === 0) { + console.warn(`❌ ${docKey}에 파일이 없음:`, { files, length: files?.length }); + toast.error("다운로드할 파일이 없습니다."); + return; + } + + const file = files[fileIndex]; + console.log(`📄 선택된 파일 (index ${fileIndex}):`, file); + + if (!file) { + console.warn(`❌ 파일 인덱스 ${fileIndex}에 파일이 없음`); + toast.error("파일을 찾을 수 없습니다."); + return; + } + + // 파일 객체의 모든 속성 확인 + console.log(`🔍 파일 객체 전체 속성:`, Object.keys(file)); + console.log(`🔍 파일 상세 정보:`, { + filePath: file.filePath, + path: file.path, + originalFileName: file.originalFileName, + fileName: file.fileName, + name: file.name, + fullObject: file + }); + + // filePath와 fileName 추출 + const filePath = file.filePath || file.path; + const fileName = file.originalFileName || file.fileName || file.name; + + console.log(`📝 추출된 파일 정보:`, { filePath, fileName }); + + if (!filePath || !fileName) { + console.error(`❌ 파일 정보 누락:`, { + filePath, + fileName, + fileObject: file, + availableKeys: Object.keys(file) + }); + toast.error("파일 정보가 올바르지 않습니다."); + return; + } + + console.log(`📥 파일 다운로드 시작:`, { filePath, fileName, docKey }); + + // downloadFile 함수를 동적으로 import하여 파일 다운로드 + const { downloadFile } = await import('@/lib/file-download'); + const result = await downloadFile(filePath, fileName, { + showToast: true, + onError: (error: any) => { + console.error("파일 다운로드 오류:", error); + toast.error(`파일 다운로드 실패: ${error}`); + }, + onSuccess: (fileName: string, fileSize?: number) => { + console.log(`✅ 파일 다운로드 성공:`, { fileName, fileSize }); + } + }); + + if (!result.success) { + console.error("파일 다운로드 실패:", result.error); + } + } catch (error) { + console.error("파일 다운로드 중 오류 발생:", error); + toast.error("파일 다운로드 중 오류가 발생했습니다."); + } + }; + + // 기본계약 파일 다운로드 핸들러 + const handleContractDownload = async (contractIndex: number) => { + try { + if (!registration.basicContracts || registration.basicContracts.length === 0) { + toast.error("다운로드할 계약이 없습니다."); + return; + } + + const contract = registration.basicContracts[contractIndex]; + if (!contract) { + toast.error("계약을 찾을 수 없습니다."); + return; + } + + if (contract.status !== "COMPLETED") { + toast.error("완료된 계약서만 다운로드할 수 있습니다."); + return; + } + + // 서명된 계약서 파일 정보 확인 + const filePath = contract.filePath; + const fileName = contract.fileName || `${contract.templateName || '기본계약'}_${registration.companyName}.docx`; + + if (!filePath) { + toast.error("계약서 파일을 찾을 수 없습니다."); + return; + } + + console.log(`📥 기본계약 다운로드 시작:`, { + filePath, + fileName, + templateName: contract.templateName + }); + + // downloadFile 함수를 사용하여 서명된 계약서 다운로드 + const { downloadFile } = await import('@/lib/file-download'); + const result = await downloadFile(filePath, fileName, { + showToast: true, + onError: (error: any) => { + console.error("기본계약 다운로드 오류:", error); + toast.error(`기본계약 다운로드 실패: ${error}`); + }, + onSuccess: (fileName: string, fileSize?: number) => { + console.log(`✅ 기본계약 다운로드 성공:`, { fileName, fileSize }); + } + }); + + if (!result.success) { + console.error("기본계약 다운로드 실패:", result.error); + } + } catch (error) { + console.error("기본계약 다운로드 중 오류 발생:", error); + toast.error("기본계약 다운로드 중 오류가 발생했습니다."); + } + }; return ( @@ -205,7 +306,7 @@ export function DocumentStatusDialog({ {isSubmitted ? "2024.01.01" : "-"}
- {/* {isSubmitted && ( + {isSubmitted && ( - )} */} + )}
); @@ -262,7 +363,11 @@ export function DocumentStatusDialog({
{isCompleted && ( - -- cgit v1.2.3