courrier preview
This commit is contained in:
parent
c355585355
commit
41480e6666
@ -17,14 +17,13 @@ import ComposeEmailFooter from './ComposeEmailFooter';
|
||||
import RichEmailEditor from './RichEmailEditor';
|
||||
import QuotedEmailContent from './QuotedEmailContent';
|
||||
|
||||
// Import ONLY from the centralized formatter
|
||||
// Import from the centralized utils
|
||||
import {
|
||||
formatReplyEmail,
|
||||
formatForwardedEmail,
|
||||
formatEmailAddresses,
|
||||
type EmailMessage,
|
||||
type EmailAddress
|
||||
} from '@/lib/utils/email-formatter';
|
||||
formatEmailAddresses
|
||||
} from '@/lib/utils/email-utils';
|
||||
import { EmailMessage, EmailAddress } from '@/types/email';
|
||||
|
||||
/**
|
||||
* CENTRAL EMAIL COMPOSER COMPONENT
|
||||
@ -88,41 +87,31 @@ export default function ComposeEmail(props: ComposeEmailProps) {
|
||||
try {
|
||||
// Set recipients based on type
|
||||
if (type === 'reply' || type === 'reply-all') {
|
||||
// Reply goes to the original sender
|
||||
setTo(formatEmailAddresses(initialEmail.from || []));
|
||||
// Get formatted data for reply
|
||||
const formatted = formatReplyEmail(initialEmail, type);
|
||||
|
||||
// For reply-all, include all original recipients in CC
|
||||
if (type === 'reply-all') {
|
||||
const allRecipients = [
|
||||
...(initialEmail.to || []),
|
||||
...(initialEmail.cc || [])
|
||||
];
|
||||
setCc(formatEmailAddresses(allRecipients));
|
||||
}
|
||||
|
||||
// Set subject with Re: prefix
|
||||
const subjectBase = initialEmail.subject || '(No subject)';
|
||||
const subject = subjectBase.match(/^Re:/i) ? subjectBase : `Re: ${subjectBase}`;
|
||||
setSubject(subject);
|
||||
|
||||
// Format the reply content
|
||||
const { content } = formatReplyEmail(initialEmail, type);
|
||||
setEmailContent(content);
|
||||
|
||||
// Show CC field if there are CC recipients
|
||||
if (initialEmail.cc && initialEmail.cc.length > 0) {
|
||||
// Set the recipients
|
||||
setTo(formatted.to);
|
||||
if (formatted.cc) {
|
||||
setCc(formatted.cc);
|
||||
setShowCc(true);
|
||||
}
|
||||
|
||||
// Set subject
|
||||
setSubject(formatted.subject);
|
||||
|
||||
// Set the email content (use HTML if available)
|
||||
setEmailContent(formatted.content.html || formatted.content.text);
|
||||
}
|
||||
else if (type === 'forward') {
|
||||
// Set subject with Fwd: prefix
|
||||
const subjectBase = initialEmail.subject || '(No subject)';
|
||||
const subject = subjectBase.match(/^(Fwd|FW|Forward):/i) ? subjectBase : `Fwd: ${subjectBase}`;
|
||||
setSubject(subject);
|
||||
// Get formatted data for forward
|
||||
const formatted = formatForwardedEmail(initialEmail);
|
||||
|
||||
// Format the forward content
|
||||
const { content } = formatForwardedEmail(initialEmail);
|
||||
setEmailContent(content);
|
||||
// Set subject
|
||||
setSubject(formatted.subject);
|
||||
|
||||
// Set the email content (use HTML if available)
|
||||
setEmailContent(formatted.content.html || formatted.content.text);
|
||||
|
||||
// If the original email has attachments, we should include them
|
||||
if (initialEmail.attachments && initialEmail.attachments.length > 0) {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
'use client';
|
||||
|
||||
import React, { useMemo, CSSProperties } from 'react';
|
||||
import { renderEmailContent, normalizeEmailContent } from '@/lib/utils/email-utils';
|
||||
import { renderEmailContent } from '@/lib/utils/email-utils';
|
||||
import { EmailContent } from '@/types/email';
|
||||
|
||||
interface EmailContentDisplayProps {
|
||||
@ -44,13 +44,42 @@ const EmailContentDisplay: React.FC<EmailContentDisplayProps> = ({
|
||||
return content as EmailContent;
|
||||
}
|
||||
|
||||
// Special case for simple string content
|
||||
if (typeof content === 'string') {
|
||||
return normalizeEmailContent({ content });
|
||||
// Special case for email message with content property
|
||||
if (content && typeof content === 'object' && content.content &&
|
||||
typeof content.content === 'object' &&
|
||||
'text' in content.content &&
|
||||
'isHtml' in content.content) {
|
||||
return content.content as EmailContent;
|
||||
}
|
||||
|
||||
// Otherwise normalize it
|
||||
return normalizeEmailContent(content);
|
||||
// Special case for simple string content
|
||||
if (typeof content === 'string') {
|
||||
return {
|
||||
text: content,
|
||||
isHtml: content.trim().startsWith('<'),
|
||||
direction: 'ltr'
|
||||
} as EmailContent;
|
||||
}
|
||||
|
||||
// For HTML/text properties
|
||||
if (content && typeof content === 'object') {
|
||||
if (content.html || content.text) {
|
||||
return {
|
||||
html: content.html,
|
||||
text: content.text || '',
|
||||
isHtml: !!content.html,
|
||||
direction: 'ltr'
|
||||
} as EmailContent;
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback
|
||||
console.warn('EmailContentDisplay: Unable to properly normalize content format');
|
||||
return {
|
||||
text: 'Content format not supported',
|
||||
isHtml: false,
|
||||
direction: 'ltr'
|
||||
} as EmailContent;
|
||||
} catch (error) {
|
||||
console.error('Error normalizing content in EmailContentDisplay:', error);
|
||||
return {
|
||||
@ -114,10 +143,10 @@ const EmailContentDisplay: React.FC<EmailContentDisplayProps> = ({
|
||||
{typeof content === 'object' && (
|
||||
<p><strong>Keys:</strong> {Object.keys(content).join(', ')}</p>
|
||||
)}
|
||||
<p><strong>Normalized:</strong> {normalizedContent.isHtml ? 'HTML' : 'Text'}</p>
|
||||
<p><strong>Direction:</strong> {normalizedContent.direction}</p>
|
||||
<p><strong>Has HTML:</strong> {!!normalizedContent.html}</p>
|
||||
<p><strong>Text Length:</strong> {normalizedContent.text?.length || 0}</p>
|
||||
<p><strong>Normalized:</strong> {normalizedContent?.isHtml ? 'HTML' : 'Text'}</p>
|
||||
<p><strong>Direction:</strong> {normalizedContent?.direction}</p>
|
||||
<p><strong>Has HTML:</strong> {!!normalizedContent?.html}</p>
|
||||
<p><strong>Text Length:</strong> {normalizedContent?.text?.length || 0}</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
|
||||
@ -191,7 +191,7 @@ export default function EmailPreview({ email, loading = false, onReply }: EmailP
|
||||
</div>
|
||||
|
||||
{/* Attachments list */}
|
||||
{hasAttachments && (
|
||||
{hasAttachments && standardizedEmail.attachments && (
|
||||
<div className="px-6 py-3 border-b bg-muted/20">
|
||||
<h3 className="text-sm font-medium mb-2">Attachments ({standardizedEmail.attachments.length})</h3>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user