import { observer } from "mobx-react-lite"; // components import { ChevronLeft, ChevronRight } from "lucide-react"; import { CalendarMonthsDropdown, CalendarOptionsDropdown } from "components/issues"; // icons import { useCalendarView } from "hooks/store/use-calendar-view"; 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"; import { EIssueFilterType } from "constants/issue"; import { IIssueDisplayFilterOptions, IIssueDisplayProperties, IIssueFilterOptions, TIssueKanbanFilters, } from "@plane/types"; interface ICalendarHeader { issuesFilterStore: IProjectIssuesFilter | IModuleIssuesFilter | ICycleIssuesFilter | IProjectViewIssuesFilter; updateFilters?: ( projectId: string, filterType: EIssueFilterType, filters: IIssueFilterOptions | IIssueDisplayFilterOptions | IIssueDisplayProperties | TIssueKanbanFilters ) => Promise; setSelectedDate: (date: Date) => void; } export const CalendarHeader: React.FC = observer((props) => { const { issuesFilterStore, updateFilters, setSelectedDate } = props; const issueCalendarView = useCalendarView(); const calendarLayout = issuesFilterStore.issueFilters?.displayFilters?.calendar?.layout ?? "month"; const { activeMonthDate, activeWeekDate } = issueCalendarView.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); issueCalendarView.updateCalendarFilters({ activeMonthDate: previousMonthFirstDate, }); } else { const previousWeekDate = new Date( activeWeekDate.getFullYear(), activeWeekDate.getMonth(), activeWeekDate.getDate() - 7 ); issueCalendarView.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); issueCalendarView.updateCalendarFilters({ activeMonthDate: nextMonthFirstDate, }); } else { const nextWeekDate = new Date( activeWeekDate.getFullYear(), activeWeekDate.getMonth(), activeWeekDate.getDate() + 7 ); issueCalendarView.updateCalendarFilters({ activeWeekDate: nextWeekDate, }); } }; const handleToday = () => { const today = new Date(); const firstDayOfCurrentMonth = new Date(today.getFullYear(), today.getMonth(), 1); issueCalendarView.updateCalendarFilters({ activeMonthDate: firstDayOfCurrentMonth, activeWeekDate: today, }); setSelectedDate(today); }; return (
); });