import React, { useState } from "react"; import { observer } from "mobx-react-lite"; import { usePopper } from "react-popper"; import { ChevronLeft, ChevronRight } from "lucide-react"; import { Popover, Transition } from "@headlessui/react"; //hooks // icons // constants import { MONTHS_LIST } from "@/constants/calendar"; import { getDate } from "@/helpers/date-time.helper"; import { useCalendarView } from "@/hooks/store"; import { ICycleIssuesFilter } from "@/store/issue/cycle"; import { IModuleIssuesFilter } from "@/store/issue/module"; import { IProjectIssuesFilter } from "@/store/issue/project"; import { IProjectViewIssuesFilter } from "@/store/issue/project-views"; // helpers interface Props { issuesFilterStore: IProjectIssuesFilter | IModuleIssuesFilter | ICycleIssuesFilter | IProjectViewIssuesFilter; } export const CalendarMonthsDropdown: React.FC = observer((props: Props) => { const { issuesFilterStore } = props; const issueCalendarView = useCalendarView(); const calendarLayout = issuesFilterStore.issueFilters?.displayFilters?.calendar?.layout ?? "month"; const [referenceElement, setReferenceElement] = useState(null); const [popperElement, setPopperElement] = useState(null); const { styles, attributes } = usePopper(referenceElement, popperElement, { placement: "auto", modifiers: [ { name: "preventOverflow", options: { padding: 12, }, }, ], }); const { activeMonthDate } = issueCalendarView.calendarFilters; const getWeekLayoutHeader = (): string => { const allDaysOfActiveWeek = issueCalendarView.allDaysOfActiveWeek; if (!allDaysOfActiveWeek) return "Week view"; const daysList = Object.keys(allDaysOfActiveWeek); const firstDay = getDate(daysList[0]); const lastDay = getDate(daysList[daysList.length - 1]); if (!firstDay || !lastDay) return "Week view"; if (firstDay.getMonth() === lastDay.getMonth() && firstDay.getFullYear() === lastDay.getFullYear()) return `${MONTHS_LIST[firstDay.getMonth() + 1].title} ${firstDay.getFullYear()}`; if (firstDay.getFullYear() !== lastDay.getFullYear()) { return `${MONTHS_LIST[firstDay.getMonth() + 1].shortTitle} ${firstDay.getFullYear()} - ${ MONTHS_LIST[lastDay.getMonth() + 1].shortTitle } ${lastDay.getFullYear()}`; } else return `${MONTHS_LIST[firstDay.getMonth() + 1].shortTitle} - ${ MONTHS_LIST[lastDay.getMonth() + 1].shortTitle } ${lastDay.getFullYear()}`; }; const handleDateChange = (date: Date) => { issueCalendarView.updateCalendarFilters({ activeMonthDate: date, }); }; return (
{activeMonthDate.getFullYear()}
{Object.values(MONTHS_LIST).map((month, index) => ( ))}
); });