blob: 84b7eec7d08694ac3b55e7df7c76568af530db1a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
import type { ReactQueryOptions } from '@/lib/types';
import { useApi } from '../useApi';
type DateRange = {
startDate?: string;
endDate?: string;
};
export function useDateRangeQuery(websiteId: string, options?: ReactQueryOptions) {
const { get, useQuery } = useApi();
const { data } = useQuery<DateRange>({
queryKey: ['date-range', websiteId],
queryFn: () => get(`/websites/${websiteId}/daterange`),
enabled: !!websiteId,
...options,
});
return {
startDate: data?.startDate ? new Date(data.startDate) : null,
endDate: data?.endDate ? new Date(data.endDate) : null,
};
}
|