diff --git a/components/ComposeEmail.tsx b/components/ComposeEmail.tsx index d207721d..d02800ad 100644 --- a/components/ComposeEmail.tsx +++ b/components/ComposeEmail.tsx @@ -6,33 +6,21 @@ import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Textarea } from '@/components/ui/textarea'; import { Label } from '@/components/ui/label'; -import DOMPurify from 'isomorphic-dompurify'; +import { sanitizeHtml } from '@/lib/utils/email-formatter'; -// Add a CSS style block to handle the direction properly -const forceLTRStyles = ` -.force-ltr { - direction: ltr !important; - text-align: left !important; - unicode-bidi: isolate !important; - writing-mode: horizontal-tb !important; -} -.force-ltr * { - direction: ltr !important; - text-align: left !important; - unicode-bidi: isolate !important; -} -[dir="rtl"] .force-ltr, -[dir="rtl"] .force-ltr * { - direction: ltr !important; - text-align: left !important; -} +// Simple CSS for email styling - leverages our centralized sanitization for text direction +const emailStyles = ` .email-content { - direction: ltr !important; - text-align: left !important; + font-family: Arial, sans-serif; } -.email-content * { - direction: ltr !important; - text-align: left !important; +.quoted-content { + margin-top: 20px; + border-top: 1px solid #e2e2e2; + padding-top: 10px; + color: #555; +} +.user-message { + margin-bottom: 20px; } `; @@ -164,17 +152,19 @@ export default function ComposeEmail({ // Handle contentEditable input changes const handleUserMessageChange = () => { if (contentEditableRef.current) { - const content = contentEditableRef.current.innerHTML; + let content = contentEditableRef.current.innerHTML; // Check if this is the initial state or if the user has actually typed something if (content && content !== '
Write your message here...
') { setHasStartedTyping(true); } + // Sanitize the user's message using our centralized sanitizer + content = sanitizeHtml(content); setUserMessage(content); // Combine user message with quoted content for the full email body - const combined = `${content}${quotedContent ? `Write your message here...
'; - } - }} - dangerouslySetInnerHTML={hasStartedTyping ? { __html: userMessage } : { __html: 'Write your message here...
' }} - style={{ direction: 'ltr', textAlign: 'left' }} - /> - - {/* Original email content with clear visual separation */} - {quotedContent && ( - <> -Write your message here...
'; + } + }} + dangerouslySetInnerHTML={hasStartedTyping ? { __html: userMessage } : { __html: 'Write your message here...
' }} + /> +