Leave project mutation

This commit is contained in:
Daniel Hougaard
2024-06-17 22:08:08 +02:00
parent 5142d6f3c1
commit 80e55a9341
2 changed files with 15 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
export {
useAddGroupToWorkspace,
useDeleteGroupFromWorkspace,
useLeaveProject,
useUpdateGroupWorkspaceRole
} from "./mutations";
export {
@@ -30,4 +31,5 @@ export {
useUpdateIdentityWorkspaceRole,
useUpdateUserWorkspaceRole,
useUpdateWsEnvironment,
useUpgradeProject} from "./queries";
useUpgradeProject
} from "./queries";

View File

@@ -62,3 +62,15 @@ export const useDeleteGroupFromWorkspace = () => {
}
});
};
export const useLeaveProject = () => {
return useMutation<{}, {}, { workspaceId: string; organizationId: 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`;
}
});
};