diff --git a/frontend/src/components/Compose.tsx b/frontend/src/components/Compose.tsx new file mode 100644 index 00000000..f83cbeea --- /dev/null +++ b/frontend/src/components/Compose.tsx @@ -0,0 +1,83 @@ +import { useState } from 'react' +import { mailApi } from '../api/mailApi' +import { useMailStore } from '../store/mailStore' + +export default function Compose() { + const { replyTo, closeCompose, username } = useMailStore() + const [to, setTo] = useState(replyTo?.sender_addr || '') + const [cc, setCc] = useState('') + const [subject, setSubject] = useState( + replyTo ? (replyTo.subject.startsWith('Re:') ? replyTo.subject : `Re: ${replyTo.subject}`) : '' + ) + const [body, setBody] = useState( + replyTo + ? `\n\n---\n${replyTo.date}에 ${replyTo.sender} (${replyTo.sender_addr}) 님이 작성:\n${replyTo.body_text || '(HTML 메일)'}\n` + : '' + ) + const [sending, setSending] = useState(false) + const [error, setError] = useState('') + const [success, setSuccess] = useState(false) + const [showCc, setShowCc] = useState(false) + + const send = async () => { + if (!to.trim() || !subject.trim()) { setError('받는사람과 제목은 필수입니다'); return } + setSending(true); setError('') + try { + await mailApi.send({ to, cc: cc || undefined, subject, body }) + setSuccess(true) + setTimeout(closeCompose, 1500) + } catch (e: any) { + setError(e.response?.data?.detail || '발송에 실패했습니다') + } finally { setSending(false) } + } + + return ( +
e.target === e.currentTarget && closeCompose()}> +
+
+ ✏️ {replyTo ? '답장' : '새 메일'} + +
+ +
+
+ + {username} +
+
+ + setTo(e.target.value)} placeholder="수신자 이메일" /> + +
+ {showCc && ( +
+ + setCc(e.target.value)} placeholder="참조 이메일" /> +
+ )} +
+ + setSubject(e.target.value)} placeholder="제목 입력" /> +
+
+ +