import { Popover, Transition } from "@headlessui/react"; import { addMonths, addSevenDaysToDate, formatDate, getCurrentWeekEndDate, getCurrentWeekStartDate, isSameMonth, isSameYear, lastDayOfWeek, startOfWeek, subtract7DaysToDate, subtractMonths, updateDateWithMonth, updateDateWithYear, } from "helpers/calendar.helper"; import React from "react"; import { monthOptions, yearOptions } from "constants/calendar"; import { ICalendarRange } from "types"; import { CheckIcon, ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, } from "@heroicons/react/24/outline"; import { CustomMenu, ToggleSwitch } from "components/ui"; type Props = { isMonthlyView: boolean; setIsMonthlyView: React.Dispatch>; currentDate: Date; setCurrentDate: React.Dispatch>; setCalendarDateRange: React.Dispatch>; showWeekEnds: boolean; setShowWeekEnds: React.Dispatch>; }; export const CalendarHeader: React.FC = ({ setIsMonthlyView, isMonthlyView, currentDate, setCurrentDate, setCalendarDateRange, showWeekEnds, setShowWeekEnds, }) => { const updateDate = (date: Date) => { setCurrentDate(date); setCalendarDateRange({ startDate: startOfWeek(date), endDate: lastDayOfWeek(date), }); }; return (
{({ open }) => ( <>
{formatDate(currentDate, "Month")}{" "} {formatDate(currentDate, "yyyy")}
{yearOptions.map((year) => ( ))}
{monthOptions.map((month) => ( ))}
)}
{isMonthlyView ? "Monthly" : "Weekly"}
} > { setIsMonthlyView(true); setCalendarDateRange({ startDate: startOfWeek(currentDate), endDate: lastDayOfWeek(currentDate), }); }} className="w-52 text-sm text-brand-secondary" >
Monthly View
{ setIsMonthlyView(false); setCalendarDateRange({ startDate: getCurrentWeekStartDate(currentDate), endDate: getCurrentWeekEndDate(currentDate), }); }} className="w-52 text-sm text-brand-secondary" >
Weekly View

Show weekends

setShowWeekEnds(!showWeekEnds)} />
); }; export default CalendarHeader;