aboutsummaryrefslogtreecommitdiff
path: root/src/components/hooks/queries/useDateRangeQuery.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/hooks/queries/useDateRangeQuery.ts')
-rw-r--r--src/components/hooks/queries/useDateRangeQuery.ts23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/components/hooks/queries/useDateRangeQuery.ts b/src/components/hooks/queries/useDateRangeQuery.ts
new file mode 100644
index 0000000..84b7eec
--- /dev/null
+++ b/src/components/hooks/queries/useDateRangeQuery.ts
@@ -0,0 +1,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,
+ };
+}