Path: blob/main/components/dashboard/src/data/oidc-clients/upsert-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 { getOIDCClientsQueryKey } from "./oidc-clients-query";9import {10CreateClientConfigResponse,11UpdateClientConfigResponse,12} from "@gitpod/public-api/lib/gitpod/experimental/v1/oidc_pb";1314// TODO: find a better way to type this against the API15type UpsertOIDCClientMutationArgs =16| Parameters<typeof oidcService.updateClientConfig>[0]17| Parameters<typeof oidcService.createClientConfig>[0];1819export const useUpsertOIDCClientMutation = () => {20const queryClient = useQueryClient();2122return useMutation<CreateClientConfigResponse | UpdateClientConfigResponse, Error, UpsertOIDCClientMutationArgs>({23mutationFn: async ({ config = {} }: UpsertOIDCClientMutationArgs) => {24if ("id" in config) {25return await oidcService.updateClientConfig({26config,27});28} else {29return await oidcService.createClientConfig({30config,31});32}33},34onSuccess(resp, { config = {} }) {35if (!config || !config.organizationId) {36return;37}3839queryClient.invalidateQueries({ queryKey: getOIDCClientsQueryKey(config.organizationId || "") });40},41});42};434445