diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-07-21 07:54:26 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-07-21 07:54:26 +0000 |
| commit | 14f61e24947fb92dd71ec0a7196a6e815f8e66da (patch) | |
| tree | 317c501d64662d05914330628f867467fba78132 /lib/tech-vendors/table/attachmentButton.tsx | |
| parent | 194bd4bd7e6144d5c09c5e3f5476d254234dce72 (diff) | |
(최겸)기술영업 RFQ 담당자 초대, 요구사항 반영
Diffstat (limited to 'lib/tech-vendors/table/attachmentButton.tsx')
| -rw-r--r-- | lib/tech-vendors/table/attachmentButton.tsx | 152 |
1 files changed, 76 insertions, 76 deletions
diff --git a/lib/tech-vendors/table/attachmentButton.tsx b/lib/tech-vendors/table/attachmentButton.tsx index 12dc6f77..2754c9f0 100644 --- a/lib/tech-vendors/table/attachmentButton.tsx +++ b/lib/tech-vendors/table/attachmentButton.tsx @@ -1,76 +1,76 @@ -'use client'; - -import React from 'react'; -import { Button } from '@/components/ui/button'; -import { PaperclipIcon } from 'lucide-react'; -import { Badge } from '@/components/ui/badge'; -import { toast } from 'sonner'; -import { type VendorAttach } from '@/db/schema/vendors'; -import { downloadTechVendorAttachments } from '../service'; - -interface AttachmentsButtonProps { - vendorId: number; - hasAttachments: boolean; - attachmentsList?: VendorAttach[]; -} - -export function AttachmentsButton({ vendorId, hasAttachments, attachmentsList = [] }: AttachmentsButtonProps) { - if (!hasAttachments) return null; - - const handleDownload = async () => { - try { - toast.loading('첨부파일을 준비하는 중...'); - - // 서버 액션 호출 - const result = await downloadTechVendorAttachments(vendorId); - - // 로딩 토스트 닫기 - toast.dismiss(); - - if (!result || !result.url) { - toast.error('다운로드 준비 중 오류가 발생했습니다.'); - return; - } - - // 파일 다운로드 트리거 - toast.success('첨부파일 다운로드가 시작되었습니다.'); - - // 다운로드 링크 열기 - const a = document.createElement('a'); - a.href = result.url; - a.download = result.fileName || '첨부파일.zip'; - a.style.display = 'none'; - document.body.appendChild(a); - a.click(); - document.body.removeChild(a); - - } catch (error) { - toast.dismiss(); - toast.error('첨부파일 다운로드에 실패했습니다.'); - console.error('첨부파일 다운로드 오류:', error); - } - }; - - return ( - <> - {attachmentsList && attachmentsList.length > 0 && - <Button - variant="ghost" - size="icon" - onClick={handleDownload} - title={`${attachmentsList.length}개 파일 다운로드`} - > - <PaperclipIcon className="h-4 w-4 text-muted-foreground group-hover:text-primary transition-colors" /> - {/* {attachmentsList.length > 1 && ( - <Badge - variant="secondary" - className="pointer-events-none absolute -top-1 -right-1 h-4 min-w-[1rem] p-0 text-[0.425rem] leading-none flex items-center justify-center" - > - {attachmentsList.length} - </Badge> - )} */} - </Button> - } - </> - ); -} +'use client';
+
+import React from 'react';
+import { Button } from '@/components/ui/button';
+import { PaperclipIcon } from 'lucide-react';
+import { Badge } from '@/components/ui/badge';
+import { toast } from 'sonner';
+import { type VendorAttach } from '@/db/schema/vendors';
+import { downloadTechVendorAttachments } from '../service';
+
+interface AttachmentsButtonProps {
+ vendorId: number;
+ hasAttachments: boolean;
+ attachmentsList?: VendorAttach[];
+}
+
+export function AttachmentsButton({ vendorId, hasAttachments, attachmentsList = [] }: AttachmentsButtonProps) {
+ if (!hasAttachments) return null;
+
+ const handleDownload = async () => {
+ try {
+ toast.loading('첨부파일을 준비하는 중...');
+
+ // 서버 액션 호출
+ const result = await downloadTechVendorAttachments(vendorId);
+
+ // 로딩 토스트 닫기
+ toast.dismiss();
+
+ if (!result || !result.url) {
+ toast.error('다운로드 준비 중 오류가 발생했습니다.');
+ return;
+ }
+
+ // 파일 다운로드 트리거
+ toast.success('첨부파일 다운로드가 시작되었습니다.');
+
+ // 다운로드 링크 열기
+ const a = document.createElement('a');
+ a.href = result.url;
+ a.download = result.fileName || '첨부파일.zip';
+ a.style.display = 'none';
+ document.body.appendChild(a);
+ a.click();
+ document.body.removeChild(a);
+
+ } catch (error) {
+ toast.dismiss();
+ toast.error('첨부파일 다운로드에 실패했습니다.');
+ console.error('첨부파일 다운로드 오류:', error);
+ }
+ };
+
+ return (
+ <>
+ {attachmentsList && attachmentsList.length > 0 &&
+ <Button
+ variant="ghost"
+ size="icon"
+ onClick={handleDownload}
+ title={`${attachmentsList.length}개 파일 다운로드`}
+ >
+ <PaperclipIcon className="h-4 w-4 text-muted-foreground group-hover:text-primary transition-colors" />
+ {/* {attachmentsList.length > 1 && (
+ <Badge
+ variant="secondary"
+ className="pointer-events-none absolute -top-1 -right-1 h-4 min-w-[1rem] p-0 text-[0.425rem] leading-none flex items-center justify-center"
+ >
+ {attachmentsList.length}
+ </Badge>
+ )} */}
+ </Button>
+ }
+ </>
+ );
+}
|
