mirror of
https://github.com/complexcaresolutions/dak.c2s.git
synced 2026-03-17 23:03:41 +00:00
38 lines
1 KiB
TypeScript
38 lines
1 KiB
TypeScript
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
|
import api from '@/services/api'
|
|
import type { ReportMeta } from '@/types'
|
|
|
|
interface ReportsListResponse {
|
|
items: ReportMeta[]
|
|
total: number
|
|
}
|
|
|
|
export function useReports() {
|
|
return useQuery({
|
|
queryKey: ['reports'],
|
|
queryFn: () =>
|
|
api.get<ReportsListResponse>('/reports/list').then(r => r.data),
|
|
})
|
|
}
|
|
|
|
export function useGenerateReport() {
|
|
const queryClient = useQueryClient()
|
|
return useMutation({
|
|
mutationFn: (params: { jahr: number; kw: number }) =>
|
|
api.post<ReportMeta>('/reports/generate', null, { params }).then(r => r.data),
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: ['reports'] })
|
|
},
|
|
})
|
|
}
|
|
|
|
export function useDeleteReports() {
|
|
const queryClient = useQueryClient()
|
|
return useMutation({
|
|
mutationFn: (ids: number[]) =>
|
|
api.delete('/reports/delete', { data: ids }),
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: ['reports'] })
|
|
},
|
|
})
|
|
}
|