2023-10-25 10:39:50 +00:00
|
|
|
import { action, makeObservable, runInAction } from "mobx";
|
|
|
|
// types
|
|
|
|
import { RootStore } from "../root";
|
2023-10-30 14:39:04 +00:00
|
|
|
import { IIssueType } from "store/issue";
|
2023-10-25 10:39:50 +00:00
|
|
|
|
|
|
|
export interface IModuleIssueCalendarViewStore {
|
|
|
|
// actions
|
|
|
|
handleDragDrop: (source: any, destination: any) => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class ModuleIssueCalendarViewStore implements IModuleIssueCalendarViewStore {
|
|
|
|
// root store
|
|
|
|
rootStore;
|
|
|
|
|
|
|
|
constructor(_rootStore: RootStore) {
|
|
|
|
makeObservable(this, {
|
|
|
|
// actions
|
|
|
|
handleDragDrop: action,
|
|
|
|
});
|
|
|
|
|
|
|
|
this.rootStore = _rootStore;
|
|
|
|
}
|
|
|
|
|
|
|
|
handleDragDrop = async (source: any, destination: any) => {
|
|
|
|
const workspaceSlug = this.rootStore?.workspace?.workspaceSlug;
|
|
|
|
const projectId = this.rootStore?.project?.projectId;
|
|
|
|
const moduleId = this.rootStore?.module?.moduleId;
|
|
|
|
const issueType: IIssueType | null = this.rootStore?.moduleIssue?.getIssueType;
|
|
|
|
const issueLayout = this.rootStore?.issueFilter?.userDisplayFilters?.layout || null;
|
|
|
|
const currentIssues: any = this.rootStore.moduleIssue.getIssues;
|
|
|
|
|
|
|
|
if (workspaceSlug && projectId && moduleId && issueType && issueLayout === "calendar" && currentIssues) {
|
|
|
|
// update issue payload
|
|
|
|
let updateIssue: any = {
|
|
|
|
workspaceSlug: workspaceSlug,
|
|
|
|
projectId: projectId,
|
|
|
|
};
|
|
|
|
|
2023-11-06 15:30:36 +00:00
|
|
|
const droppableSourceColumnId = source?.droppableId || null;
|
|
|
|
const droppableDestinationColumnId = destination?.droppableId || null;
|
2023-10-25 10:39:50 +00:00
|
|
|
|
|
|
|
if (droppableSourceColumnId === droppableDestinationColumnId) return;
|
|
|
|
|
|
|
|
if (droppableSourceColumnId != droppableDestinationColumnId) {
|
|
|
|
// horizontal
|
|
|
|
const _sourceIssues = currentIssues[droppableSourceColumnId];
|
|
|
|
let _destinationIssues = currentIssues[droppableDestinationColumnId] || [];
|
|
|
|
|
|
|
|
const [removed] = _sourceIssues.splice(source.index, 1);
|
|
|
|
|
|
|
|
if (_destinationIssues && _destinationIssues.length > 0)
|
|
|
|
_destinationIssues.splice(destination.index, 0, {
|
|
|
|
...removed,
|
|
|
|
target_date: droppableDestinationColumnId,
|
|
|
|
});
|
|
|
|
else _destinationIssues = [..._destinationIssues, { ...removed, target_date: droppableDestinationColumnId }];
|
|
|
|
|
|
|
|
updateIssue = { ...updateIssue, issueId: removed?.id, target_date: droppableDestinationColumnId };
|
|
|
|
|
|
|
|
currentIssues[droppableSourceColumnId] = _sourceIssues;
|
|
|
|
currentIssues[droppableDestinationColumnId] = _destinationIssues;
|
|
|
|
}
|
|
|
|
|
|
|
|
const reorderedIssues = {
|
|
|
|
...this.rootStore?.moduleIssue.issues,
|
|
|
|
[moduleId]: {
|
|
|
|
...this.rootStore?.moduleIssue.issues?.[moduleId],
|
|
|
|
[issueType]: {
|
|
|
|
...this.rootStore?.moduleIssue.issues?.[moduleId]?.[issueType],
|
|
|
|
[issueType]: currentIssues,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
runInAction(() => {
|
|
|
|
this.rootStore.moduleIssue.issues = { ...reorderedIssues };
|
|
|
|
});
|
|
|
|
|
2023-11-29 08:55:57 +00:00
|
|
|
this.rootStore.projectIssues.updateIssue(
|
2023-10-25 10:39:50 +00:00
|
|
|
updateIssue.workspaceSlug,
|
|
|
|
updateIssue.projectId,
|
|
|
|
updateIssue.issueId,
|
|
|
|
updateIssue
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
}
|