diff --git a/src/app/dashboard/month-and-year-selector.tsx b/src/app/dashboard/month-and-year-selector.tsx index 7dff51b..a77d4e6 100644 --- a/src/app/dashboard/month-and-year-selector.tsx +++ b/src/app/dashboard/month-and-year-selector.tsx @@ -2,17 +2,19 @@ import { format, parse } from 'date-fns'; import { ChevronLeft, ChevronRight } from 'lucide-react'; -import type { AppRouterInstance } from 'next/dist/shared/lib/app-router-context.shared-runtime'; import { usePathname, useRouter } from 'next/navigation'; import { useState } from 'react'; import { Button } from '~/components/ui/button'; import { Popover, PopoverContent, PopoverTrigger } from '~/components/ui/popover'; import { cn } from '~/lib/utils'; -export default function MonthAndYearSelector({ month, year }: { month: string; year: string }) { +export default function MonthAndYearSelector(input: { month: string; year: string }) { const router = useRouter(); const pathname = usePathname(); + const [month, setMonth] = useState(input.month); + const [year, setYear] = useState(input.year); + const [isOpen, setIsOpen] = useState(false); return ( @@ -23,43 +25,42 @@ export default function MonthAndYearSelector({ month, year }: { month: string; y - - setIsOpen(false)} {...{ month, year, router, pathname }} /> + + + ); } -type MonthAndYearSelectorChild = { - month: string; +type YearSelectorProps = { year: string; - router: AppRouterInstance; - pathname: string; + setYear: (year: string) => void; }; -function YearSelector({ month, year, router, pathname }: MonthAndYearSelectorChild) { +function YearSelector({ year, setYear }: YearSelectorProps) { return (
{ - const params = new URLSearchParams(); - params.set('year', `${parseInt(year) - 1}`); - params.set('month', month); - router.push(pathname + '?' + params.toString()); - }} + onClick={() => setYear(`${parseInt(year) - 1}`)} >
{year}
{ - const params = new URLSearchParams(); - params.set('year', `${parseInt(year) + 1}`); - params.set('month', month); - router.push(pathname + '?' + params.toString()); - }} + onClick={() => setYear(`${parseInt(year) + 1}`)} >
@@ -67,15 +68,11 @@ function YearSelector({ month, year, router, pathname }: MonthAndYearSelectorChi ); } -function MonthSelector({ - month, - year, - router, - pathname, - onClick, -}: MonthAndYearSelectorChild & { - onClick: () => void; -}) { +type MonthSelectorProps = { + month: string; + setMonth: (month: string) => void; +}; +function MonthSelector({ month, setMonth }: MonthSelectorProps) { const months = [ 'January', 'February', @@ -97,11 +94,8 @@ function MonthSelector({