feat: schema v1.7 + sections/shifts frontend
- Universeel festival/event model (parent_event_id, event_type) - event_person_activations pivot tabel - Event model: parent/children relaties + helper scopes - DevSeeder: festival structuur met sub-events - Sections & Shifts frontend (twee-kolom layout) - BACKLOG.md aangemaakt met 22 gedocumenteerde wensen
This commit is contained in:
77
apps/app/src/composables/api/useTimeSlots.ts
Normal file
77
apps/app/src/composables/api/useTimeSlots.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
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/section'
|
||||
|
||||
interface ApiResponse<T> {
|
||||
success: boolean
|
||||
data: T
|
||||
message?: string
|
||||
}
|
||||
|
||||
interface PaginatedResponse<T> {
|
||||
data: T[]
|
||||
}
|
||||
|
||||
export function useTimeSlotList(eventId: Ref<string>) {
|
||||
return useQuery({
|
||||
queryKey: ['time-slots', eventId],
|
||||
queryFn: async () => {
|
||||
const { data } = await apiClient.get<PaginatedResponse<TimeSlot>>(
|
||||
`/events/${eventId.value}/time-slots`,
|
||||
)
|
||||
|
||||
return data.data
|
||||
},
|
||||
enabled: () => !!eventId.value,
|
||||
})
|
||||
}
|
||||
|
||||
export function useCreateTimeSlot(eventId: Ref<string>) {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (payload: CreateTimeSlotPayload) => {
|
||||
const { data } = await apiClient.post<ApiResponse<TimeSlot>>(
|
||||
`/events/${eventId.value}/time-slots`,
|
||||
payload,
|
||||
)
|
||||
|
||||
return data.data
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['time-slots', eventId.value] })
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function useUpdateTimeSlot(eventId: Ref<string>) {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async ({ id, ...payload }: UpdateTimeSlotPayload & { id: string }) => {
|
||||
const { data } = await apiClient.put<ApiResponse<TimeSlot>>(
|
||||
`/events/${eventId.value}/time-slots/${id}`,
|
||||
payload,
|
||||
)
|
||||
|
||||
return data.data
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['time-slots', eventId.value] })
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function useDeleteTimeSlot(eventId: Ref<string>) {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (id: string) => {
|
||||
await apiClient.delete(`/events/${eventId.value}/time-slots/${id}`)
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['time-slots', eventId.value] })
|
||||
},
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user