From b54f6f03150dd78d86db62201b6386bf14b72394 Mon Sep 17 00:00:00 2001
From: dujinkim <dujin.kim@dtsolution.co.kr>
Date: Wed, 15 Oct 2025 12:52:11 +0000
Subject: (대표님) 커버, 데이터룸, 파일매니저, 담당자할당 등
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 lib/vendor-document-list/plant/upload/table.tsx | 37 +++++++++++++++++++------
 1 file changed, 29 insertions(+), 8 deletions(-)

(limited to 'lib/vendor-document-list/plant/upload/table.tsx')

diff --git a/lib/vendor-document-list/plant/upload/table.tsx b/lib/vendor-document-list/plant/upload/table.tsx
index 84b04092..2247fc57 100644
--- a/lib/vendor-document-list/plant/upload/table.tsx
+++ b/lib/vendor-document-list/plant/upload/table.tsx
@@ -21,6 +21,7 @@ import { SingleUploadDialog } from "./components/single-upload-dialog"
 import { HistoryDialog } from "./components/history-dialog"
 import { ViewSubmissionDialog } from "./components/view-submission-dialog"
 import { toast } from "sonner"
+import { quickDownload } from "@/lib/file-download"
 
 interface StageSubmissionsTableProps {
   promises: Promise<[
@@ -167,23 +168,43 @@ export function StageSubmissionsTable({ promises, selectedProjectId }: StageSubm
     const { type, row } = rowAction;
   
     if (type === "downloadCover") {
-       // 2) 서버에서 생성 후 다운로드 (예: API 호출)
+      const projectCode = row.original.projectCode;
+      const project = projects.find(p => p.code === projectCode);
+  
+      if (!project) {
+        toast.error("프로젝트 정보를 찾을 수 없습니다.");
+        setRowAction(null);
+        return;
+      }
+  
       (async () => {
         try {
-          const res = await fetch(`/api/stages/${row.original.stageId}/cover`, { method: "POST" });
-          if (!res.ok) throw new Error("failed");
-          const { fileUrl } = await res.json(); // 서버 응답: { fileUrl: string }
-          window.open(fileUrl, "_blank", "noopener,noreferrer");
+          const res = await fetch(`/api/projects/${project.id}/cover`, { 
+            method: "GET" 
+          });
+          
+          if (!res.ok) {
+            const error = await res.json();
+            throw new Error(error.message || "커버 페이지를 가져올 수 없습니다");
+          }
+          
+          const { fileUrl, fileName } = await res.json();
+          
+          // quickDownload 사용
+          quickDownload(fileUrl, fileName || `${projectCode}_cover.docx`);
+          
+          toast.success("커버 페이지 다운로드를 시작했습니다.");
+          
         } catch (e) {
-          toast.error("커버 페이지 생성에 실패했습니다.");
+          toast.error(e instanceof Error ? e.message : "커버 페이지 다운로드에 실패했습니다.");
           console.error(e);
         } finally {
           setRowAction(null);
         }
       })();
     }
-  }, [rowAction, setRowAction]);
-
+  }, [rowAction, setRowAction, projects]);
+  
   return (
     <>
       <DataTable table={table}>
-- 
cgit v1.2.3

