diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-08-07 05:04:39 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-08-07 05:04:39 +0000 |
| commit | e270e477f362dd68249bb4a013c66eab293bba82 (patch) | |
| tree | ef29ec732fc62c220ca2f6ab12aa282b0db7c9ab /lib/basic-contract/vendor-table/basic-contract-columns.tsx | |
| parent | a5cecbef039e29beaa616e3a36e7f15b8b35623c (diff) | |
(최겸) PQ요청+기본계약 로직 수정(한글화 미적용)
Diffstat (limited to 'lib/basic-contract/vendor-table/basic-contract-columns.tsx')
| -rw-r--r-- | lib/basic-contract/vendor-table/basic-contract-columns.tsx | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/lib/basic-contract/vendor-table/basic-contract-columns.tsx b/lib/basic-contract/vendor-table/basic-contract-columns.tsx index b79487d7..c9e8da53 100644 --- a/lib/basic-contract/vendor-table/basic-contract-columns.tsx +++ b/lib/basic-contract/vendor-table/basic-contract-columns.tsx @@ -8,6 +8,7 @@ import { toast } from "sonner" import { getErrorMessage } from "@/lib/handle-error" import { formatDate, formatDateTime } from "@/lib/utils" +import { downloadFile } from "@/lib/file-download" import { Badge } from "@/components/ui/badge" import { Button } from "@/components/ui/button" import { Checkbox } from "@/components/ui/checkbox" @@ -36,28 +37,24 @@ interface GetColumnsProps { /** * 파일 다운로드 함수 */ -/** - * 파일 다운로드 함수 - */ -const handleFileDownload = (filePath: string | null, fileName: string | null) => { +const handleFileDownload = async (filePath: string | null, fileName: string | null) => { if (!filePath || !fileName) { toast.error("파일 정보가 없습니다."); return; } try { - // 전체 URL 생성 - const fullUrl = `${window.location.origin}${filePath}`; + // /api/files/ 엔드포인트를 통한 안전한 다운로드 + const apiFilePath = `/api/files/${filePath.startsWith('/') ? filePath.substring(1) : filePath}`; - // a 태그를 생성하여 다운로드 실행 - const link = document.createElement('a'); - link.href = fullUrl; - link.download = fileName; // 다운로드될 파일명 설정 - document.body.appendChild(link); - link.click(); - document.body.removeChild(link); - - toast.success("파일 다운로드를 시작합니다."); + const result = await downloadFile(apiFilePath, fileName, { + action: 'download', + showToast: true + }); + + if (!result.success) { + console.error("파일 다운로드 실패:", result.error); + } } catch (error) { console.error("파일 다운로드 오류:", error); toast.error("파일 다운로드 중 오류가 발생했습니다."); @@ -104,16 +101,19 @@ export function getColumns({ setRowAction }: GetColumnsProps): ColumnDef<BasicCo id: "download", header: "", cell: ({ row }) => { - const template = row.original; - const filePath = template.status === "PENDING" ? template.filePath : template.signedFilePath + const contract = row.original; + // PENDING 상태일 때는 원본 PDF 파일 (signedFilePath), COMPLETED일 때는 서명된 파일 (signedFilePath) + const filePath = contract.signedFilePath; + const fileName = contract.signedFileName; return ( <Button variant="ghost" size="icon" - onClick={() => handleFileDownload(filePath, template.fileName)} - title={`${template.fileName} 다운로드`} + onClick={() => handleFileDownload(filePath, fileName)} + title={`${fileName} 다운로드`} className="hover:bg-muted" + disabled={!filePath || !fileName} > <Paperclip className="h-4 w-4" /> <span className="sr-only">다운로드</span> |
