const { useState, useEffect } = React; function Dashboard() { const [dashboard, setDashboard] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { fetch('/api/dashboard') .then(res => res.json()) .then(data => { setDashboard(data); setLoading(false); }) .catch(err => { setError(err.message); setLoading(false); }); }, []); if (loading) return
Loading dashboard...
; if (error) return
Error: {error}
; if (!dashboard) return null; return (

Dashboard

{/* Key Metrics */}
{Object.entries(dashboard.by_tier).map(([tier, count]) => (
{count}
{tier}
))}
{/* Due for Contact */}
Due for Contact
{dashboard.due_contacts.length === 0 ? (

No contacts due today

) : (
{dashboard.due_contacts.map(contact => (
{contact.full_name}
{contact.organisation} • {contact.next_due_date ? new Date(contact.next_due_date).toLocaleDateString() : 'No date'}
{contact.tier}
))}
)}
{/* Cooling Relationships */} {dashboard.cooling_relationships.length > 0 && (
Cooling Relationships ⚠️
{dashboard.cooling_relationships.map(contact => (
{contact.full_name}
Last contacted: {contact.last_contacted ? new Date(contact.last_contacted).toLocaleDateString() : 'Never'}
{contact.tier}
))}
)} {/* Pending Email Approvals (Principal only) */} {dashboard.pending_approvals.length > 0 && (
Pending Email Approvals
{dashboard.pending_approvals.map(approval => (
{approval.subject}
From: {approval.created_by}
))}
)}
); }