diff --git a/components/email/ComposeEmail.tsx b/components/email/ComposeEmail.tsx index 74649f6d..6e727edb 100644 --- a/components/email/ComposeEmail.tsx +++ b/components/email/ComposeEmail.tsx @@ -6,8 +6,10 @@ import { } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; +import { Textarea } from '@/components/ui/textarea'; import { Card, CardContent, CardHeader, CardTitle, CardFooter } from '@/components/ui/card'; import DOMPurify from 'isomorphic-dompurify'; +import { Label } from '@/components/ui/label'; // Import ONLY from the centralized formatter import { @@ -186,12 +188,13 @@ export default function ComposeEmail(props: ComposeEmailAllProps) { setEmailContent(content); } - // Create a local variable to avoid type comparison issues - const isNewEmail = type === 'new'; - + // For type safety + const isReplyType = (t: 'new' | 'reply' | 'reply-all' | 'forward'): t is 'reply' | 'reply-all' | 'forward' => + t === 'reply' || t === 'reply-all' || t === 'forward'; + // Focus editor after initializing content setTimeout(() => { - if (!isNewEmail && editorRef.current) { + if (isReplyType(type) && editorRef.current) { // For replies/forwards, focus contentEditable editorRef.current.focus(); @@ -555,83 +558,223 @@ function LegacyAdapter({ replyTo, forwardFrom }: LegacyComposeEmailProps) { - // If not showing compose, return null - if (!showCompose) { - return null; - } + // Create a ref for the contentEditable div + const composeBodyRef = useRef(null); - // Determine email type - const determineType = (): 'new' | 'reply' | 'reply-all' | 'forward' => { - if (originalEmail) { - return originalEmail.type; + // Set the content of the contentEditable div on mount + useEffect(() => { + if (composeBodyRef.current && composeBody) { + composeBodyRef.current.innerHTML = composeBody; } - - if (composeSubject.startsWith('Re:')) { - return 'reply'; - } - - if (composeSubject.startsWith('Fwd:')) { - return 'forward'; - } - - return 'new'; + }, [composeBody, showCompose]); + + // Handle clicking the content editable area + const handleComposeAreaClick = () => { + composeBodyRef.current?.focus(); }; - // Create email message object if needed for replies/forwards - const emailForCompose = (() => { - const type = determineType(); - - // Only create an email object if we're replying or forwarding - if (type === 'new' || !composeBody) { - return null; + // Handle input events on the contentEditable div + const handleInput = () => { + if (composeBodyRef.current) { + setComposeBody(composeBodyRef.current.innerHTML); } + }; + + // Handle file attachment + const handleFileAttachment = (e: React.ChangeEvent) => { + if (!e.target.files || e.target.files.length === 0) return; - return { - id: 'temp-id', - messageId: '', + // Here you would normally process the files and add them to attachments + console.log('Files selected:', e.target.files); + + // Just a placeholder - in a real implementation you'd convert files to the format needed + const newAttachments = Array.from(e.target.files).map(file => ({ + name: file.name, + type: file.type, + size: file.size, + // In a real implementation you'd use FileReader to read the file content + })); + + // Add to existing attachments + setAttachments([...attachments, ...newAttachments]); + }; + + // Handle send email action + const handleSendEmail = async () => { + // Call the provided onSend handler with the email data + await onSend({ + to: composeTo, + cc: composeCc, + bcc: composeBcc, subject: composeSubject, - from: [{ name: '', address: '' }], - to: [{ name: '', address: '' }], - date: new Date(), - content: composeBody, - html: composeBody, - hasAttachments: false - }; - })(); + body: composeBody, + attachments + }); + }; + + if (!showCompose) return null; return (
-
- { - onCancel?.(); - setShowCompose(false); - }} - onSend={async (emailData: { - to: string; - cc?: string; - bcc?: string; - subject: string; - body: string; - attachments?: Array<{ - name: string; - content: string; - type: string; - }>; - }) => { - // Update legacy state before sending - setComposeTo(emailData.to); - if (emailData.cc) setComposeCc(emailData.cc); - if (emailData.bcc) setComposeBcc(emailData.bcc); - setComposeSubject(emailData.subject); - setComposeBody(emailData.body); - - // Call the legacy onSend function - await onSend(emailData); - }} - /> +
+ {/* Modal Header */} +
+

+ {replyTo ? 'Reply' : forwardFrom ? 'Forward' : 'New Message'} +

+ +
+ + {/* Modal Body */} +
+
+ {/* To Field */} +
+ + setComposeTo(e.target.value)} + placeholder="recipient@example.com" + className="w-full mt-1 bg-white border-gray-300 text-gray-900" + /> +
+ + {/* CC/BCC Toggle Buttons */} +
+ + +
+ + {/* CC Field */} + {showCc && ( +
+ + setComposeCc(e.target.value)} + placeholder="cc@example.com" + className="w-full mt-1 bg-white border-gray-300 text-gray-900" + /> +
+ )} + + {/* BCC Field */} + {showBcc && ( +
+ + setComposeBcc(e.target.value)} + placeholder="bcc@example.com" + className="w-full mt-1 bg-white border-gray-300 text-gray-900" + /> +
+ )} + + {/* Subject Field */} +
+ + setComposeSubject(e.target.value)} + placeholder="Enter subject" + className="w-full mt-1 bg-white border-gray-300 text-gray-900" + /> +
+ + {/* Message Body */} +
+ +
+
+
+
+ + {/* Modal Footer */} +
+
+ {/* File Input for Attachments */} + + +
+
+ + +
+
);