Refactored filter parameters.

This commit is contained in:
Mike Cao 2024-03-26 17:31:16 -07:00
parent 1a839d1cae
commit cff2d00536
13 changed files with 291 additions and 123 deletions

View file

@ -1,19 +1,30 @@
import { useApi } from 'components/hooks';
import { subDays } from 'date-fns';
export function useWebsiteValues(websiteId: string, type: string) {
const now = Date.now();
export function useWebsiteValues({
websiteId,
type,
startDate,
endDate,
search,
}: {
websiteId: string;
type: string;
startDate: Date;
endDate: Date;
search?: string;
}) {
const { get, useQuery } = useApi();
return useQuery({
queryKey: ['websites:values', websiteId, type],
queryKey: ['websites:values', { websiteId, type, startDate, endDate, search }],
queryFn: () =>
get(`/websites/${websiteId}/values`, {
type,
startAt: +subDays(now, 90),
endAt: now,
startAt: +startDate,
endAt: +endDate,
search,
}),
enabled: !!(websiteId && type),
enabled: !!(websiteId && type && startDate && endDate),
});
}