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:
Lakhan Baheti 2023-12-11 15:51:40 +05:30 committed by GitHub
parent bf2c6e36ef
commit 26d37fbd38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 39 additions and 17 deletions

View File

@ -4,6 +4,8 @@ import { observer } from "mobx-react-lite";
import { DragDropContext, DropResult } from "@hello-pangea/dnd"; import { DragDropContext, DropResult } from "@hello-pangea/dnd";
// components // components
import { CalendarChart, IssuePeekOverview } from "components/issues"; import { CalendarChart, IssuePeekOverview } from "components/issues";
// hooks
import useToast from "hooks/use-toast";
// types // types
import { IIssue } from "types"; import { IIssue } from "types";
import { import {
@ -34,7 +36,7 @@ interface IBaseCalendarRoot {
[EIssueActions.REMOVE]?: (issue: IIssue) => Promise<void>; [EIssueActions.REMOVE]?: (issue: IIssue) => Promise<void>;
}; };
viewId?: string; 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) => { export const BaseCalendarRoot = observer((props: IBaseCalendarRoot) => {
@ -44,12 +46,15 @@ export const BaseCalendarRoot = observer((props: IBaseCalendarRoot) => {
const router = useRouter(); const router = useRouter();
const { workspaceSlug, peekIssueId, peekProjectId } = router.query; const { workspaceSlug, peekIssueId, peekProjectId } = router.query;
// hooks
const { setToastAlert } = useToast();
const displayFilters = issuesFilterStore.issueFilters?.displayFilters; const displayFilters = issuesFilterStore.issueFilters?.displayFilters;
const issues = issueStore.getIssues; const issues = issueStore.getIssues;
const groupedIssueIds = (issueStore.getIssuesIds ?? {}) as IGroupedIssues; const groupedIssueIds = (issueStore.getIssuesIds ?? {}) as IGroupedIssues;
const onDragEnd = (result: DropResult) => { const onDragEnd = async (result: DropResult) => {
if (!result) return; if (!result) return;
// return if not dropped on the correct place // 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 // return if dropped on the same date
if (result.destination.droppableId === result.source.droppableId) return; 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( const handleIssues = useCallback(

View File

@ -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) if (workspaceSlug && projectId && cycleId)
handleCalenderDragDrop( await handleCalenderDragDrop(
source, source,
destination, destination,
workspaceSlug.toString(), workspaceSlug.toString(),

View File

@ -38,8 +38,8 @@ export const ModuleCalendarLayout: React.FC = observer(() => {
}, },
}; };
const handleDragDrop = (source: any, destination: any, issues: IIssue[], issueWithIds: any) => { const handleDragDrop = async (source: any, destination: any, issues: IIssue[], issueWithIds: any) => {
handleCalenderDragDrop( await handleCalenderDragDrop(
source, source,
destination, destination,
workspaceSlug, workspaceSlug,

View File

@ -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) if (workspaceSlug && projectId)
handleCalenderDragDrop( await handleCalenderDragDrop(
source, source,
destination, destination,
workspaceSlug.toString(), workspaceSlug.toString(),

View File

@ -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) if (workspaceSlug && projectId)
handleCalenderDragDrop( await handleCalenderDragDrop(
source, source,
destination, destination,
workspaceSlug.toString(), workspaceSlug.toString(),

View File

@ -121,8 +121,9 @@ export const GanttInlineCreateIssueForm: React.FC<Props> = observer((props) => {
}); });
try { try {
quickAddCallback && quickAddCallback(workspaceSlug, projectId, payload, viewId); if (quickAddCallback) {
await quickAddCallback(workspaceSlug, projectId, payload, viewId);
}
setToastAlert({ setToastAlert({
type: "success", type: "success",
title: "Success!", title: "Success!",

View File

@ -147,7 +147,7 @@ export const BaseKanBanRoot: React.FC<IBaseKanBanLayout> = observer((props: IBas
setIsDragStarted(true); setIsDragStarted(true);
}; };
const onDragEnd = (result: DropResult) => { const onDragEnd = async (result: DropResult) => {
setIsDragStarted(false); setIsDragStarted(false);
if (!result) return; if (!result) return;
@ -171,7 +171,15 @@ export const BaseKanBanRoot: React.FC<IBaseKanBanLayout> = observer((props: IBas
}); });
setDeleteIssueModal(true); setDeleteIssueModal(true);
} else { } 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",
});
}
);
} }
} }
}; };

View File

@ -45,8 +45,8 @@ export class CalendarHelpers implements ICalendarHelpers {
target_date: destinationColumnId, target_date: destinationColumnId,
}; };
if (viewId) store?.updateIssue(workspaceSlug, projectId, updateIssue.id, updateIssue, viewId); if (viewId) return await store?.updateIssue(workspaceSlug, projectId, updateIssue.id, updateIssue, viewId);
else store?.updateIssue(workspaceSlug, projectId, updateIssue.id, updateIssue); else return await store?.updateIssue(workspaceSlug, projectId, updateIssue.id, updateIssue);
} }
} }
}; };