courrier preview
This commit is contained in:
parent
5ea88d2d6c
commit
5adf1a9a62
@ -8,7 +8,11 @@ import { Button } from '@/components/ui/button';
|
|||||||
import { Email } from '@/hooks/use-courrier';
|
import { Email } from '@/hooks/use-courrier';
|
||||||
|
|
||||||
interface EmailDetailViewProps {
|
interface EmailDetailViewProps {
|
||||||
email: Email & { html?: string; text?: string };
|
email: Email & {
|
||||||
|
html?: string;
|
||||||
|
text?: string;
|
||||||
|
starred?: boolean; // Add starred property to interface
|
||||||
|
};
|
||||||
onBack: () => void;
|
onBack: () => void;
|
||||||
onReply: () => void;
|
onReply: () => void;
|
||||||
onReplyAll: () => void;
|
onReplyAll: () => void;
|
||||||
@ -26,8 +30,9 @@ export default function EmailDetailView({
|
|||||||
}: EmailDetailViewProps) {
|
}: EmailDetailViewProps) {
|
||||||
|
|
||||||
// Format date for display
|
// Format date for display
|
||||||
const formatDate = (dateString: string) => {
|
const formatDate = (dateString: string | Date) => {
|
||||||
const date = new Date(dateString);
|
// Convert to Date object if string
|
||||||
|
const date = typeof dateString === 'string' ? new Date(dateString) : dateString;
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
|
|
||||||
if (date.toDateString() === now.toDateString()) {
|
if (date.toDateString() === now.toDateString()) {
|
||||||
@ -40,8 +45,43 @@ export default function EmailDetailView({
|
|||||||
// Render email content based on the email body
|
// Render email content based on the email body
|
||||||
const renderEmailContent = () => {
|
const renderEmailContent = () => {
|
||||||
try {
|
try {
|
||||||
// Use fallback for content, html, or text
|
console.log('EmailDetailView renderEmailContent', {
|
||||||
return <div dangerouslySetInnerHTML={{ __html: email.content || email.html || email.text || '' }} />;
|
hasContent: !!email.content,
|
||||||
|
contentType: typeof email.content,
|
||||||
|
hasHtml: !!email.html,
|
||||||
|
hasText: !!email.text
|
||||||
|
});
|
||||||
|
|
||||||
|
// Determine what content to use and how to handle it
|
||||||
|
let contentToUse = '';
|
||||||
|
|
||||||
|
if (email.content) {
|
||||||
|
// If content is a string, use it directly
|
||||||
|
if (typeof email.content === 'string') {
|
||||||
|
contentToUse = email.content;
|
||||||
|
}
|
||||||
|
// If content is an object with html/text properties
|
||||||
|
else if (typeof email.content === 'object') {
|
||||||
|
contentToUse = email.content.html || email.content.text || '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Fall back to html or text properties if content is not available
|
||||||
|
else if (email.html) {
|
||||||
|
contentToUse = email.html;
|
||||||
|
}
|
||||||
|
else if (email.text) {
|
||||||
|
// Convert plain text to HTML with line breaks
|
||||||
|
contentToUse = email.text
|
||||||
|
.replace(/&/g, '&')
|
||||||
|
.replace(/</g, '<')
|
||||||
|
.replace(/>/g, '>')
|
||||||
|
.replace(/\n/g, '<br>');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return content or fallback message
|
||||||
|
return contentToUse ?
|
||||||
|
<div dangerouslySetInnerHTML={{ __html: contentToUse }} /> :
|
||||||
|
<div className="text-gray-500">No content available</div>;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Error rendering email:', e);
|
console.error('Error rendering email:', e);
|
||||||
return <div className="text-gray-500">Failed to render email content</div>;
|
return <div className="text-gray-500">Failed to render email content</div>;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user