From 6d0cf1b4e99f52ca5fb65941aaa6f6dfe0e15913 Mon Sep 17 00:00:00 2001 From: Anmol Singh Bhatia <121005188+anmolsinghbhatia@users.noreply.github.com> Date: Fri, 9 Aug 2024 19:14:38 +0530 Subject: [PATCH] [WEB-2190] fix: unauthorised delete and redirections (#5342) * fix: cycle unauthorised delete action redirection * fix: intake unauthorised delete action redirection --- web/core/components/cycles/delete-modal.tsx | 3 +- .../inbox/content/inbox-issue-header.tsx | 2 +- web/core/store/inbox/project-inbox.store.ts | 30 +++++++++---------- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/web/core/components/cycles/delete-modal.tsx b/web/core/components/cycles/delete-modal.tsx index b9b1fdbc55..e31a785b53 100644 --- a/web/core/components/cycles/delete-modal.tsx +++ b/web/core/components/cycles/delete-modal.tsx @@ -42,6 +42,7 @@ export const CycleDeleteModal: React.FC = observer((props) => { try { await deleteCycle(workspaceSlug, projectId, cycle.id) .then(() => { + if (cycleId || peekCycle) router.push(`/${workspaceSlug}/projects/${projectId}/cycles`); setToast({ type: TOAST_TYPE.SUCCESS, title: "Success!", @@ -68,8 +69,6 @@ export const CycleDeleteModal: React.FC = observer((props) => { }); }) .finally(() => handleClose()); - - if (cycleId || peekCycle) router.push(`/${workspaceSlug}/projects/${projectId}/cycles`); } catch (error) { setToast({ type: TOAST_TYPE.ERROR, diff --git a/web/core/components/inbox/content/inbox-issue-header.tsx b/web/core/components/inbox/content/inbox-issue-header.tsx index 1b18f063ab..8d4561fc12 100644 --- a/web/core/components/inbox/content/inbox-issue-header.tsx +++ b/web/core/components/inbox/content/inbox-issue-header.tsx @@ -140,7 +140,7 @@ export const InboxIssueActionsHeader: FC = observer((p const handleInboxIssueDelete = async () => { if (!inboxIssue || !currentInboxIssueId) return; - await deleteInboxIssue(workspaceSlug, projectId, currentInboxIssueId).finally(() => { + await deleteInboxIssue(workspaceSlug, projectId, currentInboxIssueId).then(() => { if (!isNotificationEmbed) router.push(`/${workspaceSlug}/projects/${projectId}/inbox`); }); }; diff --git a/web/core/store/inbox/project-inbox.store.ts b/web/core/store/inbox/project-inbox.store.ts index d270ab068d..bf0a485762 100644 --- a/web/core/store/inbox/project-inbox.store.ts +++ b/web/core/store/inbox/project-inbox.store.ts @@ -484,25 +484,23 @@ export class ProjectInboxStore implements IProjectInboxStore { const currentIssue = this.inboxIssues?.[inboxIssueId]; try { if (!currentIssue) return; - runInAction(() => { - set( - this, - ["inboxIssuePaginationInfo", "total_results"], - (this.inboxIssuePaginationInfo?.total_results || 0) - 1 - ); - set(this, "inboxIssues", omit(this.inboxIssues, inboxIssueId)); - set( - this, - ["inboxIssueIds"], - this.inboxIssueIds.filter((id) => id !== inboxIssueId) - ); + await this.inboxIssueService.destroy(workspaceSlug, projectId, inboxIssueId).then(() => { + runInAction(() => { + set( + this, + ["inboxIssuePaginationInfo", "total_results"], + (this.inboxIssuePaginationInfo?.total_results || 0) - 1 + ); + set(this, "inboxIssues", omit(this.inboxIssues, inboxIssueId)); + set( + this, + ["inboxIssueIds"], + this.inboxIssueIds.filter((id) => id !== inboxIssueId) + ); + }); }); - await this.inboxIssueService.destroy(workspaceSlug, projectId, inboxIssueId); } catch (error) { console.error("Error removing the intake issue"); - set(this.inboxIssues, [inboxIssueId], currentIssue); - set(this, ["inboxIssuePaginationInfo", "total_results"], (this.inboxIssuePaginationInfo?.total_results || 0) + 1); - set(this, ["inboxIssueIds"], [...this.inboxIssueIds, inboxIssueId]); throw error; } };