fix: harden pipeline navigation data loading
Some checks failed
Velocity-OS Deployment Pipeline / lint (push) Has been cancelled
Velocity-OS Deployment Pipeline / build-and-push (agents) (push) Has been cancelled
Velocity-OS Deployment Pipeline / build-and-push (core) (push) Has been cancelled
Velocity-OS Deployment Pipeline / build-and-push (media-engine) (push) Has been cancelled
Velocity-OS Deployment Pipeline / build-and-push (webos) (push) Has been cancelled
Velocity-OS Deployment Pipeline / sign-images (agents) (push) Has been cancelled
Velocity-OS Deployment Pipeline / sign-images (core) (push) Has been cancelled
Velocity-OS Deployment Pipeline / sign-images (media-engine) (push) Has been cancelled
Velocity-OS Deployment Pipeline / sign-images (webos) (push) Has been cancelled
Velocity-OS Deployment Pipeline / notify-ingress (push) Has been cancelled

This commit is contained in:
2026-05-02 13:05:26 +05:30
parent 08a19db035
commit 58628dac35
7 changed files with 169 additions and 57 deletions

View File

@@ -1,5 +1,6 @@
import { useQuery } from '@tanstack/react-query';
import { api } from '@/shared/lib/apiClient';
import { unwrapArray } from '@/shared/lib/apiShape';
/**
* useKanban — Pipeline Pillar kanban board data
@@ -8,11 +9,23 @@ import { api } from '@/shared/lib/apiClient';
export function useKanban() {
const query = useQuery({
queryKey: ['kanban'],
queryFn: () => api.get<KanbanStage[]>('/crm/pipeline/kanban'),
queryFn: async () => {
const payload = await api.get<unknown>('/crm/pipeline/kanban?limit=250&offset=0');
return unwrapArray<RawKanbanStage>(payload).map(normalizeStage);
},
staleTime: 30_000,
refetchInterval: 60_000,
refetchOnMount: 'always',
refetchOnWindowFocus: true,
retry: 1,
});
return { stages: query.data ?? [], isLoading: query.isLoading };
return {
stages: query.data ?? [],
isLoading: query.isLoading,
isError: query.isError,
error: query.error,
refetch: query.refetch,
};
}
export interface KanbanStage {
@@ -32,3 +45,36 @@ export interface KanbanLead {
lastContactChannel: string;
isVaultActive?: boolean;
}
interface RawKanbanStage {
id?: string;
stage?: string;
status?: string;
label?: string;
emoji?: string;
leads?: unknown;
items?: unknown;
data?: unknown;
}
function normalizeStage(stage: RawKanbanStage): KanbanStage {
const id = String(stage.id ?? stage.stage ?? stage.status ?? 'new');
const leads = unwrapArray<KanbanLead>(stage.leads ?? stage.items ?? stage.data).map(normalizeLead);
return {
id,
label: String(stage.label ?? id.replace(/_/g, ' ').replace(/\b\w/g, (c) => c.toUpperCase())),
emoji: String(stage.emoji ?? id.slice(0, 1).toUpperCase()),
leads,
};
}
function normalizeLead(lead: Partial<KanbanLead>): KanbanLead {
return {
...lead,
id: String(lead.id),
name: String(lead.name ?? 'Unnamed Client'),
qdScore: Number.isFinite(Number(lead.qdScore)) ? Number(lead.qdScore) : 0,
lastContactRelative: String(lead.lastContactRelative ?? 'No contact yet'),
lastContactChannel: String(lead.lastContactChannel ?? 'crm'),
};
}