// 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 (
{/* ── En-tête ── */}
Klyvio — Espace administrateur

Dashboard audits

{/* ── 4 métriques business ── */}
{[ { label: "Audits réalisés", value: audits.length || "—", sub: `${thisMonth} ce mois-ci`, icon: "file", color: "var(--white)" }, { label: "Agents recommandés", value: totalAgents || "—", sub: "sur tous les audits", icon: "sparkles", color: "var(--accent)" }, { label: "CA potentiel", value: fmtEurK(totalCA), sub: "investissement an 1 cumulé", icon: "euro", color: "#10B981" }, { label: "Gain cumulé clients",value: fmtEurK(totalGain), sub: "gain annuel estimé total", icon: "trending", color: "#F59E0B" }, ].map(({ label, value, sub, icon, color }) => (
{label}
{value}
{sub}
))}
{/* ── Score moyen ── */}
{[ { label: "Score moyen maturité IA", value: audits.length ? `${avg} / 100` : "—", icon: "target" }, { label: "Ce mois-ci", value: thisMonth || "—", icon: "calendar" }, ].map(({ label, value, icon }) => (
{label}
{value}
))}
{/* ── Liste audits ── */}

Tous les audits {search && ({filtered.length} résultat{filtered.length > 1 ? "s" : ""})}

setSearch(e.target.value)} style={{ width: 260, background: "rgba(255,255,255,0.04)", fontSize: 13 }} />
{audits.length === 0 && (

Aucun audit complété pour le moment.

Les audits apparaîtront ici dès qu'un client aura terminé le questionnaire.

)} {audits.length > 0 && filtered.length === 0 && (
Aucun résultat pour "{search}".
)} {filtered.length > 0 && ( {["Entreprise", "Contact", "Date", "Score", "Niveau", ""].map(h => ( ))} {filtered.map((audit, i) => { const info = scoreInfo(audit.score || 0); return ( e.currentTarget.style.background = "rgba(255,255,255,0.025)"} onMouseLeave={e => e.currentTarget.style.background = "transparent"} > ); })}
{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}
)}
); } window.AdminDashboard = AdminDashboard;