Skip to content

Commit

Permalink
Invalidate instead of hard reload
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielHougaard committed Jun 17, 2024
1 parent 54c8da8 commit f121f8e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
8 changes: 4 additions & 4 deletions frontend/src/hooks/api/workspace/mutations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand Down Expand Up @@ -152,7 +153,7 @@ export const DeleteProjectSection = () => {
</Button>
)}
</ProjectPermissionCan>
{!!isOnlyAdminMember && (
{!isOnlyAdminMember && (
<Button
disabled={isMembersLoading || (members && members?.length < 2)}
isLoading={isLeaving}
Expand Down

0 comments on commit f121f8e

Please sign in to comment.