From f121f8e828d6da92af0847f9bbd53fb2a80d6b09 Mon Sep 17 00:00:00 2001 From: Daniel Hougaard <62331820+DanielHougaard@users.noreply.github.com> Date: Mon, 17 Jun 2024 22:35:35 +0200 Subject: [PATCH] Invalidate instead of hard reload --- frontend/src/hooks/api/workspace/mutations.tsx | 8 ++++---- .../DeleteProjectSection/DeleteProjectSection.tsx | 7 ++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/frontend/src/hooks/api/workspace/mutations.tsx b/frontend/src/hooks/api/workspace/mutations.tsx index 03f0d473d..5aba02098 100644 --- a/frontend/src/hooks/api/workspace/mutations.tsx +++ b/frontend/src/hooks/api/workspace/mutations.tsx @@ -64,13 +64,13 @@ export const useDeleteGroupFromWorkspace = () => { }; export const useLeaveProject = () => { - return useMutation<{}, {}, { workspaceId: string; organizationId: string }>({ + const queryClient = useQueryClient(); + return useMutation<{}, {}, { workspaceId: string }>({ mutationFn: ({ workspaceId }) => { return apiRequest.delete(`/api/v1/workspace/${workspaceId}/leave`); }, - onSuccess: (_, { organizationId }) => { - // Invalidating the query here will cause a permission error, so we won't invalidate any queries here. Instead after leaving the workspace, we will redirect the user to the organization overview page. - window.location.href = `/org/${organizationId}/overview`; + onSuccess: () => { + queryClient.invalidateQueries(workspaceKeys.getAllUserWorkspace); } }); }; diff --git a/frontend/src/views/Settings/ProjectSettingsPage/components/DeleteProjectSection/DeleteProjectSection.tsx b/frontend/src/views/Settings/ProjectSettingsPage/components/DeleteProjectSection/DeleteProjectSection.tsx index 81ee31101..edbb78c2e 100644 --- a/frontend/src/views/Settings/ProjectSettingsPage/components/DeleteProjectSection/DeleteProjectSection.tsx +++ b/frontend/src/views/Settings/ProjectSettingsPage/components/DeleteProjectSection/DeleteProjectSection.tsx @@ -114,9 +114,10 @@ export const DeleteProjectSection = () => { } } + // If it's actually a no-access member, then we don't really care about the members. + await leaveProject.mutateAsync({ - workspaceId: currentWorkspace.id, - organizationId: currentOrg.id + workspaceId: currentWorkspace.id }); router.push(`/org/${currentOrg.id}/overview`); @@ -152,7 +153,7 @@ export const DeleteProjectSection = () => { )} - {!!isOnlyAdminMember && ( + {!isOnlyAdminMember && (