import { observer } from "mobx-react-lite"; // mobx store import { useMobxStore } from "lib/mobx/store-provider"; // components import { CalendarMonthsDropdown, CalendarOptionsDropdown } from "components/issues"; // icons import { ChevronLeft, ChevronRight } from "lucide-react"; import { ICycleIssuesFilterStore, IModuleIssuesFilterStore, IProjectIssuesFilterStore, IViewIssuesFilterStore, } from "store/issues"; interface ICalendarHeader { issuesFilterStore: | IProjectIssuesFilterStore | IModuleIssuesFilterStore | ICycleIssuesFilterStore | IViewIssuesFilterStore; } export const CalendarHeader: React.FC = observer((props) => { const { issuesFilterStore } = props; const { issueFilter: issueFilterStore, calendar: calendarStore } = useMobxStore(); const calendarLayout = issueFilterStore.userDisplayFilters.calendar?.layout ?? "month"; const { activeMonthDate, activeWeekDate } = calendarStore.calendarFilters; const handlePrevious = () => { if (calendarLayout === "month") { const previousMonthYear = activeMonthDate.getMonth() === 0 ? activeMonthDate.getFullYear() - 1 : activeMonthDate.getFullYear(); const previousMonthMonth = activeMonthDate.getMonth() === 0 ? 11 : activeMonthDate.getMonth() - 1; const previousMonthFirstDate = new Date(previousMonthYear, previousMonthMonth, 1); calendarStore.updateCalendarFilters({ activeMonthDate: previousMonthFirstDate, }); } else { const previousWeekDate = new Date( activeWeekDate.getFullYear(), activeWeekDate.getMonth(), activeWeekDate.getDate() - 7 ); calendarStore.updateCalendarFilters({ activeWeekDate: previousWeekDate, }); } }; const handleNext = () => { if (calendarLayout === "month") { const nextMonthYear = activeMonthDate.getMonth() === 11 ? activeMonthDate.getFullYear() + 1 : activeMonthDate.getFullYear(); const nextMonthMonth = (activeMonthDate.getMonth() + 1) % 12; const nextMonthFirstDate = new Date(nextMonthYear, nextMonthMonth, 1); calendarStore.updateCalendarFilters({ activeMonthDate: nextMonthFirstDate, }); } else { const nextWeekDate = new Date( activeWeekDate.getFullYear(), activeWeekDate.getMonth(), activeWeekDate.getDate() + 7 ); calendarStore.updateCalendarFilters({ activeWeekDate: nextWeekDate, }); } }; const handleToday = () => { const today = new Date(); const firstDayOfCurrentMonth = new Date(today.getFullYear(), today.getMonth(), 1); calendarStore.updateCalendarFilters({ activeMonthDate: firstDayOfCurrentMonth, activeWeekDate: today, }); }; return (
); });