45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
|
|
'use client';
|
||
|
|
|
||
|
|
import { useQuery } from '@tanstack/react-query';
|
||
|
|
|
||
|
|
import { apiFetch } from '@/lib/api/client';
|
||
|
|
|
||
|
|
export interface OnboardingStatusStep {
|
||
|
|
id: string;
|
||
|
|
href: string;
|
||
|
|
label: string;
|
||
|
|
description: string;
|
||
|
|
done: boolean;
|
||
|
|
auto: boolean;
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface OnboardingStatusPayload {
|
||
|
|
steps: OnboardingStatusStep[];
|
||
|
|
completed: number;
|
||
|
|
total: number;
|
||
|
|
percent: number;
|
||
|
|
isComplete: boolean;
|
||
|
|
nextStep: { id: string; label: string; href: string } | null;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Shared onboarding-status query. Drives the topbar banner, dashboard tile,
|
||
|
|
* and the admin checklist summary. Cached for 60s so all three surfaces
|
||
|
|
* share a single fetch on first paint.
|
||
|
|
*
|
||
|
|
* Pass `enabled=false` to skip the network call (e.g. when the current
|
||
|
|
* user isn't a super_admin and the surface won't render anyway).
|
||
|
|
*/
|
||
|
|
export function useOnboardingStatus(opts: { enabled?: boolean } = {}) {
|
||
|
|
return useQuery<OnboardingStatusPayload>({
|
||
|
|
queryKey: ['admin', 'onboarding-status'],
|
||
|
|
queryFn: () =>
|
||
|
|
apiFetch<{ data: OnboardingStatusPayload }>('/api/v1/admin/onboarding/status').then(
|
||
|
|
(r) => r.data,
|
||
|
|
),
|
||
|
|
staleTime: 60_000,
|
||
|
|
enabled: opts.enabled ?? true,
|
||
|
|
retry: false,
|
||
|
|
});
|
||
|
|
}
|