Files
crewli/apps/app/src/composables/api/useEvents.ts
bert.hausmans c417a6647a feat(app): auth, orgs/events UI, router guards, and dev tooling
- Add Sanctum auth flow (store, composables, login, axios interceptors)
- Add dashboard, organisation list/detail, events CRUD dialogs
- Wire router guards, navigation, organisation switcher in layout
- Replace Vuexy @db types in NavSearchBar; add @iconify/types; themeConfig title typing
- Vuetify settings.scss + resolve configFile via fileURLToPath; drop dead path aliases
- Root index redirects to dashboard; fix events table route name
- API: DevSeeder + DatabaseSeeder updates; docs TEST_SCENARIO; corporate identity assets

Made-with: Cursor
2026-04-07 21:51:10 +02:00

87 lines
2.2 KiB
TypeScript

import { useMutation, useQuery, useQueryClient } from '@tanstack/vue-query'
import type { Ref } from 'vue'
import { apiClient } from '@/lib/axios'
import type {
CreateEventPayload,
EventType,
UpdateEventPayload,
} from '@/types/event'
interface ApiResponse<T> {
success: boolean
data: T
message?: string
}
interface PaginatedResponse<T> {
data: T[]
links: Record<string, string | null>
meta: {
current_page: number
per_page: number
total: number
last_page: number
}
}
export function useEventList(orgId: Ref<string>) {
return useQuery({
queryKey: ['events', orgId],
queryFn: async () => {
const { data } = await apiClient.get<PaginatedResponse<EventType>>(
`/organisations/${orgId.value}/events`,
)
return data.data
},
enabled: () => !!orgId.value,
})
}
export function useEventDetail(orgId: Ref<string>, id: Ref<string>) {
return useQuery({
queryKey: ['events', orgId, id],
queryFn: async () => {
const { data } = await apiClient.get<ApiResponse<EventType>>(
`/organisations/${orgId.value}/events/${id.value}`,
)
return data.data
},
enabled: () => !!orgId.value && !!id.value,
})
}
export function useCreateEvent(orgId: Ref<string>) {
const queryClient = useQueryClient()
return useMutation({
mutationFn: async (payload: CreateEventPayload) => {
const { data } = await apiClient.post<ApiResponse<EventType>>(
`/organisations/${orgId.value}/events`,
payload,
)
return data.data
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['events', orgId.value] })
},
})
}
export function useUpdateEvent(orgId: Ref<string>, id: Ref<string>) {
const queryClient = useQueryClient()
return useMutation({
mutationFn: async (payload: UpdateEventPayload) => {
const { data } = await apiClient.put<ApiResponse<EventType>>(
`/organisations/${orgId.value}/events/${id.value}`,
payload,
)
return data.data
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['events', orgId.value] })
queryClient.invalidateQueries({ queryKey: ['events', orgId.value, id.value] })
},
})
}