11'use client' ;
22
3- import { filterOptions , type DynamicQueryFilter } from '@databuddy/shared' ;
3+ import { type DynamicQueryFilter , filterOptions } from '@databuddy/shared' ;
44import { ArrowClockwiseIcon , WarningIcon , XIcon } from '@phosphor-icons/react' ;
55import { useQueryClient } from '@tanstack/react-query' ;
6- import { format , subDays , subHours } from 'date-fns ' ;
6+ import dayjs from 'dayjs ' ;
77import { useAtom } from 'jotai' ;
88import dynamic from 'next/dynamic' ;
99import Link from 'next/link' ;
@@ -16,6 +16,7 @@ import { DateRangePicker } from '@/components/date-range-picker';
1616import { Button } from '@/components/ui/button' ;
1717import { Skeleton } from '@/components/ui/skeleton' ;
1818import { Tabs , TabsContent , TabsList , TabsTrigger } from '@/components/ui/tabs' ;
19+ import { operatorOptions , useFilters } from '@/hooks/use-filters' ;
1920import { useWebsite } from '@/hooks/use-websites' ;
2021import { trpc } from '@/lib/trpc' ;
2122import {
@@ -25,16 +26,15 @@ import {
2526 timeGranularityAtom ,
2627 timezoneAtom ,
2728} from '@/stores/jotai/filterAtoms' ;
28- import { operatorOptions , useFilters } from '@/hooks/use-filters' ;
29+ import {
30+ AddFilterForm ,
31+ getOperatorShorthand ,
32+ } from './_components/utils/add-filters' ;
2933import type {
3034 FullTabProps ,
3135 WebsiteDataTabProps ,
3236} from './_components/utils/types' ;
3337import { EmptyState } from './_components/utils/ui-components' ;
34- import {
35- AddFilterForm ,
36- getOperatorShorthand ,
37- } from './_components/utils/add-filters' ;
3838
3939type TabId =
4040 | 'overview'
@@ -130,8 +130,10 @@ function WebsiteDetailsPage() {
130130 ( range : ( typeof quickRanges ) [ 0 ] ) => {
131131 const now = new Date ( ) ;
132132 const start = range . hours
133- ? subHours ( now , range . hours )
134- : subDays ( now , range . days || 7 ) ;
133+ ? dayjs ( now ) . subtract ( range . hours , 'hour' ) . toDate ( )
134+ : dayjs ( now )
135+ . subtract ( range . days || 7 , 'day' )
136+ . toDate ( ) ;
135137 setDateRangeAction ( { startDate : start , endDate : now } ) ;
136138 } ,
137139 [ setDateRangeAction ]
@@ -336,16 +338,18 @@ function WebsiteDetailsPage() {
336338 { quickRanges . map ( ( range ) => {
337339 const now = new Date ( ) ;
338340 const start = range . hours
339- ? subHours ( now , range . hours )
340- : subDays ( now , range . days || 7 ) ;
341+ ? dayjs ( now ) . subtract ( range . hours , 'hour' ) . toDate ( )
342+ : dayjs ( now )
343+ . subtract ( range . days || 7 , 'day' )
344+ . toDate ( ) ;
341345 const dayPickerCurrentRange = dayPickerSelectedRange ;
342346 const isActive =
343347 dayPickerCurrentRange ?. from &&
344348 dayPickerCurrentRange ?. to &&
345- format ( dayPickerCurrentRange . from , 'yyyy -MM-dd ') ===
346- format ( start , 'yyyy -MM-dd ') &&
347- format ( dayPickerCurrentRange . to , 'yyyy -MM-dd ') ===
348- format ( now , 'yyyy -MM-dd ') ;
349+ dayjs ( dayPickerCurrentRange . from ) . format ( 'YYYY -MM-DD ') ===
350+ dayjs ( start ) . format ( 'YYYY -MM-DD ') &&
351+ dayjs ( dayPickerCurrentRange . to ) . format ( 'YYYY -MM-DD ') ===
352+ dayjs ( now ) . format ( 'YYYY -MM-DD ') ;
349353
350354 return (
351355 < Button
0 commit comments