import React, { useState } from "react"; import { observer } from "mobx-react-lite"; import { useRouter } from "next/router"; import { usePopper } from "react-popper"; import { Popover, Transition } from "@headlessui/react"; // hooks // ui // icons import { Check, ChevronUp } from "lucide-react"; import { ToggleSwitch } from "@plane/ui"; // types import { IIssueDisplayFilterOptions, IIssueDisplayProperties, IIssueFilterOptions, TCalendarLayouts, TIssueKanbanFilters } from "@plane/types"; // constants import { CALENDAR_LAYOUTS } from "constants/calendar"; import { EIssueFilterType } from "constants/issue"; 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"; interface ICalendarHeader { issuesFilterStore: IProjectIssuesFilter | IModuleIssuesFilter | ICycleIssuesFilter | IProjectViewIssuesFilter; updateFilters?: ( projectId: string, filterType: EIssueFilterType, filters: IIssueFilterOptions | IIssueDisplayFilterOptions | IIssueDisplayProperties | TIssueKanbanFilters ) => Promise; } export const CalendarOptionsDropdown: React.FC = observer((props) => { const { issuesFilterStore, updateFilters } = props; const router = useRouter(); const { projectId } = router.query; const issueCalendarView = useCalendarView(); 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 calendarLayout = issuesFilterStore.issueFilters?.displayFilters?.calendar?.layout ?? "month"; const showWeekends = issuesFilterStore.issueFilters?.displayFilters?.calendar?.show_weekends ?? false; const handleLayoutChange = (layout: TCalendarLayouts) => { if (!projectId || !updateFilters) return; updateFilters(projectId.toString(), EIssueFilterType.DISPLAY_FILTERS, { calendar: { ...issuesFilterStore.issueFilters?.displayFilters?.calendar, layout, }, }); issueCalendarView.updateCalendarPayload( layout === "month" ? issueCalendarView.calendarFilters.activeMonthDate : issueCalendarView.calendarFilters.activeWeekDate ); }; const handleToggleWeekends = () => { const showWeekends = issuesFilterStore.issueFilters?.displayFilters?.calendar?.show_weekends ?? false; if (!projectId || !updateFilters) return; updateFilters(projectId.toString(), EIssueFilterType.DISPLAY_FILTERS, { calendar: { ...issuesFilterStore.issueFilters?.displayFilters?.calendar, show_weekends: !showWeekends, }, }); }; return ( {({ open }) => ( <>
{Object.entries(CALENDAR_LAYOUTS).map(([layout, layoutDetails]) => ( ))}
)}
); });