From 195f8b7115b0df7e1bd49822b6a1de7e6c6749ef Mon Sep 17 00:00:00 2001 From: alma Date: Sat, 26 Apr 2025 11:58:58 +0200 Subject: [PATCH] courrier clean 2 --- components/ComposeEmail.tsx | 342 ++++++++++++++++++------------------ 1 file changed, 169 insertions(+), 173 deletions(-) diff --git a/components/ComposeEmail.tsx b/components/ComposeEmail.tsx index 2e8965db..fe049a85 100644 --- a/components/ComposeEmail.tsx +++ b/components/ComposeEmail.tsx @@ -4,7 +4,8 @@ import { useState, useRef, useEffect } from 'react'; import { X, Paperclip, ChevronDown, ChevronUp, SendHorizontal, Loader2 } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; -import { Card, CardContent, CardHeader, CardTitle, CardFooter } from '@/components/ui/card'; +import { Textarea } from '@/components/ui/textarea'; +import { Label } from '@/components/ui/label'; import DOMPurify from 'isomorphic-dompurify'; import { formatEmailForReply, formatEmailForForward } from '@/lib/email-formatter'; @@ -84,17 +85,8 @@ export default function ComposeEmail({ onCancel }: ComposeEmailProps) { const [isSending, setIsSending] = useState(false); - const editorRef = useRef(null); const fileInputRef = useRef(null); - const composeBodyRef = useRef(null); - useEffect(() => { - if (editorRef.current) { - editorRef.current.focus(); - } - }, [showCompose]); - - // Initialize content when replying or forwarding useEffect(() => { // Initialize reply if replyTo is provided if (replyTo) { @@ -115,17 +107,15 @@ export default function ComposeEmail({ }); setComposeBody(bodyContent); - - // Show CC if needed for reply-all - if (formattedEmail.cc) { - setComposeCc(formattedEmail.cc); - setShowCc(true); - } - } else if (forwardFrom) { - // Initialize forward email if forwardFrom is provided + } + }, [replyTo, setComposeTo, setComposeSubject, setComposeBody]); + + useEffect(() => { + // Initialize forward email if forwardFrom is provided + if (forwardFrom) { initializeForwardedEmail(forwardFrom); } - }, [replyTo, forwardFrom]); + }, [forwardFrom]); // Initialize forwarded email content const initializeForwardedEmail = async (email: any) => { @@ -174,171 +164,177 @@ export default function ComposeEmail({ `); }; - if (!showCompose) return null; - - const handleFileSelection = (e: React.ChangeEvent) => { - if (e.target.files && e.target.files.length > 0) { - const newAttachments = Array.from(e.target.files).map(file => ({ - name: file.name, - type: file.type, - size: file.size, - file - })); - setAttachments([...attachments, ...newAttachments]); + // Handle file attachment selection + const handleFileAttachment = (e: React.ChangeEvent) => { + if (e.target.files) { + const newFiles = Array.from(e.target.files); + setAttachments([...attachments, ...newFiles]); } }; - // Body input area - const renderBodyInput = () => ( -
{ - const target = e.target as HTMLDivElement; - setComposeBody(target.innerHTML); - }} - ref={composeBodyRef} - style={{ direction: 'ltr' }} - /> - ); - return ( - - -
- {replyTo ? 'Reply' : forwardFrom ? 'Forward' : 'New Message'} - -
-
- -
-
- To: - setComposeTo(e.target.value)} - /> -
- - {showCc && ( -
- Cc: - setComposeCc(e.target.value)} - /> + <> + {/* Compose Email Modal */} + {showCompose && ( +
+
+ {/* Modal Header */} +
+

+ {composeSubject.startsWith('Re:') ? 'Reply' : + composeSubject.startsWith('Fwd:') ? 'Forward' : 'New Message'} +

+
- )} - {showBcc && ( -
- Bcc: - setComposeBcc(e.target.value)} - /> -
- )} + {/* 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 */} +
+ + +
-
- Subject: - setComposeSubject(e.target.value)} - /> -
- - {renderBodyInput()} - - {attachments.length > 0 && ( -
-

Attachments:

-
- {attachments.map((file, index) => ( -
- - {file.name} - + {/* 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 */} +
+ +