Invalidated the next and prev nav buttons for the calender component when compared to a new valid date range state withing the calender context.

This commit is contained in:
Lucid Kobold
2022-03-25 23:50:07 -05:00
parent 03b5c0c651
commit 827441ca1e
3 changed files with 25 additions and 2 deletions

View File

@@ -2,12 +2,13 @@ import React, { useContext } from "react";
import { useRouter } from "next/router";
import { HStack, IconButton } from "@chakra-ui/react";
import { Icon } from "@iconify/react";
import { sub, add, format } from "date-fns";
import { sub, add, format, isSameMonth } from "date-fns";
import DatePicker from "./DatePicker";
import { CalenderContext } from "../../contexts/CalenderContext";
const CalenderNav = (): JSX.Element => {
const { selectedDate } = useContext(CalenderContext);
const { selectedDate, validDateRange } = useContext(CalenderContext);
const { start: validStart, end: validEnd } = validDateRange;
const router = useRouter();
@@ -43,12 +44,14 @@ const CalenderNav = (): JSX.Element => {
return (
<HStack spacing={10} as="nav" w="auto" h="10vh" textAlign="center">
<IconButton
isDisabled={isSameMonth(selectedDate, validStart)}
aria-label="Previous Month"
icon={<Icon icon="akar-icons:chevron-left" />}
onClick={() => handleNavButtons("prev")}
/>
<DatePicker />
<IconButton
isDisabled={isSameMonth(selectedDate, validEnd)}
aria-label="Next Month"
icon={<Icon icon="akar-icons:chevron-right" />}
onClick={() => handleNavButtons("next")}