umami/src/components/hooks/queries/useReports.ts

30 lines
831 B
TypeScript
Raw Normal View History

2024-02-03 06:20:13 +00:00
'use client';
2023-06-15 10:27:41 +00:00
import useApi from './useApi';
2024-01-29 02:33:40 +00:00
import useFilterQuery from './useFilterQuery';
2024-01-30 08:10:25 +00:00
import useCache from 'store/cache';
2023-06-15 10:27:41 +00:00
2024-01-30 08:10:25 +00:00
export function useReports({ websiteId, teamId }: { websiteId?: string; teamId?: string }) {
const modified = useCache((state: any) => state?.reports);
2023-12-03 11:07:03 +00:00
const { get, del, useMutation } = useApi();
const queryResult = useFilterQuery({
2024-01-30 10:10:23 +00:00
queryKey: ['reports', { websiteId, teamId, modified }],
2023-12-03 11:07:03 +00:00
queryFn: (params: any) => {
2024-01-30 10:10:23 +00:00
return get('/reports', { websiteId, teamId, ...params });
2023-12-03 11:07:03 +00:00
},
2023-12-02 04:27:59 +00:00
});
2024-01-30 08:10:25 +00:00
const { mutate } = useMutation({ mutationFn: (reportId: string) => del(`/reports/${reportId}`) });
2023-06-15 10:27:41 +00:00
2024-01-30 08:10:25 +00:00
const deleteReport = (reportId: any) => {
mutate(reportId, {
onSuccess: () => {},
2023-07-30 07:11:26 +00:00
});
};
2023-08-10 20:26:33 +00:00
return {
2023-12-03 11:07:03 +00:00
...queryResult,
2023-08-10 20:26:33 +00:00
deleteReport,
};
2023-06-15 10:27:41 +00:00
}
export default useReports;