Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | /**
* useTabBadges (Epic 14, Story 14.A.3)
*
* Composes EXISTING client data sources — event sessions + metrics, the event
* task list (`useEventTasks`), and the publishing-status endpoint (same query
* key as `usePublishing`, so the cache is shared) — into the count-driven tab
* attention badges. Frontend only, no backend change (NFR9).
*/
import { useMemo } from 'react';
import { useQuery } from '@tanstack/react-query';
import { publishingService } from '@/services/publishingService/publishingService';
import type { Event, EventDetailUI } from '@/types/event.types';
import { useEventTasks } from '@/hooks/useEventTasks';
import { computeTabBadges, type TabBadges } from './tabBadges';
export function useTabBadges(
event: (Event | EventDetailUI) | undefined,
eventCode: string | undefined
): TabBadges {
const { data: tasks } = useEventTasks(eventCode);
// Reuse usePublishing's exact query key so the status fetch is shared (no
// duplicate request when the Publishing tab is also mounted).
const { data: publishingStatus } = useQuery({
queryKey: ['publishing', 'status', eventCode],
queryFn: () => publishingService.getPublishingStatus(eventCode!),
enabled: !!eventCode,
staleTime: 10000,
});
const sessions = (event as { sessions?: { startTime?: string | null }[] } | undefined)?.sessions;
const pendingMaterialsCount = (event as { pendingMaterialsCount?: number } | undefined)
?.pendingMaterialsCount;
// Active registration total for the muted Registrations count (FR24).
const confirmedCount = (event as { confirmedCount?: number } | undefined)?.confirmedCount ?? 0;
const waitlistCount = (event as { waitlistCount?: number } | undefined)?.waitlistCount ?? 0;
const registrationsCount = confirmedCount + waitlistCount;
return useMemo(
() =>
computeTabBadges({
sessions,
pendingMaterialsCount,
tasks,
publishingStatus,
registrationsCount,
now: Date.now(),
}),
[sessions, pendingMaterialsCount, tasks, publishingStatus, registrationsCount]
);
}
|