Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/dashboard/src/data/auth-providers/delete-org-auth-provider-mutation.ts
2501 views
1
/**
2
* Copyright (c) 2023 Gitpod GmbH. All rights reserved.
3
* Licensed under the GNU Affero General Public License (AGPL).
4
* See License.AGPL.txt in the project root for license information.
5
*/
6
7
import { useMutation, useQueryClient } from "@tanstack/react-query";
8
import { useCurrentOrg } from "../organizations/orgs-query";
9
import { getOrgAuthProvidersQueryKey } from "./org-auth-providers-query";
10
import { authProviderClient } from "../../service/public-api";
11
import { AuthProvider, DeleteAuthProviderRequest } from "@gitpod/public-api/lib/gitpod/v1/authprovider_pb";
12
13
type DeleteAuthProviderArgs = {
14
providerId: string;
15
};
16
export const useDeleteOrgAuthProviderMutation = () => {
17
const queryClient = useQueryClient();
18
const organization = useCurrentOrg().data;
19
20
return useMutation({
21
mutationFn: async ({ providerId }: DeleteAuthProviderArgs) => {
22
if (!organization) {
23
throw new Error("No current organization selected");
24
}
25
26
const response = await authProviderClient.deleteAuthProvider(
27
new DeleteAuthProviderRequest({
28
authProviderId: providerId,
29
}),
30
);
31
32
return response;
33
},
34
onSuccess: (_, { providerId }) => {
35
if (!organization) {
36
throw new Error("No current organization selected");
37
}
38
39
const queryKey = getOrgAuthProvidersQueryKey(organization.id);
40
queryClient.setQueryData<AuthProvider[]>(queryKey, (providers) => {
41
return providers?.filter((p) => p.id !== providerId);
42
});
43
44
queryClient.invalidateQueries({ queryKey });
45
},
46
});
47
};
48
49