diff options
Diffstat (limited to 'lib/rfq-last/vendor')
| -rw-r--r-- | lib/rfq-last/vendor/send-rfq-dialog.tsx | 61 |
1 files changed, 55 insertions, 6 deletions
diff --git a/lib/rfq-last/vendor/send-rfq-dialog.tsx b/lib/rfq-last/vendor/send-rfq-dialog.tsx index 42470ecc..bf90bc6e 100644 --- a/lib/rfq-last/vendor/send-rfq-dialog.tsx +++ b/lib/rfq-last/vendor/send-rfq-dialog.tsx @@ -545,7 +545,7 @@ export function SendRfqDialog({ setVendorsWithRecipients( selectedVendors.map(v => ({ ...v, - selectedMainEmail: v.primaryEmail || v.vendorEmail || '', + selectedMainEmail: '', // 기본값 제거 - 사용자가 직접 선택하도록 additionalEmails: [], customEmails: [] })) @@ -838,10 +838,53 @@ export function SendRfqDialog({ // 전송 처리 const handleSend = async () => { try { - // 유효성 검사 - const vendorsWithoutEmail = vendorsWithRecipients.filter(v => !v.selectedMainEmail); - if (vendorsWithoutEmail.length > 0) { - toast.error(`${vendorsWithoutEmail.map(v => v.vendorName).join(', ')}의 주 수신자를 선택해주세요.`); + // 주 수신자가 없는 벤더 확인 (가장 먼저 검증) + const vendorsWithoutMainEmail = vendorsWithRecipients.filter(v => !v.selectedMainEmail || v.selectedMainEmail.trim() === ''); + + if (vendorsWithoutMainEmail.length > 0) { + // 사용 가능한 이메일이 있는지 확인 + const vendorsWithAvailableEmails = vendorsWithoutMainEmail.filter(v => { + const hasRepresentativeEmail = !!v.representativeEmail; + const hasVendorEmail = !!v.vendorEmail; + const hasContacts = v.contacts && v.contacts.length > 0; + const hasCustomEmails = v.customEmails && v.customEmails.length > 0; + const hasAdditionalEmails = v.additionalEmails && v.additionalEmails.length > 0; + + return hasRepresentativeEmail || hasVendorEmail || hasContacts || hasCustomEmails || hasAdditionalEmails; + }); + + if (vendorsWithAvailableEmails.length > 0) { + // 사용 가능한 이메일이 있지만 주 수신자가 선택되지 않은 경우 + toast.error( + `${vendorsWithAvailableEmails.map(v => v.vendorName).join(', ')}의 주 수신자를 선택해주세요. ` + + `(CC에서 선택하거나 수신자 추가 버튼으로 이메일을 추가한 후 주 수신자로 선택해주세요)` + ); + return; + } + + // 사용 가능한 이메일이 전혀 없는 경우 + const vendorsWithoutAnyEmail = vendorsWithoutMainEmail.filter(v => { + const hasRepresentativeEmail = !!v.representativeEmail; + const hasVendorEmail = !!v.vendorEmail; + const hasContacts = v.contacts && v.contacts.length > 0; + const hasCustomEmails = v.customEmails && v.customEmails.length > 0; + + return !hasRepresentativeEmail && !hasVendorEmail && !hasContacts && !hasCustomEmails; + }); + + if (vendorsWithoutAnyEmail.length > 0) { + toast.error( + `${vendorsWithoutAnyEmail.map(v => v.vendorName).join(', ')}에 사용 가능한 이메일이 없습니다. ` + + `수신자 추가 버튼(+)을 눌러 이메일을 추가해주세요.` + ); + return; + } + } + + // 모든 벤더가 주 수신자를 가지고 있는지 최종 확인 + const finalCheck = vendorsWithRecipients.filter(v => !v.selectedMainEmail || v.selectedMainEmail.trim() === ''); + if (finalCheck.length > 0) { + toast.error(`${finalCheck.map(v => v.vendorName).join(', ')}의 주 수신자를 선택해주세요.`); return; } @@ -874,6 +917,12 @@ export function SendRfqDialog({ ); }, [vendorsWithRecipients]); + // 발송 가능 여부 확인 (모든 벤더가 주 수신자를 가지고 있어야 함) + const canSend = React.useMemo(() => { + if (vendorsWithRecipients.length === 0) return false; + return vendorsWithRecipients.every(v => v.selectedMainEmail && v.selectedMainEmail.trim() !== ''); + }, [vendorsWithRecipients]); + return ( <Dialog open={open} onOpenChange={onOpenChange}> <DialogContent className="max-w-5xl max-h-[90vh] flex flex-col"> @@ -1653,7 +1702,7 @@ export function SendRfqDialog({ </Button> <Button onClick={handleSend} - disabled={isSending || isGeneratingPdfs} + disabled={isSending || isGeneratingPdfs || !canSend} > {isGeneratingPdfs ? ( <> |
