From 3584f72bf5380639c3552a8fdb9dbf5ebde21a04 Mon Sep 17 00:00:00 2001 From: alma Date: Wed, 30 Apr 2025 23:18:20 +0200 Subject: [PATCH] courrier preview --- components/email/ComposeEmail.tsx | 153 ++++++++++++++++++++---------- 1 file changed, 105 insertions(+), 48 deletions(-) diff --git a/components/email/ComposeEmail.tsx b/components/email/ComposeEmail.tsx index eb0d7f8d..84e9a13d 100644 --- a/components/email/ComposeEmail.tsx +++ b/components/email/ComposeEmail.tsx @@ -12,10 +12,7 @@ import { Label } from '@/components/ui/label'; // Import sub-components import ComposeEmailHeader from './ComposeEmailHeader'; -import ComposeEmailForm from './ComposeEmailForm'; -import ComposeEmailFooter from './ComposeEmailFooter'; import RichEmailEditor from './RichEmailEditor'; -import QuotedEmailContent from './QuotedEmailContent'; // Import from the centralized utils import { @@ -33,9 +30,6 @@ import { EmailMessage, EmailAddress } from '@/types/email'; * * All code that needs to compose emails should import this component from: * @/components/email/ComposeEmail - * - * It uses the centralized email formatter from @/lib/utils/email-formatter.ts - * for consistent handling of email content and text direction. */ // Define interface for the modern props @@ -57,12 +51,6 @@ interface ComposeEmailProps { }) => Promise; } -// Add a helper to fix table widths in HTML -function fixTableWidths(html: string): string { - if (!html) return html; - return html.replace(/]*width)/g, '(''); const [subject, setSubject] = useState(''); const [emailContent, setEmailContent] = useState(''); + const [quotedContent, setQuotedContent] = useState(''); const [showCc, setShowCc] = useState(false); const [showBcc, setShowBcc] = useState(false); const [sending, setSending] = useState(false); @@ -81,6 +70,8 @@ export default function ComposeEmail(props: ComposeEmailProps) { type: string; }>>([]); + const editorRef = useRef(null); + // Initialize the form when replying to or forwarding an email useEffect(() => { if (initialEmail && type !== 'new') { @@ -100,8 +91,11 @@ export default function ComposeEmail(props: ComposeEmailProps) { // Set subject setSubject(formatted.subject); - // Set the email content (use HTML if available) - setEmailContent(formatted.content.html || formatted.content.text); + // Set the quoted content (original email) + setQuotedContent(formatted.content.html || formatted.content.text); + + // Start with empty content for the reply + setEmailContent(''); } else if (type === 'forward') { // Get formatted data for forward @@ -110,8 +104,11 @@ export default function ComposeEmail(props: ComposeEmailProps) { // Set subject setSubject(formatted.subject); - // Set the email content (use HTML if available) - setEmailContent(formatted.content.html || formatted.content.text); + // Set the quoted content (original email) + setQuotedContent(formatted.content.html || formatted.content.text); + + // Start with empty content for the forward + setEmailContent(''); // If the original email has attachments, we should include them if (initialEmail.attachments && initialEmail.attachments.length > 0) { @@ -154,12 +151,17 @@ export default function ComposeEmail(props: ComposeEmailProps) { setSending(true); try { + // Combine the new content with the quoted content + const fullContent = type !== 'new' + ? `${emailContent}
${quotedContent}
` + : emailContent; + await onSend({ to, cc: cc || undefined, bcc: bcc || undefined, subject, - body: emailContent, + body: fullContent, attachments }); @@ -173,34 +175,26 @@ export default function ComposeEmail(props: ComposeEmailProps) { } }; - // Additional effect to ensure we scroll to the top and focus the editor + // Focus and scroll to top when opened useEffect(() => { - // Focus the editor and ensure it's scrolled to the top - const editorContainer = document.querySelector('.ql-editor') as HTMLElement; - if (editorContainer) { - // Set timeout to ensure DOM is fully rendered - setTimeout(() => { - // Focus the editor - editorContainer.focus(); + setTimeout(() => { + if (editorRef.current) { + editorRef.current.focus(); - // Make sure all scroll containers are at the top - editorContainer.scrollTop = 0; - - // Find all possible scrollable parent containers - const scrollContainers = [ - document.querySelector('.ql-container') as HTMLElement, - document.querySelector('.rich-email-editor-container') as HTMLElement, - document.querySelector('.h-full.flex.flex-col.p-6') as HTMLElement + // Scroll to top + const scrollElements = [ + editorRef.current, + document.querySelector('.overflow-y-auto'), + document.querySelector('.compose-email-body') ]; - // Scroll all containers to top - scrollContainers.forEach(container => { - if (container) { - container.scrollTop = 0; + scrollElements.forEach(el => { + if (el instanceof HTMLElement) { + el.scrollTop = 0; } }); - }, 100); - } + } + }, 100); }, []); return ( @@ -209,7 +203,7 @@ export default function ComposeEmail(props: ComposeEmailProps) { type={type} onClose={onClose} /> -
+
{/* To Field */}
@@ -281,17 +275,30 @@ export default function ComposeEmail(props: ComposeEmailProps) { />
- {/* Message Body */} + {/* Message Body - Simplified Editor */}
- +
+ {/* Simple editor for new content */} +
setEmailContent(e.currentTarget.innerHTML)} + /> + + {/* Quoted content from original email */} + {quotedContent && ( +
+
+
+ )} +
@@ -376,6 +383,56 @@ export default function ComposeEmail(props: ComposeEmailProps) {
+ + {/* Styles for email display */} +
); } \ No newline at end of file