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/update-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 { getOrgAuthProvidersQueryKey } from "./org-auth-providers-query";
9
import { UpdateAuthProviderRequest } from "@gitpod/public-api/lib/gitpod/v1/authprovider_pb";
10
import { authProviderClient } from "../../service/public-api";
11
12
type UpdateAuthProviderArgs = {
13
provider: {
14
id: string;
15
clientId: string;
16
clientSecret: string;
17
authorizationUrl?: string;
18
tokenUrl?: string;
19
};
20
};
21
export const useUpdateOrgAuthProviderMutation = () => {
22
const queryClient = useQueryClient();
23
24
return useMutation({
25
mutationFn: async ({ provider }: UpdateAuthProviderArgs) => {
26
const response = await authProviderClient.updateAuthProvider(
27
new UpdateAuthProviderRequest({
28
authProviderId: provider.id,
29
clientId: provider.clientId,
30
clientSecret: provider.clientSecret,
31
authorizationUrl: provider.authorizationUrl,
32
tokenUrl: provider.tokenUrl,
33
}),
34
);
35
return response.authProvider!;
36
},
37
onSuccess(provider) {
38
const orgId = provider?.owner?.value;
39
if (!orgId) {
40
return;
41
}
42
43
queryClient.invalidateQueries({ queryKey: getOrgAuthProvidersQueryKey(orgId) });
44
},
45
});
46
};
47
48