forked from github/plane
chore: error handling for user permission while issue drag & drop (#3060)
* filx: gantt chart quick add permission * fix: permission toast on drag & drop issues
This commit is contained in:
parent
bf2c6e36ef
commit
26d37fbd38
@ -4,6 +4,8 @@ import { observer } from "mobx-react-lite";
|
||||
import { DragDropContext, DropResult } from "@hello-pangea/dnd";
|
||||
// components
|
||||
import { CalendarChart, IssuePeekOverview } from "components/issues";
|
||||
// hooks
|
||||
import useToast from "hooks/use-toast";
|
||||
// types
|
||||
import { IIssue } from "types";
|
||||
import {
|
||||
@ -34,7 +36,7 @@ interface IBaseCalendarRoot {
|
||||
[EIssueActions.REMOVE]?: (issue: IIssue) => Promise<void>;
|
||||
};
|
||||
viewId?: string;
|
||||
handleDragDrop: (source: any, destination: any, issues: any, issueWithIds: any) => void;
|
||||
handleDragDrop: (source: any, destination: any, issues: any, issueWithIds: any) => Promise<void>;
|
||||
}
|
||||
|
||||
export const BaseCalendarRoot = observer((props: IBaseCalendarRoot) => {
|
||||
@ -44,12 +46,15 @@ export const BaseCalendarRoot = observer((props: IBaseCalendarRoot) => {
|
||||
const router = useRouter();
|
||||
const { workspaceSlug, peekIssueId, peekProjectId } = router.query;
|
||||
|
||||
// hooks
|
||||
const { setToastAlert } = useToast();
|
||||
|
||||
const displayFilters = issuesFilterStore.issueFilters?.displayFilters;
|
||||
|
||||
const issues = issueStore.getIssues;
|
||||
const groupedIssueIds = (issueStore.getIssuesIds ?? {}) as IGroupedIssues;
|
||||
|
||||
const onDragEnd = (result: DropResult) => {
|
||||
const onDragEnd = async (result: DropResult) => {
|
||||
if (!result) return;
|
||||
|
||||
// return if not dropped on the correct place
|
||||
@ -58,7 +63,15 @@ export const BaseCalendarRoot = observer((props: IBaseCalendarRoot) => {
|
||||
// return if dropped on the same date
|
||||
if (result.destination.droppableId === result.source.droppableId) return;
|
||||
|
||||
if (handleDragDrop) handleDragDrop(result.source, result.destination, issues, groupedIssueIds);
|
||||
if (handleDragDrop) {
|
||||
await handleDragDrop(result.source, result.destination, issues, groupedIssueIds).catch((err) => {
|
||||
setToastAlert({
|
||||
title: "Error",
|
||||
type: "error",
|
||||
message: err.detail ?? "Failed to perform this action",
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const handleIssues = useCallback(
|
||||
|
@ -41,9 +41,9 @@ export const CycleCalendarLayout: React.FC = observer(() => {
|
||||
},
|
||||
};
|
||||
|
||||
const handleDragDrop = (source: any, destination: any, issues: IIssue[], issueWithIds: any) => {
|
||||
const handleDragDrop = async (source: any, destination: any, issues: IIssue[], issueWithIds: any) => {
|
||||
if (workspaceSlug && projectId && cycleId)
|
||||
handleCalenderDragDrop(
|
||||
await handleCalenderDragDrop(
|
||||
source,
|
||||
destination,
|
||||
workspaceSlug.toString(),
|
||||
|
@ -38,8 +38,8 @@ export const ModuleCalendarLayout: React.FC = observer(() => {
|
||||
},
|
||||
};
|
||||
|
||||
const handleDragDrop = (source: any, destination: any, issues: IIssue[], issueWithIds: any) => {
|
||||
handleCalenderDragDrop(
|
||||
const handleDragDrop = async (source: any, destination: any, issues: IIssue[], issueWithIds: any) => {
|
||||
await handleCalenderDragDrop(
|
||||
source,
|
||||
destination,
|
||||
workspaceSlug,
|
||||
|
@ -31,9 +31,9 @@ export const CalendarLayout: React.FC = observer(() => {
|
||||
},
|
||||
};
|
||||
|
||||
const handleDragDrop = (source: any, destination: any, issues: IIssue[], issueWithIds: any) => {
|
||||
const handleDragDrop = async (source: any, destination: any, issues: IIssue[], issueWithIds: any) => {
|
||||
if (workspaceSlug && projectId)
|
||||
handleCalenderDragDrop(
|
||||
await handleCalenderDragDrop(
|
||||
source,
|
||||
destination,
|
||||
workspaceSlug.toString(),
|
||||
|
@ -32,9 +32,9 @@ export const ProjectViewCalendarLayout: React.FC = observer(() => {
|
||||
},
|
||||
};
|
||||
|
||||
const handleDragDrop = (source: any, destination: any, issues: IIssue[], issueWithIds: any) => {
|
||||
const handleDragDrop = async (source: any, destination: any, issues: IIssue[], issueWithIds: any) => {
|
||||
if (workspaceSlug && projectId)
|
||||
handleCalenderDragDrop(
|
||||
await handleCalenderDragDrop(
|
||||
source,
|
||||
destination,
|
||||
workspaceSlug.toString(),
|
||||
|
@ -121,8 +121,9 @@ export const GanttInlineCreateIssueForm: React.FC<Props> = observer((props) => {
|
||||
});
|
||||
|
||||
try {
|
||||
quickAddCallback && quickAddCallback(workspaceSlug, projectId, payload, viewId);
|
||||
|
||||
if (quickAddCallback) {
|
||||
await quickAddCallback(workspaceSlug, projectId, payload, viewId);
|
||||
}
|
||||
setToastAlert({
|
||||
type: "success",
|
||||
title: "Success!",
|
||||
|
@ -147,7 +147,7 @@ export const BaseKanBanRoot: React.FC<IBaseKanBanLayout> = observer((props: IBas
|
||||
setIsDragStarted(true);
|
||||
};
|
||||
|
||||
const onDragEnd = (result: DropResult) => {
|
||||
const onDragEnd = async (result: DropResult) => {
|
||||
setIsDragStarted(false);
|
||||
|
||||
if (!result) return;
|
||||
@ -171,7 +171,15 @@ export const BaseKanBanRoot: React.FC<IBaseKanBanLayout> = observer((props: IBas
|
||||
});
|
||||
setDeleteIssueModal(true);
|
||||
} else {
|
||||
handleDragDrop(result.source, result.destination, sub_group_by, group_by, issues, issueIds);
|
||||
await handleDragDrop(result.source, result.destination, sub_group_by, group_by, issues, issueIds).catch(
|
||||
(err) => {
|
||||
setToastAlert({
|
||||
title: "Error",
|
||||
type: "error",
|
||||
message: err.detail ?? "Failed to perform this action",
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -45,8 +45,8 @@ export class CalendarHelpers implements ICalendarHelpers {
|
||||
target_date: destinationColumnId,
|
||||
};
|
||||
|
||||
if (viewId) store?.updateIssue(workspaceSlug, projectId, updateIssue.id, updateIssue, viewId);
|
||||
else store?.updateIssue(workspaceSlug, projectId, updateIssue.id, updateIssue);
|
||||
if (viewId) return await store?.updateIssue(workspaceSlug, projectId, updateIssue.id, updateIssue, viewId);
|
||||
else return await store?.updateIssue(workspaceSlug, projectId, updateIssue.id, updateIssue);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user