2023-11-23 09:17:04 +00:00
|
|
|
import { FC, useCallback } from "react";
|
2023-11-29 08:55:57 +00:00
|
|
|
import { useRouter } from "next/router";
|
2023-11-23 09:17:04 +00:00
|
|
|
import { observer } from "mobx-react-lite";
|
|
|
|
import { DragDropContext, DropResult } from "@hello-pangea/dnd";
|
|
|
|
// components
|
2023-11-29 08:55:57 +00:00
|
|
|
import { CalendarChart, IssuePeekOverview } from "components/issues";
|
2023-11-23 09:17:04 +00:00
|
|
|
// types
|
|
|
|
import { IIssue } from "types";
|
2023-11-27 08:45:33 +00:00
|
|
|
import {
|
|
|
|
ICycleIssuesFilterStore,
|
|
|
|
ICycleIssuesStore,
|
|
|
|
IModuleIssuesFilterStore,
|
|
|
|
IModuleIssuesStore,
|
|
|
|
IProjectIssuesFilterStore,
|
|
|
|
IProjectIssuesStore,
|
|
|
|
IViewIssuesFilterStore,
|
|
|
|
IViewIssuesStore,
|
|
|
|
} from "store/issues";
|
|
|
|
import { IIssueCalendarViewStore } from "store/issue";
|
2023-11-23 09:17:04 +00:00
|
|
|
import { IQuickActionProps } from "../list/list-view-types";
|
|
|
|
import { EIssueActions } from "../types";
|
|
|
|
import { IGroupedIssues } from "store/issues/types";
|
|
|
|
|
|
|
|
interface IBaseCalendarRoot {
|
|
|
|
issueStore: IProjectIssuesStore | IModuleIssuesStore | ICycleIssuesStore | IViewIssuesStore;
|
2023-11-27 08:45:33 +00:00
|
|
|
issuesFilterStore:
|
|
|
|
| IProjectIssuesFilterStore
|
|
|
|
| IModuleIssuesFilterStore
|
|
|
|
| ICycleIssuesFilterStore
|
|
|
|
| IViewIssuesFilterStore;
|
2023-11-23 09:17:04 +00:00
|
|
|
calendarViewStore: IIssueCalendarViewStore;
|
|
|
|
QuickActions: FC<IQuickActionProps>;
|
|
|
|
issueActions: {
|
|
|
|
[EIssueActions.DELETE]: (issue: IIssue) => void;
|
|
|
|
[EIssueActions.UPDATE]?: (issue: IIssue) => void;
|
|
|
|
[EIssueActions.REMOVE]?: (issue: IIssue) => void;
|
|
|
|
};
|
|
|
|
viewId?: string;
|
2023-11-28 13:47:38 +00:00
|
|
|
handleDragDrop: (source: any, destination: any, issues: any, issueWithIds: any) => void;
|
2023-11-23 09:17:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const BaseCalendarRoot = observer((props: IBaseCalendarRoot) => {
|
2023-11-29 08:55:57 +00:00
|
|
|
const { issueStore, issuesFilterStore, QuickActions, issueActions, viewId, handleDragDrop } = props;
|
|
|
|
|
|
|
|
// router
|
|
|
|
const router = useRouter();
|
|
|
|
const { workspaceSlug, peekIssueId, peekProjectId } = router.query;
|
2023-11-23 09:17:04 +00:00
|
|
|
|
2023-11-27 08:45:33 +00:00
|
|
|
const displayFilters = issuesFilterStore.issueFilters?.displayFilters;
|
2023-11-23 09:17:04 +00:00
|
|
|
|
|
|
|
const issues = issueStore.getIssues;
|
|
|
|
const groupedIssueIds = (issueStore.getIssuesIds ?? {}) as IGroupedIssues;
|
|
|
|
|
|
|
|
const onDragEnd = (result: DropResult) => {
|
|
|
|
if (!result) return;
|
|
|
|
|
|
|
|
// return if not dropped on the correct place
|
|
|
|
if (!result.destination) return;
|
|
|
|
|
|
|
|
// return if dropped on the same date
|
|
|
|
if (result.destination.droppableId === result.source.droppableId) return;
|
|
|
|
|
2023-11-28 13:47:38 +00:00
|
|
|
if (handleDragDrop) handleDragDrop(result.source, result.destination, issues, groupedIssueIds);
|
2023-11-23 09:17:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const handleIssues = useCallback(
|
|
|
|
(date: string, issue: IIssue, action: EIssueActions) => {
|
|
|
|
if (issueActions[action]) {
|
|
|
|
issueActions[action]!(issue);
|
|
|
|
}
|
|
|
|
},
|
2023-11-29 08:55:57 +00:00
|
|
|
[issueActions]
|
2023-11-23 09:17:04 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
2023-11-29 08:55:57 +00:00
|
|
|
<>
|
|
|
|
<div className="h-full w-full pt-4 bg-custom-background-100 overflow-hidden">
|
|
|
|
<DragDropContext onDragEnd={onDragEnd}>
|
|
|
|
<CalendarChart
|
|
|
|
issues={issues}
|
|
|
|
groupedIssueIds={groupedIssueIds}
|
|
|
|
layout={displayFilters?.calendar?.layout}
|
|
|
|
showWeekends={displayFilters?.calendar?.show_weekends ?? false}
|
2023-12-06 13:51:24 +00:00
|
|
|
quickActions={(issue, customActionButton) => (
|
2023-11-29 08:55:57 +00:00
|
|
|
<QuickActions
|
2023-12-06 13:51:24 +00:00
|
|
|
customActionButton={customActionButton}
|
2023-11-29 08:55:57 +00:00
|
|
|
issue={issue}
|
|
|
|
handleDelete={async () => handleIssues(issue.target_date ?? "", issue, EIssueActions.DELETE)}
|
|
|
|
handleUpdate={
|
|
|
|
issueActions[EIssueActions.UPDATE]
|
|
|
|
? async (data) => handleIssues(issue.target_date ?? "", data, EIssueActions.UPDATE)
|
|
|
|
: undefined
|
|
|
|
}
|
|
|
|
handleRemoveFromView={
|
|
|
|
issueActions[EIssueActions.REMOVE]
|
|
|
|
? async () => handleIssues(issue.target_date ?? "", issue, EIssueActions.REMOVE)
|
|
|
|
: undefined
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
quickAddCallback={issueStore.quickAddIssue}
|
|
|
|
viewId={viewId}
|
|
|
|
/>
|
|
|
|
</DragDropContext>
|
|
|
|
</div>
|
|
|
|
{workspaceSlug && peekIssueId && peekProjectId && (
|
|
|
|
<IssuePeekOverview
|
|
|
|
workspaceSlug={workspaceSlug.toString()}
|
|
|
|
projectId={peekProjectId.toString()}
|
|
|
|
issueId={peekIssueId.toString()}
|
|
|
|
handleIssue={(issueToUpdate) =>
|
|
|
|
handleIssues(issueToUpdate.target_date ?? "", issueToUpdate as IIssue, EIssueActions.UPDATE)
|
|
|
|
}
|
2023-11-23 09:17:04 +00:00
|
|
|
/>
|
2023-11-29 08:55:57 +00:00
|
|
|
)}
|
|
|
|
</>
|
2023-11-23 09:17:04 +00:00
|
|
|
);
|
|
|
|
});
|