Path: blob/main/components/dashboard/src/data/oidc-clients/delete-oidc-client-mutation.ts
2501 views
/**1* Copyright (c) 2023 Gitpod GmbH. All rights reserved.2* Licensed under the GNU Affero General Public License (AGPL).3* See License.AGPL.txt in the project root for license information.4*/56import { useMutation, useQueryClient } from "@tanstack/react-query";7import { oidcService } from "../../service/public-api";8import { useCurrentOrg } from "../organizations/orgs-query";9import { getOIDCClientsQueryKey, OIDCClientsQueryResults } from "./oidc-clients-query";1011type DeleteOIDCClientArgs = {12clientId: string;13};14export const useDeleteOIDCClientMutation = () => {15const queryClient = useQueryClient();16const organization = useCurrentOrg().data;1718return useMutation({19mutationFn: async ({ clientId }: DeleteOIDCClientArgs) => {20if (!organization) {21throw new Error("No current organization selected");22}2324return await oidcService.deleteClientConfig({25id: clientId,26organizationId: organization.id,27});28},29onSuccess: (_, { clientId }) => {30if (!organization) {31throw new Error("No current organization selected");32}3334const queryKey = getOIDCClientsQueryKey(organization.id);35// filter out deleted client immediately36queryClient.setQueryData<OIDCClientsQueryResults>(queryKey, (clients) => {37return clients?.filter((c) => c.id !== clientId);38});3940// then invalidate query41queryClient.invalidateQueries({ queryKey });42},43});44};454647