2026-05-12 14:50:58 +02:00
|
|
|
'use client';
|
|
|
|
|
|
|
|
|
|
import { useQuery } from '@tanstack/react-query';
|
|
|
|
|
|
|
|
|
|
import { apiFetch } from '@/lib/api/client';
|
|
|
|
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
|
|
|
|
import { Skeleton } from '@/components/ui/skeleton';
|
2026-05-13 11:50:07 +02:00
|
|
|
import { formatEnum } from '@/lib/constants';
|
2026-05-12 14:50:58 +02:00
|
|
|
|
|
|
|
|
interface SourceRow {
|
|
|
|
|
source: string;
|
|
|
|
|
total: number;
|
|
|
|
|
won: number;
|
|
|
|
|
lost: number;
|
|
|
|
|
conversionRate: number;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface SourceConversionResponse {
|
|
|
|
|
data: SourceRow[];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Horizontal bar list of lead-source conversion rates. Complements the
|
|
|
|
|
* existing Lead Source Attribution donut: that one shows where leads
|
|
|
|
|
* COME from, this shows which sources actually CONVERT. Lets marketing
|
|
|
|
|
* spend follow the buyers, not the tire-kickers.
|
|
|
|
|
*
|
|
|
|
|
* Renders only sources with at least one lead; uses a compact bar-in-
|
|
|
|
|
* row layout so 5-8 sources fit comfortably without scrolling.
|
|
|
|
|
*/
|
|
|
|
|
export function SourceConversionChart() {
|
|
|
|
|
const { data, isLoading } = useQuery<SourceConversionResponse>({
|
|
|
|
|
queryKey: ['dashboard', 'source_conversion'],
|
|
|
|
|
queryFn: () => apiFetch<SourceConversionResponse>('/api/v1/dashboard/source-conversion'),
|
|
|
|
|
staleTime: 60_000,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const rows = data?.data ?? [];
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Card>
|
|
|
|
|
<CardHeader>
|
|
|
|
|
<CardTitle className="text-base">Source conversion</CardTitle>
|
|
|
|
|
<CardDescription>Won deals as a percentage of leads per source.</CardDescription>
|
|
|
|
|
</CardHeader>
|
|
|
|
|
<CardContent>
|
|
|
|
|
{isLoading ? (
|
|
|
|
|
<div className="space-y-3">
|
fix(audit-wave-10): aria-hidden sweep on decorative Lucide icons (#69)
Mechanical codemod added \`aria-hidden\` to 444 self-closing single-line
Lucide icon JSX elements across 267 .tsx files in:
- shared/, layout/, dashboard/
- admin/ (all sections)
- clients/, berths/, yachts/, companies/, interests/, documents/
- reminders/, reservations/, residential/, expenses/, email/
The regex targeted only the safe pattern \`<IconName className="..." />\`
(no other props, self-closing, capitalized component name). Every match
inspected is a decorative companion to visible text or sits inside a
button whose accessible name comes from \`aria-label\` / sr-only text
— the icon itself should not be announced.
Screen readers no longer double-read the icon + the adjacent label
text (e.g. "Pencil Pencil Edit" → just "Edit"). The existing
@axe-core/playwright smoke test (\`20-accessibility.spec.ts\`) continues
to pass.
Test suite stays at 1315/1315 vitest. typescript clean.
Closes task #69 (aria-hidden sweep) from the AUDIT-2026-05-12 follow-ups
backlog.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-13 12:37:22 +02:00
|
|
|
<Skeleton className="h-8 w-full" aria-hidden />
|
|
|
|
|
<Skeleton className="h-8 w-full" aria-hidden />
|
|
|
|
|
<Skeleton className="h-8 w-full" aria-hidden />
|
2026-05-12 14:50:58 +02:00
|
|
|
</div>
|
|
|
|
|
) : rows.length === 0 ? (
|
|
|
|
|
<p className="py-4 text-center text-sm text-muted-foreground">
|
|
|
|
|
Once interests have a source assigned, conversion rates will appear here.
|
|
|
|
|
</p>
|
|
|
|
|
) : (
|
|
|
|
|
<ul className="space-y-3">
|
|
|
|
|
{rows.map((r) => {
|
|
|
|
|
const pct = Math.round(r.conversionRate * 100);
|
2026-05-13 11:50:07 +02:00
|
|
|
const label = formatEnum(r.source);
|
2026-05-12 14:50:58 +02:00
|
|
|
return (
|
|
|
|
|
<li key={r.source} className="space-y-1">
|
|
|
|
|
<div className="flex items-center justify-between text-xs">
|
|
|
|
|
<span className="font-medium text-foreground">{label}</span>
|
|
|
|
|
<span className="tabular-nums text-muted-foreground">
|
|
|
|
|
<span className="font-semibold text-foreground">{pct}%</span>
|
|
|
|
|
<span className="ml-1.5">
|
|
|
|
|
({r.won} won · {r.total} total)
|
|
|
|
|
</span>
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
{/* Inline bar — keeps the widget compact and lets eight
|
|
|
|
|
rows share the same vertical space a Recharts plot
|
|
|
|
|
would use for two. */}
|
|
|
|
|
<div className="h-2 w-full overflow-hidden rounded-full bg-muted">
|
|
|
|
|
<div
|
|
|
|
|
className="h-full rounded-full bg-primary transition-all"
|
|
|
|
|
style={{ width: `${Math.max(pct, 2)}%` }}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</li>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</ul>
|
|
|
|
|
)}
|
|
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
);
|
|
|
|
|
}
|