// R-P7 (P7 Lead-Inbox) Interim-UI (AD-28) — lead statistics (D-P7 // "Lead-Statistiken", archetype A2 + KPI-Kit), composed from ~/ui. Pure: renders // LeadStatisticsVM (KPI tiles + by-source/by-status breakdowns) inside the shared // PageShell/PageHeader/PageBody chrome, the same page frame the dashboard uses. // Shares are derived from the counts the VM already carries — no invented // aggregates. The brief's richer breakdowns (reaction time, per-owner, weekday, // trend charts) are not yet exposed by the service and stay a tracked // design-nachzug. No useLoaderData. Final Subframe optics = tracked design-nachzug. import { useTranslation } from "react-i18next"; import { FeatherBarChart2, FeatherCheckCircle, FeatherInbox, FeatherShieldOff, FeatherTrendingUp } from "@subframe/core"; import type { LeadStatBreakdownRow, LeadStatKpi, LeadStatisticsVM } from "@hivegrid/view-models"; import { PAGE_HEADER_ICON_CLASS, PageBody, PageHeader, PageShell } from "../shared/PageShell"; import { Alert } from "~/ui/components/Alert"; import { Card } from "~/ui/components/Card"; import { EmptyState } from "~/ui/components/EmptyState"; import { Loader } from "~/ui/components/Loader"; import { Progress } from "~/ui/components/Progress"; import { StatsCard } from "~/ui/components/StatsCard"; import { useLocaleFormatters } from "~/locale/format"; export type LeadStatisticsActions = { /** Open the inbox filtered to what the tile counts. */ onOpenLeads: (kpi: LeadStatKpi) => void; }; export type LeadStatisticsPageProps = { vm: LeadStatisticsVM; actions: LeadStatisticsActions; }; const sectionHeading = "text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary"; const mutedText = "text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary"; const kpiIcons: Record = { total: , new: , converted: , spam: , }; export function LeadStatisticsPage(props: LeadStatisticsPageProps) { const { t } = useTranslation(); const formatters = useLocaleFormatters(); const header = ( } title={t("leads.statistics.title")} subtitle={t("leads.statistics.subtitle")} /> ); if (props.vm.status === "loading" || props.vm.status === "idle") { return ( {header} {t("leads.statistics.loading")} ); } if (props.vm.status === "error") { return ( {header} ); } const data = props.vm.status === "ready" ? props.vm.data : null; const total = data?.kpis.find((kpi) => kpi.key === "total")?.value ?? 0; if (!data || total === 0) { return ( {header} ); } /** Share of all leads — the only derivation, straight from the VM counts. */ const share = (count: number) => (total > 0 ? count / total : 0); return ( {header}
{data.kpis.map((kpi) => ( // Each tile is a shortcut into the inbox, filtered to exactly what it // counts — a button, so it is reachable by keyboard like any control. ))}
{data.canReadAll ? null : ( {t("leads.statistics.scopeOwnOnly")} )}
); } function BreakdownCard({ uiId, heading, description, rows, total, }: { uiId: string; heading: string; description: string; rows: readonly LeadStatBreakdownRow[]; total: number; }) { const { t } = useTranslation(); const formatters = useLocaleFormatters(); return (
{heading} {description}
{rows.length === 0 ? ( {t("leads.statistics.breakdown.empty")} ) : (
{rows.map((row) => ( 0 ? Math.round((row.count / total) * 100) : 0} label={t(row.labelKey)} statusText={t("leads.statistics.breakdown.count", { value: formatters.number(row.count), percent: formatters.percent(total > 0 ? row.count / total : 0, { maximumFractionDigits: 0 }), })} data-ui-id={`${uiId}.row.${row.key}`} /> ))}
)}
); } export default LeadStatisticsPage;