// Email Profile Card Component const { useState, useEffect } = React; const EmailProfileCard = ({ profile, onRefresh, onRemove, onViewEmails }) => { const [emails, setEmails] = useState([]); const [loadingEmails, setLoadingEmails] = useState(true); const { isCrifSender, formatLastCheck } = ApiUtils; useEffect(() => { if (!profile?.id) return; setLoadingEmails(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(() => setLoadingEmails(false)); }, [profile?.id, profile?.total_count]); const isFromJob = profile.source === 'job'; const flowType = profile.crif_mode ? 'Email + CRIF' : 'Email'; const isBlocked = profile.is_blocked; return ( onViewEmails(profile)}> {/* Header */}
{isBlocked ? '🚫' : '📧'}
{profile.person_name &&
{profile.person_name}
}
{profile.email_address}
{profile.provider} {isFromJob && Auto} {isBlocked && Bloccato}
0 ? 'bg-blue-100 text-blue-700' : 'bg-slate-100 text-slate-600'}`}> {loadingEmails ? '...' : emails.length} email
{/* Error / Blocked status */} {isBlocked && (
🚫 Account Bloccato
Errore di autenticazione. {profile.error && `Dettaglio: ${profile.error}`}
)} {profile.error && !isBlocked &&
⚠️ {profile.error}
} {/* Email previews */} {loadingEmails ? (
Caricamento...
) : emails.length > 0 ? (
{emails.slice(0, 3).map((email, idx) => { const isCrif = isCrifSender(email); return (
{isCrif && CRIF} {email.sender_name || email.sender?.split('@')[0]}
{email.subject || '(Nessun oggetto)'}
); })} {emails.length > 3 &&
+{emails.length - 3} altre
}
) : !profile.error && (
📭 Nessuna email
)} {/* Footer */}
e.stopPropagation()}> Ultimo: {formatLastCheck(profile.last_check)}
); }; window.EmailProfileCard = EmailProfileCard;