Files
2026-07-13 12:58:18 +08:00

49 lines
1.2 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"use client";
import { computeKpis, formatCurrency } from "@/lib/crm";
import type { CrmState } from "@/lib/crm";
import { KpiCard } from "./KpiCard";
import { Skeleton } from "@/components/ui/skeleton";
export function KpiStrip({
crm,
loading,
}: {
crm: CrmState;
loading?: boolean;
}) {
if (loading) {
return (
<div className="grid grid-cols-2 gap-3 lg:grid-cols-4">
{Array.from({ length: 4 }).map((_, i) => (
<Skeleton key={i} className="h-[88px] w-full rounded-xl" />
))}
</div>
);
}
const k = computeKpis(crm);
return (
<div className="grid grid-cols-2 gap-3 lg:grid-cols-4">
<KpiCard
label="Open pipeline"
value={formatCurrency(k.openPipeline)}
sub="across open deals"
/>
<KpiCard
label="Weighted forecast"
value={formatCurrency(k.weightedForecast)}
sub="amount × probability"
/>
<KpiCard
label="Win rate"
value={k.winRate === null ? "—" : `${Math.round(k.winRate * 100)}%`}
sub="closed won / closed"
/>
<KpiCard
label="At-risk deals"
value={String(k.atRisk)}
sub="need attention"
/>
</div>
);
}