feat(dashboard): custom date range + KPI port-hydration gate

DateRangePicker grows a "Custom range" mode (From/To inputs capped
at today, mutually-bounded so From <= To). dashboard-shell threads
the range through to /api/v1/analytics, which validates calendar
dates via ISO round-trip and enforces a 365-day cap as a backstop
against the occupancy timeline N+1.

KpiCards now gates its query on currentPortId so the early
unhydrated-store fetch can't cache a zeroed/error response and
display "-" until staleTime expires.

MyRemindersRail drops xl:h-full so the rail no longer stretches
past its grid row and overlaps ActivityFeed below.

useRealtimeInvalidation switches to partial-prefix queryKeys so a
realtime mutation invalidates every cached range bucket at once
instead of just the one currently visible.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Matt Ciaccio
2026-05-04 22:54:55 +02:00
parent e598cc0708
commit 77ad10ced1
7 changed files with 260 additions and 30 deletions

View File

@@ -3,6 +3,7 @@
import { useQuery } from '@tanstack/react-query';
import { apiFetch } from '@/lib/api/client';
import { useUIStore } from '@/stores/ui-store';
import { KPITile } from '@/components/ui/kpi-tile';
import { Skeleton } from '@/components/ui/skeleton';
import { WidgetErrorBoundary } from './widget-error-boundary';
@@ -37,11 +38,19 @@ function KpiTileSkeleton() {
}
export function KpiCards() {
// Keying on currentPortId ensures React Query treats a port-resolved fetch
// as a different query than the one that fires on first paint when the
// store hasn't yet hydrated. Without this, an early null-port fetch could
// cache an error and display "-" indefinitely until the staleTime expires.
const portId = useUIStore((s) => s.currentPortId);
const { data, isLoading, isError } = useQuery<KpiData>({
queryKey: ['dashboard', 'kpis'],
queryKey: ['dashboard', 'kpis', portId],
queryFn: () => apiFetch<KpiData>('/api/v1/dashboard/kpis'),
staleTime: 60_000,
retry: 2,
// Avoid running until we have a port id - gates against the early
// unauth/no-port window where the API would return zeroes/errors.
enabled: !!portId,
});
if (isLoading) {
@@ -62,22 +71,22 @@ export function KpiCards() {
}> = [
{
label: 'Total Clients',
value: isError ? '' : String(data?.totalClients ?? 0),
value: isError ? '-' : String(data?.totalClients ?? 0),
accent: 'brand',
},
{
label: 'Active Interests',
value: isError ? '' : String(data?.activeInterests ?? 0),
value: isError ? '-' : String(data?.activeInterests ?? 0),
accent: 'teal',
},
{
label: 'Pipeline Value',
value: isError ? '' : formatCurrency(data?.pipelineValueUsd ?? 0),
value: isError ? '-' : formatCurrency(data?.pipelineValueUsd ?? 0),
accent: 'success',
},
{
label: 'Occupancy Rate',
value: isError ? '' : formatPercent(data?.occupancyRate ?? 0),
value: isError ? '-' : formatPercent(data?.occupancyRate ?? 0),
accent: 'purple',
},
];