diff options
Diffstat (limited to 'lib/vendor-investigation/table/update-investigation-sheet.tsx')
| -rw-r--r-- | lib/vendor-investigation/table/update-investigation-sheet.tsx | 43 |
1 files changed, 19 insertions, 24 deletions
diff --git a/lib/vendor-investigation/table/update-investigation-sheet.tsx b/lib/vendor-investigation/table/update-investigation-sheet.tsx index 14350815..37d1b2cd 100644 --- a/lib/vendor-investigation/table/update-investigation-sheet.tsx +++ b/lib/vendor-investigation/table/update-investigation-sheet.tsx @@ -64,7 +64,7 @@ import { updateVendorInvestigationSchema, type UpdateVendorInvestigationSchema, } from "../validations" -import { updateVendorInvestigationAction, getInvestigationAttachments, deleteInvestigationAttachment } from "../service" +import { updateVendorInvestigationAction, getInvestigationAttachments, deleteInvestigationAttachment, createVendorInvestigationAttachmentAction } from "../service" import { VendorInvestigationsViewWithContacts } from "@/config/vendorInvestigationsColumnsConfig" import prettyBytes from "pretty-bytes" import { downloadFile } from "@/lib/file-download" @@ -183,15 +183,7 @@ export function UpdateVendorInvestigationSheet({ if (!investigation) return try { - const response = await fetch(`/api/vendor-investigations/${investigation.investigationId}/attachments?attachmentId=${attachmentId}`, { - method: "DELETE", - }) - - if (!response.ok) { - const errorData = await response.json() - throw new Error(errorData.error || "첨부파일 삭제 실패") - } - + await deleteInvestigationAttachment(attachmentId) toast.success("첨부파일이 삭제되었습니다.") // 목록 새로고침 loadExistingAttachments(investigation.investigationId) @@ -409,23 +401,26 @@ export function UpdateVendorInvestigationSheet({ // 파일 업로드 함수 const uploadFiles = async (files: File[], investigationId: number) => { const uploadPromises = files.map(async (file) => { - const formData = new FormData() - formData.append("file", file) - - const response = await fetch(`/api/vendor-investigations/${investigationId}/attachments`, { - method: "POST", - body: formData, - }) + try { + // 서버 액션을 호출하여 파일 저장 및 DB 레코드 생성 + const result = await createVendorInvestigationAttachmentAction({ + investigationId, + file, + userId: undefined // 필요시 사용자 ID 추가 + }); + + if (!result.success) { + throw new Error(result.error || "파일 업로드 실패"); + } - if (!response.ok) { - const errorData = await response.json() - throw new Error(errorData.error || "파일 업로드 실패") + return result.attachment; + } catch (error) { + console.error(`파일 업로드 실패: ${file.name}`, error); + throw error; } + }); - return await response.json() - }) - - return await Promise.all(uploadPromises) + return await Promise.all(uploadPromises); } // Submit handler |
