All files / src/hooks useEventTasks.ts

0% Statements 0/7
0% Branches 0/3
0% Functions 0/4
0% Lines 0/7

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                                                                                 
/**
 * Event task React Query hooks (Epic 14, Story 14.A.3)
 *
 * Thin React Query wrappers over the EXISTING `taskService` — frontend only,
 * no backend change (AR8/NFR9). They back the Cockpit "Needs your attention"
 * list (Phase B) and the count-driven tab attention badges (Phase A).
 */
 
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
import { taskService, type EventTaskResponse } from '@/services/taskService';
 
/**
 * Fetch all tasks for a single event (`GET /events/{code}/tasks`).
 * Cache: 3 minutes (tasks are moderately volatile).
 */
export const useEventTasks = (
  eventCode: string | undefined
): UseQueryResult<EventTaskResponse[], Error> => {
  return useQuery({
    queryKey: ['eventTasks', eventCode],
    queryFn: () => taskService.listEventTasks(eventCode!),
    enabled: !!eventCode,
    staleTime: 3 * 60 * 1000,
  });
};
 
/**
 * Fetch the current organizer's tasks (`GET /tasks/my-tasks?critical=`).
 * Cache: 3 minutes.
 */
export const useMyTasks = (
  options: { critical?: boolean } = {}
): UseQueryResult<EventTaskResponse[], Error> => {
  const critical = options.critical ?? false;
  return useQuery({
    queryKey: ['myTasks', { critical }],
    queryFn: () => taskService.getMyTasks(critical),
    staleTime: 3 * 60 * 1000,
  });
};