🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
make custom date selector work
Bill Yang9e6ff3f61aa0
diff --git a/client/src/app/[site]/components/Header/CustomDateRangePicker.tsx b/client/src/app/[site]/components/Header/CustomDateRangePicker.tsxindex 06bc6655b..501063ed4 100644--- a/client/src/app/[site]/components/Header/CustomDateRangePicker.tsx+++ b/client/src/app/[site]/components/Header/CustomDateRangePicker.tsx@@ -1,11 +1,10 @@"use client";-import * as React from "react";-import { addDays, format } from "date-fns";+import { format } from "date-fns";import { CalendarIcon } from "lucide-react";+import * as React from "react";import { DateRange } from "react-day-picker";-import { cn } from "@/lib/utils";import { Button } from "@/components/ui/button";import { Calendar } from "@/components/ui/calendar";import {@@ -13,14 +12,14 @@ import {PopoverContent,PopoverTrigger,} from "@/components/ui/popover";+import { cn } from "@/lib/utils";+import { useStore } from "../../../../lib/store";export function CustomDateRangePicker({className,}: React.HTMLAttributes<HTMLDivElement>) {- const [date, setDate] = React.useState<DateRange | undefined>({- from: new Date(2022, 0, 20),- to: addDays(new Date(2022, 0, 20), 20),- });+ const [date, setDate] = React.useState<DateRange | undefined>();+ const { setTime } = useStore();return (<div className={cn("grid gap-2", className)}>@@ -28,35 +27,36 @@ export function CustomDateRangePicker({<PopoverTrigger asChild><Buttonid="date"- variant={"default"}- className={cn(- "w-[300px] justify-start text-left font-normal",- !date && "text-muted-foreground"- )}+ variant={"ghost"}+ className={cn("justify-start text-left font-normal px-2")}>- <CalendarIcon />- {date?.from ? (- date.to ? (- <>- {format(date.from, "LLL dd, y")} -{" "}- {format(date.to, "LLL dd, y")}- </>- ) : (- format(date.from, "LLL dd, y")- )- ) : (- <span>Pick a date</span>- )}+ Custom Range</Button></PopoverTrigger>- <PopoverContent className="w-auto p-0" align="start">+ <PopoverContent className="w-auto p-0 " align="start"><CalendarinitialFocusmode="range"defaultMonth={date?.from}selected={date}- onSelect={setDate}+ onSelect={(range) => {+ setDate(range);+ if (!range) return;+ if (range?.to) {+ setTime({+ mode: "range",+ startDate: range?.from?.toISOString().split("T")[0] ?? "",+ endDate: range?.to?.toISOString().split("T")[0] ?? "",+ });+ } else {+ setTime({+ mode: "day",+ day: range?.from?.toISOString().split("T")[0] ?? "",+ });+ }+ }}numberOfMonths={2}+ disabled={{ after: new Date() }}/></PopoverContent></Popover>diff --git a/client/src/app/[site]/components/Header/DateSelector.tsx b/client/src/app/[site]/components/Header/DateSelector.tsxindex 2f5332163..d9d4a2724 100644--- a/client/src/app/[site]/components/Header/DateSelector.tsx+++ b/client/src/app/[site]/components/Header/DateSelector.tsx@@ -170,6 +170,17 @@ export function DateSelector() {>This Year</DropdownMenuItem>+ <DropdownMenuItem+ onClick={() =>+ setTime({+ mode: "year",+ year: DateTime.now().startOf("year").toISODate(),+ })+ }+ >+ All Time+ </DropdownMenuItem>+ <DropdownMenuSeparator /><CustomDateRangePicker /></DropdownMenuContent></DropdownMenu>diff --git a/client/src/app/[site]/components/MainSection/Chart.tsx b/client/src/app/[site]/components/MainSection/Chart.tsxindex f8b78bce6..f885e9fa3 100644--- a/client/src/app/[site]/components/MainSection/Chart.tsx+++ b/client/src/app/[site]/components/MainSection/Chart.tsx@@ -134,7 +134,7 @@ export function Chart({min: 0,stacked: false,reverse: false,- max: Math.max(max, 10),+ max: Math.max(max, 1),}}enableGridX={false}enableGridY={true}diff --git a/client/src/app/[site]/components/MainSection/PreviousChart.tsx b/client/src/app/[site]/components/MainSection/PreviousChart.tsxindex 1383d0a40..d19c64086 100644--- a/client/src/app/[site]/components/MainSection/PreviousChart.tsx+++ b/client/src/app/[site]/components/MainSection/PreviousChart.tsx@@ -65,7 +65,7 @@ export function PreviousChart({min: 0,stacked: false,reverse: false,- max: Math.max(max, 10),+ max: Math.max(max, 1),}}enableGridX={false}enableGridY={false}diff --git a/client/src/components/ui/calendar.tsx b/client/src/components/ui/calendar.tsxindex d483651a7..3b7e3e3b5 100644--- a/client/src/components/ui/calendar.tsx+++ b/client/src/components/ui/calendar.tsx@@ -1,13 +1,13 @@-"use client"+"use client";-import * as React from "react"-import { ChevronLeft, ChevronRight } from "lucide-react"-import { DayPicker } from "react-day-picker"+import * as React from "react";+import { ChevronLeft, ChevronRight } from "lucide-react";+import { DayPicker } from "react-day-picker";-import { cn } from "@/lib/utils"-import { buttonVariants } from "@/components/ui/button"+import { cn } from "@/lib/utils";+import { buttonVariants } from "@/components/ui/button";-export type CalendarProps = React.ComponentProps<typeof DayPicker>+export type CalendarProps = React.ComponentProps<typeof DayPicker>;function Calendar({className,@@ -50,7 +50,8 @@ function Calendar({day_range_end: "day-range-end",day_selected:"bg-neutral-900 text-neutral-50 hover:bg-neutral-900 hover:text-neutral-50 focus:bg-neutral-900 focus:text-neutral-50 dark:bg-neutral-50 dark:text-neutral-900 dark:hover:bg-neutral-50 dark:hover:text-neutral-900 dark:focus:bg-neutral-50 dark:focus:text-neutral-900",- day_today: "bg-neutral-100 text-neutral-900 dark:bg-neutral-800 dark:text-neutral-50",+ day_today:+ "bg-neutral-100 text-neutral-900 dark:bg-neutral-800 dark:text-neutral-50",day_outside:"day-outside text-neutral-500 aria-selected:bg-neutral-100/50 aria-selected:text-neutral-500 dark:text-neutral-400 dark:aria-selected:bg-neutral-800/50 dark:aria-selected:text-neutral-400",day_disabled: "text-neutral-500 opacity-50 dark:text-neutral-400",@@ -69,8 +70,8 @@ function Calendar({}}{...props}/>- )+ );}-Calendar.displayName = "Calendar"+Calendar.displayName = "Calendar";-export { Calendar }+export { Calendar };diff --git a/client/src/components/ui/popover.tsx b/client/src/components/ui/popover.tsxindex b270062e2..a21912a25 100644--- a/client/src/components/ui/popover.tsx+++ b/client/src/components/ui/popover.tsx@@ -1,15 +1,15 @@-"use client"+"use client";-import * as React from "react"-import * as PopoverPrimitive from "@radix-ui/react-popover"+import * as React from "react";+import * as PopoverPrimitive from "@radix-ui/react-popover";-import { cn } from "@/lib/utils"+import { cn } from "@/lib/utils";-const Popover = PopoverPrimitive.Root+const Popover = PopoverPrimitive.Root;-const PopoverTrigger = PopoverPrimitive.Trigger+const PopoverTrigger = PopoverPrimitive.Trigger;-const PopoverAnchor = PopoverPrimitive.Anchor+const PopoverAnchor = PopoverPrimitive.Anchor;const PopoverContent = React.forwardRef<React.ElementRef<typeof PopoverPrimitive.Content>,@@ -21,13 +21,13 @@ const PopoverContent = React.forwardRef<align={align}sideOffset={sideOffset}className={cn(- "z-50 w-72 rounded-md border border-neutral-200 bg-white p-4 text-neutral-950 shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 dark:border-neutral-800 dark:bg-neutral-950 dark:text-neutral-50",+ "z-50 w-72 rounded-md border border-neutral-200 bg-white p-4 text-neutral-950 shadow-xl outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 dark:border-neutral-850 dark:bg-neutral-900 dark:text-neutral-50",className)}{...props}/></PopoverPrimitive.Portal>-))-PopoverContent.displayName = PopoverPrimitive.Content.displayName+));+PopoverContent.displayName = PopoverPrimitive.Content.displayName;-export { Popover, PopoverTrigger, PopoverContent, PopoverAnchor }+export { Popover, PopoverTrigger, PopoverContent, PopoverAnchor };