- 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
76 lines
2.0 KiB
TypeScript
76 lines
2.0 KiB
TypeScript
import { useMutation, useQuery, useQueryClient } from '@tanstack/vue-query'
|
|
import { computed, type Ref } from 'vue'
|
|
import { apiClient } from '@/lib/axios'
|
|
import { useAuthStore } from '@/stores/useAuthStore'
|
|
import type {
|
|
Organisation,
|
|
UpdateOrganisationPayload,
|
|
} from '@/types/organisation'
|
|
|
|
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 useOrganisationList() {
|
|
return useQuery({
|
|
queryKey: ['organisations'],
|
|
queryFn: async () => {
|
|
const { data } = await apiClient.get<PaginatedResponse<Organisation>>('/organisations')
|
|
return data.data
|
|
},
|
|
})
|
|
}
|
|
|
|
export function useOrganisationDetail(id: Ref<string>) {
|
|
return useQuery({
|
|
queryKey: ['organisations', id],
|
|
queryFn: async () => {
|
|
const { data } = await apiClient.get<ApiResponse<Organisation>>(`/organisations/${id.value}`)
|
|
return data.data
|
|
},
|
|
enabled: () => !!id.value,
|
|
})
|
|
}
|
|
|
|
export function useMyOrganisation() {
|
|
const authStore = useAuthStore()
|
|
const id = computed(() => authStore.currentOrganisation?.id ?? '')
|
|
|
|
return useQuery({
|
|
queryKey: ['organisations', id],
|
|
queryFn: async () => {
|
|
const { data } = await apiClient.get<ApiResponse<Organisation>>(`/organisations/${id.value}`)
|
|
return data.data
|
|
},
|
|
enabled: () => !!id.value,
|
|
})
|
|
}
|
|
|
|
export function useUpdateOrganisation() {
|
|
const queryClient = useQueryClient()
|
|
|
|
return useMutation({
|
|
mutationFn: async ({ id, ...payload }: UpdateOrganisationPayload & { id: string }) => {
|
|
const { data } = await apiClient.put<ApiResponse<Organisation>>(`/organisations/${id}`, payload)
|
|
return data.data
|
|
},
|
|
onSuccess: (_data, variables) => {
|
|
queryClient.invalidateQueries({ queryKey: ['organisations'] })
|
|
queryClient.invalidateQueries({ queryKey: ['organisations', variables.id] })
|
|
},
|
|
})
|
|
}
|