Path: blob/main/components/dashboard/src/data/oidc-clients/oidc-clients-query.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 { OIDCClientConfig } from "@gitpod/public-api/lib/gitpod/experimental/v1/oidc_pb";7import { useQuery, useQueryClient } from "@tanstack/react-query";8import { oidcService } from "../../service/public-api";9import { useCurrentOrg } from "../organizations/orgs-query";10import { useCallback } from "react";1112export type OIDCClientsQueryResults = OIDCClientConfig[];1314export const useOIDCClientsQuery = () => {15const { data: organization, isLoading } = useCurrentOrg();1617return useQuery<OIDCClientsQueryResults>({18queryKey: getOIDCClientsQueryKey(organization?.id ?? ""),19queryFn: async () => {20if (!organization) {21throw new Error("No current organization selected");22}2324const { clientConfigs } = await oidcService.listClientConfigs({ organizationId: organization.id });2526return clientConfigs;27},28enabled: !isLoading && !!organization,29});30};3132export const useInvalidateOIDCClientsQuery = () => {33const client = useQueryClient();34const { data: organization } = useCurrentOrg();3536return useCallback(() => {37if (!organization) {38throw new Error("No current organization selected");39}4041client.invalidateQueries(getOIDCClientsQueryKey(organization.id));42}, [client, organization]);43};4445export const getOIDCClientsQueryKey = (organizationId: string) => ["oidc-clients", { organizationId }];464748