Files
crewli/apps/app/src/composables/api/useTimeSlots.ts
bert.hausmans 7bc0f1a0c7 feat: fix time slot hierarchy — seeder, API include_children, frontend dropdown, navigation
Restructure the festival hierarchy end-to-end:

Seeder: Remove duplicate festival-level VOLUNTEER time slots, keep only CREW
operational slots. Rename sub-events to "Dag 1/2/3 — ..." pattern. Change
Nachtsecurity to Security (cross_event). EHBO/Security shifts now use sub-event
time slots via cross_event exception. Add flat event "Braderie Dorpstown 2026".

API: Add ?include_children=true to TimeSlotController for festivals, returning
all sub-event time slots with source and event_name fields. Update
StoreShiftRequest and UpdateShiftRequest to accept child time slots for
cross_event sections.

Frontend: Create useTimeSlotDropdown composable with 4-scenario dropdown logic.
Replace AppSelect with VAutocomplete in CreateShiftDialog with grouped items,
dimmed festival slots, and info tooltips. Add InfoTooltip reusable component.
Show festival context labels on cross_event sections in sub-event section lists.
Add read-only festival time slots on sub-event time-slots page. Add cross_event
context banner with "Bekijk alle diensten" link.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 22:07:37 +02:00

86 lines
2.6 KiB
TypeScript

import { useMutation, useQuery, useQueryClient } from '@tanstack/vue-query'
import type { Ref } from 'vue'
import { apiClient } from '@/lib/axios'
import type { CreateTimeSlotPayload, TimeSlot, UpdateTimeSlotPayload } from '@/types/timeSlot'
interface ApiResponse<T> {
success: boolean
data: T
message?: string
}
interface PaginatedResponse<T> {
data: T[]
}
export function useTimeSlotList(orgId: Ref<string>, eventId: Ref<string>, options?: { includeParent?: Ref<boolean>; includeChildren?: Ref<boolean> }) {
const includeParent = options?.includeParent
const includeChildren = options?.includeChildren
return useQuery({
queryKey: ['time-slots', eventId, includeParent, includeChildren],
queryFn: async () => {
const params: Record<string, string> = {}
if (includeParent?.value) params.include_parent = 'true'
if (includeChildren?.value) params.include_children = 'true'
const { data } = await apiClient.get<PaginatedResponse<TimeSlot>>(
`/organisations/${orgId.value}/events/${eventId.value}/time-slots`,
{ params },
)
return data.data
},
enabled: () => !!orgId.value && !!eventId.value,
})
}
export function useCreateTimeSlot(orgId: Ref<string>, eventId: Ref<string>) {
const queryClient = useQueryClient()
return useMutation({
mutationFn: async (payload: CreateTimeSlotPayload) => {
const { data } = await apiClient.post<ApiResponse<TimeSlot>>(
`/organisations/${orgId.value}/events/${eventId.value}/time-slots`,
payload,
)
return data.data
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['time-slots', eventId.value] })
},
})
}
export function useUpdateTimeSlot(orgId: Ref<string>, eventId: Ref<string>) {
const queryClient = useQueryClient()
return useMutation({
mutationFn: async ({ id, ...payload }: UpdateTimeSlotPayload & { id: string }) => {
const { data } = await apiClient.put<ApiResponse<TimeSlot>>(
`/organisations/${orgId.value}/events/${eventId.value}/time-slots/${id}`,
payload,
)
return data.data
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['time-slots', eventId.value] })
},
})
}
export function useDeleteTimeSlot(orgId: Ref<string>, eventId: Ref<string>) {
const queryClient = useQueryClient()
return useMutation({
mutationFn: async (id: string) => {
await apiClient.delete(`/organisations/${orgId.value}/events/${eventId.value}/time-slots/${id}`)
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['time-slots', eventId.value] })
},
})
}