import React, { useState } from "react"; import { observer } from "mobx-react-lite"; import { useRouter } from "next/router"; import { usePopper } from "react-popper"; import { Check, ChevronUp, MoreVerticalIcon } from "lucide-react"; import { Popover, Transition } from "@headlessui/react"; // hooks // ui // icons import { IIssueDisplayFilterOptions, IIssueDisplayProperties, IIssueFilterOptions, TCalendarLayouts, TIssueKanbanFilters, } from "@plane/types"; import { ToggleSwitch } from "@plane/ui"; // types // constants import { CALENDAR_LAYOUTS } from "@/constants/calendar"; import { EIssueFilterType } from "@/constants/issue"; import { useCalendarView } from "@/hooks/store"; import useSize from "@/hooks/use-window-size"; 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 [windowWidth] = useSize(); 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, closePopover: any) => { 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 ); if (windowWidth <= 768) closePopover(); // close the popover on mobile }; 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, close: closePopover }) => ( <>
{Object.entries(CALENDAR_LAYOUTS).map(([layout, layoutDetails]) => ( ))}
)}
); });