import React, { useState } from "react"; import { useRouter } from "next/router"; import { Popover, Transition } from "@headlessui/react"; import { observer } from "mobx-react-lite"; import { usePopper } from "react-popper"; // mobx store import { useMobxStore } from "lib/mobx/store-provider"; // ui import { ToggleSwitch } from "@plane/ui"; // icons import { Check, ChevronUp } from "lucide-react"; // types import { TCalendarLayouts } from "types"; // constants import { CALENDAR_LAYOUTS } from "constants/calendar"; import { EFilterType } from "store/issues/types"; import { ICycleIssuesFilterStore, IModuleIssuesFilterStore, IProjectIssuesFilterStore, IViewIssuesFilterStore, } from "store/issues"; interface ICalendarHeader { issuesFilterStore: | IProjectIssuesFilterStore | IModuleIssuesFilterStore | ICycleIssuesFilterStore | IViewIssuesFilterStore; } export const CalendarOptionsDropdown: React.FC = observer((props) => { const { issuesFilterStore } = props; const router = useRouter(); const { workspaceSlug, projectId } = router.query; const { calendar: calendarStore } = useMobxStore(); 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 (!workspaceSlug || !projectId) return; issuesFilterStore.updateFilters(workspaceSlug.toString(), projectId.toString(), EFilterType.DISPLAY_FILTERS, { calendar: { ...issuesFilterStore.issueFilters?.displayFilters?.calendar, layout, }, }); calendarStore.updateCalendarPayload( layout === "month" ? calendarStore.calendarFilters.activeMonthDate : calendarStore.calendarFilters.activeWeekDate ); }; const handleToggleWeekends = () => { const showWeekends = issuesFilterStore.issueFilters?.displayFilters?.calendar?.show_weekends ?? false; if (!workspaceSlug || !projectId) return; issuesFilterStore.updateFilters(workspaceSlug.toString(), projectId.toString(), EFilterType.DISPLAY_FILTERS, { calendar: { ...issuesFilterStore.issueFilters?.displayFilters?.calendar, show_weekends: !showWeekends, }, }); }; return ( {({ open }) => ( <>
{Object.entries(CALENDAR_LAYOUTS).map(([layout, layoutDetails]) => ( ))}
)}
); });