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/delete-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, OIDCClientsQueryResults } from "./oidc-clients-query";
11
12
type DeleteOIDCClientArgs = {
13
clientId: string;
14
};
15
export const useDeleteOIDCClientMutation = () => {
16
const queryClient = useQueryClient();
17
const organization = useCurrentOrg().data;
18
19
return useMutation({
20
mutationFn: async ({ clientId }: DeleteOIDCClientArgs) => {
21
if (!organization) {
22
throw new Error("No current organization selected");
23
}
24
25
return await oidcService.deleteClientConfig({
26
id: clientId,
27
organizationId: organization.id,
28
});
29
},
30
onSuccess: (_, { clientId }) => {
31
if (!organization) {
32
throw new Error("No current organization selected");
33
}
34
35
const queryKey = getOIDCClientsQueryKey(organization.id);
36
// filter out deleted client immediately
37
queryClient.setQueryData<OIDCClientsQueryResults>(queryKey, (clients) => {
38
return clients?.filter((c) => c.id !== clientId);
39
});
40
41
// then invalidate query
42
queryClient.invalidateQueries({ queryKey });
43
},
44
});
45
};
46
47