"use client"; import { useEffect, useRef, useState } from "react"; import { combine } from "@atlaskit/pragmatic-drag-and-drop/combine"; import { autoScrollForElements } from "@atlaskit/pragmatic-drag-and-drop-auto-scroll/element"; import { observer } from "mobx-react-lite"; // types import type { IIssueDisplayFilterOptions, IIssueDisplayProperties, IIssueFilterOptions, TGroupedIssues, TIssue, TIssueKanbanFilters, TIssueMap, TPaginationData, } from "@plane/types"; // ui import { Spinner } from "@plane/ui"; // components import { CalendarHeader, CalendarIssueBlocks, CalendarWeekDays, CalendarWeekHeader } from "@/components/issues"; // constants import { MONTHS_LIST } from "@/constants/calendar"; import { EIssueFilterType, EIssueLayoutTypes, EIssuesStoreType } from "@/constants/issue"; import { EUserProjectRoles } from "@/constants/project"; // helpers import { cn } from "@/helpers/common.helper"; import { renderFormattedPayloadDate } from "@/helpers/date-time.helper"; // hooks import { useIssues, useUser } from "@/hooks/store"; import useSize from "@/hooks/use-window-size"; // store import { ICycleIssuesFilter } from "@/store/issue/cycle"; import { ICalendarStore } from "@/store/issue/issue_calendar_view.store"; import { IModuleIssuesFilter } from "@/store/issue/module"; import { IProjectIssuesFilter } from "@/store/issue/project"; import { IProjectViewIssuesFilter } from "@/store/issue/project-views"; import { IssueLayoutHOC } from "../issue-layout-HOC"; import { TRenderQuickActions } from "../list/list-view-types"; import type { ICalendarWeek } from "./types"; type Props = { issuesFilterStore: IProjectIssuesFilter | IModuleIssuesFilter | ICycleIssuesFilter | IProjectViewIssuesFilter; issues: TIssueMap | undefined; groupedIssueIds: TGroupedIssues; layout: "month" | "week" | undefined; showWeekends: boolean; issueCalendarView: ICalendarStore; loadMoreIssues: (dateString: string) => void; getPaginationData: (groupId: string | undefined) => TPaginationData | undefined; getGroupIssueCount: (groupId: string | undefined) => number | undefined; quickAddCallback?: (projectId: string | null | undefined, data: TIssue) => Promise; quickActions: TRenderQuickActions; handleDragAndDrop: ( issueId: string | undefined, sourceDate: string | undefined, destinationDate: string | undefined ) => Promise; addIssuesToView?: (issueIds: string[]) => Promise; readOnly?: boolean; updateFilters?: ( projectId: string, filterType: EIssueFilterType, filters: IIssueFilterOptions | IIssueDisplayFilterOptions | IIssueDisplayProperties | TIssueKanbanFilters ) => Promise; }; export const CalendarChart: React.FC = observer((props) => { const { issuesFilterStore, issues, groupedIssueIds, layout, showWeekends, issueCalendarView, loadMoreIssues, handleDragAndDrop, quickActions, quickAddCallback, addIssuesToView, getPaginationData, getGroupIssueCount, updateFilters, readOnly = false, } = props; // states const [selectedDate, setSelectedDate] = useState(new Date()); //refs const scrollableContainerRef = useRef(null); // store hooks const { issues: { viewFlags }, } = useIssues(EIssuesStoreType.PROJECT); const { membership: { currentProjectRole }, } = useUser(); const [windowWidth] = useSize(); const { enableIssueCreation } = viewFlags || {}; const isEditingAllowed = !!currentProjectRole && currentProjectRole >= EUserProjectRoles.MEMBER; const calendarPayload = issueCalendarView.calendarPayload; const allWeeksOfActiveMonth = issueCalendarView.allWeeksOfActiveMonth; const formattedDatePayload = renderFormattedPayloadDate(selectedDate) ?? undefined; // Enable Auto Scroll for calendar useEffect(() => { const element = scrollableContainerRef.current; if (!element) return; return combine( autoScrollForElements({ element, }) ); }, [scrollableContainerRef?.current]); if (!calendarPayload || !formattedDatePayload) return (
); const issueIdList = groupedIssueIds ? groupedIssueIds[formattedDatePayload] : []; return ( <>
768, })} ref={scrollableContainerRef} >
{layout === "month" && (
{allWeeksOfActiveMonth && Object.values(allWeeksOfActiveMonth).map((week: ICalendarWeek, weekIndex) => ( ))}
)} {layout === "week" && ( )}
{/* mobile view */}

{`${selectedDate.getDate()} ${ MONTHS_LIST[selectedDate.getMonth() + 1].title }, ${selectedDate.getFullYear()}`}

{/* mobile view */}

{`${selectedDate.getDate()} ${ MONTHS_LIST[selectedDate.getMonth() + 1].title }, ${selectedDate.getFullYear()}`}

); });