Refactored useDateRange to always use query string. Fixed all time filter.

This commit is contained in:
Mike Cao 2025-10-03 17:55:39 -07:00
parent 4d06b0ca5b
commit 92ee44756c
28 changed files with 106 additions and 112 deletions

View file

@ -1,12 +1,23 @@
import { useApi } from '../useApi';
import { ReactQueryOptions } from '@/lib/types';
type DateRange = {
startDate?: string;
endDate?: string;
};
export function useDateRangeQuery(websiteId: string, options?: ReactQueryOptions) {
const { get, useQuery } = useApi();
return useQuery<any>({
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,
};
}