mirror of
https://github.com/BradNut/umami
synced 2025-09-08 17:40:29 +00:00
35 lines
693 B
TypeScript
35 lines
693 B
TypeScript
|
|
import useApi from './useApi';
|
||
|
|
import { UseQueryOptions } from '@tanstack/react-query';
|
||
|
|
|
||
|
|
export function useWebsiteMetrics(
|
||
|
|
websiteId: string,
|
||
|
|
params?: { [key: string]: any },
|
||
|
|
options?: Omit<UseQueryOptions, 'queryKey' | 'queryFn'>,
|
||
|
|
) {
|
||
|
|
const { get, useQuery } = useApi();
|
||
|
|
|
||
|
|
return useQuery({
|
||
|
|
queryKey: [
|
||
|
|
'websites:metrics',
|
||
|
|
{
|
||
|
|
websiteId,
|
||
|
|
...params,
|
||
|
|
},
|
||
|
|
],
|
||
|
|
queryFn: async () => {
|
||
|
|
const filters = { ...params };
|
||
|
|
|
||
|
|
filters[params.type] = undefined;
|
||
|
|
|
||
|
|
const data = await get(`/websites/${websiteId}/metrics`, {
|
||
|
|
...filters,
|
||
|
|
});
|
||
|
|
|
||
|
|
return data;
|
||
|
|
},
|
||
|
|
...options,
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
export default useWebsiteMetrics;
|