Skip to content

Commit 5ee36e1

Browse files
HyteqHyteq
authored andcommitted
feat: improved date-range
1 parent 47a1460 commit 5ee36e1

7 files changed

Lines changed: 454 additions & 187 deletions

File tree

apps/dashboard/app/(main)/layout.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Sidebar } from "@/components/layout/sidebar";
44
import { useAuthSession } from "@/app/providers";
55
import { RedirectToSignIn } from "@/components/auth/redirect-to-sign-in";
66
import { AuthLoading } from "@/components/auth/auth-loading";
7+
import { MantineProvider } from "@mantine/core";
78

89
export default function MainLayout({
910
children,

apps/dashboard/app/(main)/websites/[id]/page.tsx

Lines changed: 14 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ import { useWebsite } from "@/hooks/use-websites";
1515
import { useWebsiteAnalytics } from "@/hooks/use-analytics";
1616
import { format, subDays, subHours } from "date-fns";
1717
import type { DateRange as DayPickerRange } from "react-day-picker";
18-
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
19-
import { Calendar as CalendarComponent } from "@/components/ui/calendar";
18+
import { DateRangePicker } from "@/components/date-range-picker";
2019
import { useAtom } from "jotai";
2120
import {
2221
dateRangeAtom,
@@ -255,63 +254,19 @@ function WebsiteDetailsPage() {
255254
);
256255
})}
257256

258-
<Popover>
259-
<PopoverTrigger asChild>
260-
<Button
261-
variant="ghost"
262-
size="sm"
263-
className="h-6 text-xs gap-1 sm:gap-1.5 whitespace-nowrap px-2 sm:px-2.5 border-l border-border/50 ml-1 pl-2 sm:pl-3 touch-manipulation"
264-
>
265-
<CalendarIcon size={24} weight="fill" className="h-3 w-3 sm:h-3.5 sm:w-3.5 text-primary flex-shrink-0" />
266-
<span className="font-medium text-xs truncate">
267-
{dayPickerSelectedRange?.from ? format(dayPickerSelectedRange.from, 'MMM d') : ''} - {dayPickerSelectedRange?.to ? format(dayPickerSelectedRange.to, 'MMM d') : ''}
268-
</span>
269-
</Button>
270-
</PopoverTrigger>
271-
<PopoverContent className="w-auto p-2 border shadow-lg" align="end">
272-
<div className="grid gap-2">
273-
<div className="flex flex-col sm:flex-row sm:items-center justify-between mb-2 gap-2">
274-
<span className="text-sm font-medium">Select date range</span>
275-
<div className="flex gap-1 flex-wrap">
276-
{quickRanges.map((range) => (
277-
<Button
278-
key={range.label}
279-
variant="outline"
280-
size="sm"
281-
className="h-7 text-xs touch-manipulation"
282-
onClick={() => handleQuickRangeSelect(range)}
283-
>
284-
{range.label}
285-
</Button>
286-
))}
287-
</div>
288-
</div>
289-
<CalendarComponent
290-
initialFocus
291-
mode="range"
292-
defaultMonth={dayPickerSelectedRange?.from}
293-
selected={dayPickerSelectedRange}
294-
onSelect={handleDateRangeChange}
295-
numberOfMonths={window.innerWidth < 640 ? 1 : 2}
296-
disabled={(d) => d > new Date() || d < new Date(2020, 0, 1)}
297-
className="rounded-md border"
298-
/>
299-
<div className="flex justify-end">
300-
<Button
301-
size="sm"
302-
className="mt-2 touch-manipulation"
303-
onClick={() => {
304-
if (dayPickerSelectedRange?.from && dayPickerSelectedRange?.to) {
305-
setDateRangeAction({ startDate: dayPickerSelectedRange.from, endDate: dayPickerSelectedRange.to });
306-
}
307-
}}
308-
>
309-
Apply Range
310-
</Button>
311-
</div>
312-
</div>
313-
</PopoverContent>
314-
</Popover>
257+
<div className="border-l border-border/50 ml-1 pl-2 sm:pl-3">
258+
<DateRangePicker
259+
value={dayPickerSelectedRange}
260+
onChange={(range) => {
261+
if (range?.from && range?.to) {
262+
setDateRangeAction({ startDate: range.from, endDate: range.to });
263+
}
264+
}}
265+
maxDate={new Date()}
266+
minDate={new Date(2020, 0, 1)}
267+
className="w-auto"
268+
/>
269+
</div>
315270
</div>
316271
</div>
317272
)}

0 commit comments

Comments
 (0)