diff options
| author | joonhoekim <26rote@gmail.com> | 2025-10-24 19:44:29 +0900 |
|---|---|---|
| committer | joonhoekim <26rote@gmail.com> | 2025-10-24 19:44:29 +0900 |
| commit | 4142f8ce9c736a19b08f5f4f9fa55aa15d9c99b3 (patch) | |
| tree | 837ee03e61e2e97ec085acedd597f398e7b42b33 /lib/swp/table/swp-table-columns.tsx | |
| parent | 14961f2202b94be5ad881c762c524b8115a4f2cd (diff) | |
| parent | 231c4eb86771a44b24248ca403fcbb8c44fff74b (diff) | |
Merge branch 'swp' into dujinkim
Diffstat (limited to 'lib/swp/table/swp-table-columns.tsx')
| -rw-r--r-- | lib/swp/table/swp-table-columns.tsx | 93 |
1 files changed, 82 insertions, 11 deletions
diff --git a/lib/swp/table/swp-table-columns.tsx b/lib/swp/table/swp-table-columns.tsx index dd605453..573acf1b 100644 --- a/lib/swp/table/swp-table-columns.tsx +++ b/lib/swp/table/swp-table-columns.tsx @@ -3,30 +3,28 @@ import { ColumnDef } from "@tanstack/react-table"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; -import { ChevronDown, ChevronRight, FileIcon } from "lucide-react"; +import { ChevronDown, ChevronRight, FileIcon, Download, Loader2 } from "lucide-react"; import { formatDistanceToNow } from "date-fns"; import { ko } from "date-fns/locale"; import type { SwpDocumentWithStats } from "../actions"; +import { downloadSwpFile } from "../actions"; +import { useState } from "react"; +import { toast } from "sonner"; export const swpDocumentColumns: ColumnDef<SwpDocumentWithStats>[] = [ { id: "expander", header: () => null, - cell: ({ row }) => { - return row.getCanExpand() ? ( + cell: () => { + return ( <Button variant="ghost" size="sm" - onClick={row.getToggleExpandedHandler()} className="h-8 w-8 p-0" > - {row.getIsExpanded() ? ( - <ChevronDown className="h-4 w-4" /> - ) : ( - <ChevronRight className="h-4 w-4" /> - )} + <ChevronRight className="h-4 w-4" /> </Button> - ) : null; + ); }, size: 50, }, @@ -182,7 +180,6 @@ export const swpRevisionColumns: ColumnDef<RevisionRow>[] = [ <Button variant="ghost" size="sm" - onClick={row.getToggleExpandedHandler()} className="h-8 w-8 p-0 ml-8" > {row.getIsExpanded() ? ( @@ -390,5 +387,79 @@ export const swpFileColumns: ColumnDef<FileRow>[] = [ ), size: 100, }, + { + id: "actions", + header: "작업", + cell: ({ row }) => ( + <DownloadButton fileId={row.original.id} fileName={row.original.FILE_NM} /> + ), + size: 120, + }, ]; +// ============================================================================ +// 다운로드 버튼 컴포넌트: 임시 구성. Download.aspx 동작 안해서 일단 네트워크드라이브 사용하도록 처리 +// ============================================================================ + +interface DownloadButtonProps { + fileId: number; + fileName: string; +} + +function DownloadButton({ fileId, fileName }: DownloadButtonProps) { + const [isDownloading, setIsDownloading] = useState(false); + + const handleDownload = async () => { + try { + setIsDownloading(true); + + // 서버 액션 호출 + const result = await downloadSwpFile(fileId); + + if (!result.success || !result.data) { + toast.error(result.error || "파일 다운로드 실패"); + return; + } + + // Blob 생성 및 다운로드 + const blob = new Blob([result.data as unknown as BlobPart], { type: result.mimeType }); + const url = window.URL.createObjectURL(blob); + const link = document.createElement("a"); + link.href = url; + link.download = result.fileName || fileName; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + window.URL.revokeObjectURL(url); + + toast.success(`파일 다운로드 완료: ${result.fileName}`); + } catch (error) { + console.error("다운로드 오류:", error); + toast.error("파일 다운로드 중 오류가 발생했습니다."); + } finally { + setIsDownloading(false); + } + }; + + return ( + <Button + variant="outline" + size="sm" + onClick={handleDownload} + disabled={isDownloading} + > + {isDownloading ? ( + <> + <Loader2 className="h-4 w-4 mr-1 animate-spin" /> + 다운로드 중... + </> + ) : ( + <> + <Download className="h-4 w-4 mr-1" /> + 다운로드 + </> + )} + </Button> + ); +} + |
