Files
pn-new-crm/src/components/dashboard/kpi-cards.tsx
Matt Ciaccio 3a7fef59b0 fix(visual): dark-mode-safe borders + sidebar relative + ring-background
Code-review follow-up to PR10b-e:
- DetailHeaderStrip + KPITile: border-slate-200 → border-border so dark
  mode doesn't paint a bright halo around the gradient strip.
- Topbar avatar: ring-white → ring-background so the 2px ring tracks
  the surface (matches the sidebar footer pattern).
- KpiTileSkeleton stripe: bg-slate-100 → bg-muted for parity with
  shadcn skeleton tokens in dark mode.
- Sidebar <aside>: add `relative` so the absolute-positioned
  collapse-toggle button anchors to the sidebar itself rather than
  the nearest positioned ancestor.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 12:24:14 +02:00

102 lines
2.4 KiB
TypeScript

'use client';
import { useQuery } from '@tanstack/react-query';
import { apiFetch } from '@/lib/api/client';
import { KPITile } from '@/components/ui/kpi-tile';
import { Skeleton } from '@/components/ui/skeleton';
import { WidgetErrorBoundary } from './widget-error-boundary';
interface KpiData {
totalClients: number;
activeInterests: number;
pipelineValueUsd: number;
occupancyRate: number;
}
function formatCurrency(value: number): string {
return new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
maximumFractionDigits: 0,
}).format(value);
}
function formatPercent(value: number): string {
return `${value.toFixed(1)}%`;
}
function KpiTileSkeleton() {
return (
<div className="relative overflow-hidden rounded-xl border border-border bg-card p-5 shadow-sm">
<div className="absolute inset-x-0 top-0 h-1 bg-muted" aria-hidden />
<Skeleton className="h-3 w-24" />
<Skeleton className="mt-3 h-7 w-32" />
<Skeleton className="mt-2 h-3 w-12" />
</div>
);
}
export function KpiCards() {
const { data, isLoading, isError } = useQuery<KpiData>({
queryKey: ['dashboard', 'kpis'],
queryFn: () => apiFetch<KpiData>('/api/v1/dashboard/kpis'),
staleTime: 60_000,
retry: 2,
});
if (isLoading) {
return (
<>
<KpiTileSkeleton />
<KpiTileSkeleton />
<KpiTileSkeleton />
<KpiTileSkeleton />
</>
);
}
const kpis: Array<{
label: string;
value: string;
accent: 'brand' | 'success' | 'warning' | 'mint' | 'teal' | 'purple';
}> = [
{
label: 'Total Clients',
value: isError ? '—' : String(data?.totalClients ?? 0),
accent: 'brand',
},
{
label: 'Active Interests',
value: isError ? '—' : String(data?.activeInterests ?? 0),
accent: 'teal',
},
{
label: 'Pipeline Value',
value: isError ? '—' : formatCurrency(data?.pipelineValueUsd ?? 0),
accent: 'success',
},
{
label: 'Occupancy Rate',
value: isError ? '—' : formatPercent(data?.occupancyRate ?? 0),
accent: 'purple',
},
];
return (
<>
{kpis.map(({ label, value, accent }) => (
<KPITile key={label} title={label} value={value} accent={accent} />
))}
</>
);
}
export function KpiCardsWithBoundary() {
return (
<WidgetErrorBoundary>
<KpiCards />
</WidgetErrorBoundary>
);
}