Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/dashboard/src/data/oidc-clients/activate-oidc-client-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 { oidcService } from "../../service/public-api";
9
import { useCurrentOrg } from "../organizations/orgs-query";
10
import { getOIDCClientsQueryKey } from "./oidc-clients-query";
11
import { SetClientConfigActivationResponse } from "@gitpod/public-api/lib/gitpod/experimental/v1/oidc_pb";
12
13
type ActivateOIDCClientArgs = {
14
id: string;
15
};
16
export const useActivateOIDCClientMutation = () => {
17
const client = useQueryClient();
18
const { data: org } = useCurrentOrg();
19
20
return useMutation<SetClientConfigActivationResponse, Error, ActivateOIDCClientArgs>({
21
mutationFn: async ({ id }) => {
22
if (!org) {
23
throw new Error("No current organization selected");
24
}
25
26
return await oidcService.setClientConfigActivation({ id, organizationId: org.id, activate: true });
27
},
28
onSuccess: () => {
29
if (!org) {
30
return;
31
}
32
33
client.invalidateQueries(getOIDCClientsQueryKey(org.id));
34
},
35
});
36
};
37
38