// Klyvio — AdminDashboard.jsx // Dashboard administrateur — lecture depuis klyvio_audits (localStorage) function AdminDashboard({ onLogout, onViewReport }) { const [audits, setAudits] = useState([]); const [search, setSearch] = useState(""); useEffect(() => { try { const all = JSON.parse(localStorage.getItem("klyvio_audits") || "[]"); setAudits(all.sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt))); } catch { setAudits([]); } }, []); const filtered = audits.filter(a => (a.company?.name || "").toLowerCase().includes(search.toLowerCase()) || (a.email || "").toLowerCase().includes(search.toLowerCase()) || (a.name || "").toLowerCase().includes(search.toLowerCase()) || (a.company?.sectorLabel || "").toLowerCase().includes(search.toLowerCase()) ); const avg = audits.length ? Math.round(audits.reduce((s, a) => s + (a.score || 0), 0) / audits.length) : 0; const thisMonth = audits.filter(a => { try { const d = new Date(a.createdAt); const now = new Date(); return d.getMonth() === now.getMonth() && d.getFullYear() === now.getFullYear(); } catch { return false; } }).length; // Métriques business const totalAgents = audits.reduce((s, a) => s + (a.offer?.agents || a.roi?.agents || 0), 0); const totalCA = audits.reduce((s, a) => s + (a.roi?.totalInvest || 0), 0); const totalGain = audits.reduce((s, a) => s + (a.roi?.totalGain || 0), 0); function fmtEurK(v) { if (!v) return "—"; if (v >= 1000000) return `${(v / 1000000).toFixed(1).replace(".", ",")} M€`; if (v >= 1000) return `${Math.round(v / 1000)} k€`; return `${v} €`; } function scoreInfo(s) { if (s >= 70) return { label: "Avancé", color: "#10B981", bg: "rgba(16,185,129,0.12)", border: "rgba(16,185,129,0.3)" }; if (s >= 50) return { label: "En transition", color: "#F59E0B", bg: "rgba(245,158,11,0.12)", border: "rgba(245,158,11,0.3)" }; if (s >= 30) return { label: "Débutant", color: "var(--accent)", bg: "var(--accent-dim)", border: "rgba(0,174,239,0.3)" }; return { label: "Très débutant", color: "#EF4444", bg: "rgba(239,68,68,0.12)", border: "rgba(239,68,68,0.3)" }; } function fmtDate(iso) { try { return new Date(iso).toLocaleDateString("fr-FR", { day: "numeric", month: "short", year: "numeric" }); } catch { return "—"; } } return (
Aucun audit complété pour le moment.
Les audits apparaîtront ici dès qu'un client aura terminé le questionnaire.
| {h} | ))}|||||
|---|---|---|---|---|---|
|
{audit.company?.name || "—"}
{audit.company?.sectorLabel || ""}
{audit.company?.sizeLabel ? ` · ${audit.company.sizeLabel} sal.` : ""}
|
{audit.name || "—"}
{audit.email || ""}
|
{fmtDate(audit.createdAt)} | {audit.score || 0} /100 | {info.label} |