// Email List Modal Component
const { useState, useEffect } = React;
const EmailListModal = ({ profile, onClose }) => {
const [emails, setEmails] = useState([]);
const [loading, setLoading] = useState(true);
useEffect(() => {
if (!profile) return;
setLoading(true);
fetch(`/profiles/${profile.id}/emails?unread_only=false`)
.then(r => r.json())
.then(data => {
if (data.status === 'success') setEmails(data.emails || []);
})
.catch(console.error)
.finally(() => setLoading(false));
}, [profile]);
if (!profile) return null;
const { isCrifSender } = ApiUtils;
return (
e.stopPropagation()}>
📧 {profile.email_address}
{profile.person_name &&
{profile.person_name}
}
{loading ? (
) : emails.length === 0 ? (
) : (
{emails.map((email, idx) => {
const isCrif = isCrifSender(email);
return (
{isCrif && CRIF}
{email.sender_name || email.sender?.split('@')[0] || 'Sconosciuto'}
{(() => {
try {
const date = new Date(email.date);
return isNaN(date) ? '' : date.toLocaleDateString('it-IT', { day: '2-digit', month: 'short', hour: '2-digit', minute: '2-digit' });
} catch { return ''; }
})()}
{email.subject || '(Nessun oggetto)'}
{email.body_preview || ''}
{email.has_attachments &&
📎 Allegati
}
{email.is_spam &&
📁 {email.folder}}
);
})}
)}
);
};
window.EmailListModal = EmailListModal;