From 6c11fccc84f4c84fa72ee01f9caad9f76f35cea2 Mon Sep 17 00:00:00 2001 From: dujinkim Date: Tue, 16 Sep 2025 09:20:58 +0000 Subject: (대표님, 최겸) 계약, 업로드 관련, 메뉴처리, 입찰, 프리쿼트, rfqLast관련, tbeLast관련 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tbe-last/table/email-documents-dialog.tsx | 334 ++++++++++++++++++++++++++ 1 file changed, 334 insertions(+) create mode 100644 lib/tbe-last/table/email-documents-dialog.tsx (limited to 'lib/tbe-last/table/email-documents-dialog.tsx') diff --git a/lib/tbe-last/table/email-documents-dialog.tsx b/lib/tbe-last/table/email-documents-dialog.tsx new file mode 100644 index 00000000..415cd428 --- /dev/null +++ b/lib/tbe-last/table/email-documents-dialog.tsx @@ -0,0 +1,334 @@ +// lib/tbe-last/table/dialogs/email-documents-dialog.tsx + +"use client" + +import * as React from "react" +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, +} from "@/components/ui/dialog" +import { Button } from "@/components/ui/button" +import { Input } from "@/components/ui/input" +import { Label } from "@/components/ui/label" +import { Textarea } from "@/components/ui/textarea" +import { Badge } from "@/components/ui/badge" +import { ScrollArea } from "@/components/ui/scroll-area" +import { + FileText, + X, + Plus, + Mail, + Loader2, + AlertCircle, +} from "lucide-react" +import { toast } from "sonner" +import { sendDocumentsEmail } from "../service" + +interface EmailDocumentsDialogProps { + open: boolean + onOpenChange: (open: boolean) => void + selectedDocuments: any[] + sessionDetail: any + onSuccess?: () => void +} + +export function EmailDocumentsDialog({ + open, + onOpenChange, + selectedDocuments, + sessionDetail, + onSuccess +}: EmailDocumentsDialogProps) { + const [recipients, setRecipients] = React.useState([]) + const [currentEmail, setCurrentEmail] = React.useState("") + const [ccRecipients, setCcRecipients] = React.useState([]) + const [currentCc, setCurrentCc] = React.useState("") + const [comments, setComments] = React.useState("") + const [isLoading, setIsLoading] = React.useState(false) + + // 이메일 유효성 검사 + const validateEmail = (email: string) => { + const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/ + return re.test(email) + } + + // 수신자 추가 + const handleAddRecipient = () => { + if (currentEmail && validateEmail(currentEmail)) { + if (!recipients.includes(currentEmail)) { + setRecipients([...recipients, currentEmail]) + setCurrentEmail("") + } else { + toast.error("이미 추가된 이메일입니다") + } + } else { + toast.error("올바른 이메일 주소를 입력하세요") + } + } + + // CC 수신자 추가 + const handleAddCc = () => { + if (currentCc && validateEmail(currentCc)) { + if (!ccRecipients.includes(currentCc)) { + setCcRecipients([...ccRecipients, currentCc]) + setCurrentCc("") + } else { + toast.error("이미 추가된 이메일입니다") + } + } else { + toast.error("올바른 이메일 주소를 입력하세요") + } + } + + // 수신자 제거 + const removeRecipient = (email: string) => { + setRecipients(recipients.filter(r => r !== email)) + } + + // CC 수신자 제거 + const removeCc = (email: string) => { + setCcRecipients(ccRecipients.filter(r => r !== email)) + } + + // 이메일 전송 + const handleSendEmail = async () => { + if (recipients.length === 0) { + toast.error("최소 한 명의 수신자를 추가하세요") + return + } + + if (selectedDocuments.length === 0) { + toast.error("선택된 문서가 없습니다") + return + } + + setIsLoading(true) + + try { + const result = await sendDocumentsEmail({ + to: recipients, + cc: ccRecipients.length > 0 ? ccRecipients : undefined, + documents: selectedDocuments.map(doc => ({ + documentId: doc.documentId, + documentReviewId: doc.documentReviewId, + documentName: doc.documentName, + filePath: doc.filePath, + documentType: doc.documentType, + documentSource: doc.documentSource, + reviewStatus: doc.reviewStatus, + })), + comments, + sessionInfo: { + sessionId: sessionDetail?.session?.tbeSessionId, + sessionTitle: sessionDetail?.session?.title, + buyerName: sessionDetail?.session?.buyerName, + vendorName: sessionDetail?.session?.vendorName, + } + }) + + if (result.success) { + toast.success("이메일이 성공적으로 전송되었습니다") + onSuccess?.() + onOpenChange(false) + + // 초기화 + setRecipients([]) + setCcRecipients([]) + setComments("") + setCurrentEmail("") + setCurrentCc("") + } else { + throw new Error(result.error || "이메일 전송 실패") + } + } catch (error) { + console.error("Email send error:", error) + toast.error(error instanceof Error ? error.message : "이메일 전송 중 오류가 발생했습니다") + } finally { + setIsLoading(false) + } + } + + // 파일 크기 포맷 + const formatFileSize = (bytes: number) => { + if (bytes === 0) return '0 Bytes' + const k = 1024 + const sizes = ['Bytes', 'KB', 'MB', 'GB'] + const i = Math.floor(Math.log(bytes) / Math.log(k)) + return Math.round(bytes / Math.pow(k, i) * 100) / 100 + ' ' + sizes[i] + } + + return ( + + + + Send Documents via Email + + 선택한 {selectedDocuments.length}개의 문서를 이메일로 전송합니다 + + + +
+ {/* 수신자 입력 */} +
+ +
+ setCurrentEmail(e.target.value)} + onKeyPress={(e) => { + if (e.key === 'Enter') { + e.preventDefault() + handleAddRecipient() + } + }} + /> + +
+
+ {recipients.map((email) => ( + + {email} + removeRecipient(email)} + /> + + ))} +
+
+ + {/* CC 입력 */} +
+ +
+ setCurrentCc(e.target.value)} + onKeyPress={(e) => { + if (e.key === 'Enter') { + e.preventDefault() + handleAddCc() + } + }} + /> + +
+
+ {ccRecipients.map((email) => ( + + {email} + removeCc(email)} + /> + + ))} +
+
+ + {/* 코멘트 입력 */} +
+ +