'use client'; import React, { useState, useEffect } from 'react'; import { Loader2, Paperclip, FileDown } from 'lucide-react'; import { sanitizeHtml } from '@/lib/utils/email-formatter'; import { Button } from '@/components/ui/button'; import { Email } from '@/hooks/use-courrier'; import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'; interface EmailContentProps { email: Email; } export default function EmailContent({ email }: EmailContentProps) { const [content, setContent] = useState(null); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(null); useEffect(() => { if (!email) return; const renderContent = async () => { setIsLoading(true); setError(null); try { if (!email.content || email.content.length === 0) { setContent(
Email content is empty
); return; } // Use the sanitizer from the centralized formatter const sanitizedHtml = sanitizeHtml(email.content); setContent(
); } catch (err) { console.error('Error rendering email content:', err); setError('Error rendering email content. Please try again.'); setContent(null); } finally { setIsLoading(false); } }; renderContent(); }, [email]); // Render attachments if they exist const renderAttachments = () => { if (!email?.attachments || email.attachments.length === 0) { return null; } return (

Attachments ({email.attachments.length})

{email.attachments.map((attachment, index) => ( ))}
); }; if (isLoading) { return (
); } if (error) { return ( Error {error} ); } return (
{content} {renderAttachments()}
); }