Path: blob/main/components/dashboard/src/data/auth-providers/org-auth-providers-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 { useQuery, useQueryClient } from "@tanstack/react-query";7import { useCallback } from "react";8import { useCurrentOrg } from "../organizations/orgs-query";9import { authProviderClient } from "../../service/public-api";10import { AuthProvider, ListAuthProvidersRequest } from "@gitpod/public-api/lib/gitpod/v1/authprovider_pb";1112export const useOrgAuthProvidersQuery = () => {13const organization = useCurrentOrg().data;1415return useQuery<AuthProvider[]>({16queryKey: getOrgAuthProvidersQueryKey(organization?.id ?? ""),17queryFn: async () => {18if (!organization) {19throw new Error("No current organization selected");20}2122const response = await authProviderClient.listAuthProviders(23new ListAuthProvidersRequest({24id: {25case: "organizationId",26value: organization.id,27},28}),29);3031return response.authProviders;32},33});34};3536export const useInvalidateOrgAuthProvidersQuery = (organizationId: string) => {37const queryClient = useQueryClient();3839return useCallback(() => {40queryClient.invalidateQueries({ queryKey: getOrgAuthProvidersQueryKey(organizationId) });41}, [organizationId, queryClient]);42};4344export const getOrgAuthProvidersQueryKey = (organizationId: string) => ["org-auth-providers", { organizationId }];454647