diff --git a/apps/hq-web/src/pages/Clients.tsx b/apps/hq-web/src/pages/Clients.tsx index 5c04ecc..3d0ad14 100644 --- a/apps/hq-web/src/pages/Clients.tsx +++ b/apps/hq-web/src/pages/Clients.tsx @@ -1,7 +1,7 @@ import { useEffect, useState } from 'react' import { useNavigate, useSearchParams } from 'react-router-dom' -import { Badge, Button, DataTable, EmptyState, Field, Notice, PageHeader, Toolbar } from '@sims/ui' -import { createClient, getClients, type ClientStatus, type DocStatus } from '../api' +import { Badge, Button, DataTable, EmptyState, ErrorState, Field, FilterChips, Notice, PageHeader, Skeleton, Toolbar } from '@sims/ui' +import { createClient, getClients, CLIENT_STATUSES, type ClientStatus, type DocStatus } from '../api' /** Tiny fetch-render hook shared by the HQ pages (same shape as backoffice live.tsx). */ export function useData(loader: () => Promise, deps: unknown[] = []): { @@ -36,6 +36,10 @@ export function Clients() { const { data, error, reload } = useData(() => getClients(q), [q]) const [sp] = useSearchParams() const [creating, setCreating] = useState(sp.get('new') === '1') + const [statusFilter, setStatusFilter] = useState('all') + const counts = new Map() + for (const c of data ?? []) counts.set(c.status, (counts.get(c.status) ?? 0) + 1) + const shown = (data ?? []).filter((c) => statusFilter === 'all' || c.status === statusFilter) return (
@@ -49,22 +53,31 @@ export function Clients() { className="wf" style={{ maxWidth: 280 }} placeholder="Search name / code / GSTIN…" value={q} onChange={(e) => setQ(e.target.value)} /> - {data?.length ?? '…'} clients + ({ key: s, label: s, count: counts.get(s) ?? 0 })), + ]} + /> + + {shown.length} shown {creating && ( { setCreating(false); reload(); nav(`/clients/${id}`) }} /> )} - {error !== undefined && {error}} - {data === undefined ? Loading… - : data.length === 0 ? No clients{q !== '' ? ` matching “${q}”` : ' yet — add the first one'}. : ( + {error !== undefined && } + {data === undefined && error === undefined ? + : shown.length === 0 ? No clients{q !== '' ? ` matching “${q}”` : statusFilter !== 'all' ? ` with status ${statusFilter}` : ' yet — add the first one'}. : ( nav(`/clients/${data[i]!.id}`)} - rows={data.map((c) => ({ + onRowClick={(_row, i) => nav(`/clients/${shown[i]!.id}`)} + rows={shown.map((c) => ({ code: c.code, name: c.name, status: {c.status}, state: c.stateCode,