import React from "react"; import { useAppSelector } from "../../app/hooks"; import { useRouter } from "next/router"; import { HStack, IconButton } from "@chakra-ui/react"; import { Icon } from "@iconify/react"; import { format, isSameMonth, addMonths, subMonths } from "date-fns"; import findValidDateRange from "../../../lib/findValidDateRange"; import DatePicker from "./DatePicker"; interface CalenderNavProps { isLoading: boolean; title: string; } /** * @param {boolean} isLoading is the component loading? * @param {string} title the title for the current date. */ const CalenderNav = ({ title, isLoading }: CalenderNavProps): JSX.Element => { const selectedDate = useAppSelector( (state) => state.calender.selectedDateInfo ); const { date } = selectedDate; const selectedDateObj = new Date(date); const validDateRange = findValidDateRange(); const { start: validStart, end: validEnd } = validDateRange; const router = useRouter(); const handleNavButtons = (direction: "next" | "prev") => { if (direction === "next") { const newMonth = addMonths(selectedDateObj, 1); const year = format(newMonth, "y"); const month = format(newMonth, "L"); router.push(`/calendar/${year}/${month}`); } else if (direction === "prev") { const newMonth = subMonths(selectedDateObj, 1); const year = format(newMonth, "y"); const month = format(newMonth, "L"); router.push(`/calendar/${year}/${month}`); } }; return ( } onClick={() => handleNavButtons("prev")} /> } onClick={() => handleNavButtons("next")} /> ); }; export default CalenderNav;