diff --git a/frontend/src/hooks/api/workspace/index.tsx b/frontend/src/hooks/api/workspace/index.tsx index 1daec0fd0..f5e5855d4 100644 --- a/frontend/src/hooks/api/workspace/index.tsx +++ b/frontend/src/hooks/api/workspace/index.tsx @@ -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"; diff --git a/frontend/src/hooks/api/workspace/mutations.tsx b/frontend/src/hooks/api/workspace/mutations.tsx index 11853157f..03f0d473d 100644 --- a/frontend/src/hooks/api/workspace/mutations.tsx +++ b/frontend/src/hooks/api/workspace/mutations.tsx @@ -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`; + } + }); +};