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/oidc-clients-query.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 { OIDCClientConfig } from "@gitpod/public-api/lib/gitpod/experimental/v1/oidc_pb";
8
import { useQuery, useQueryClient } from "@tanstack/react-query";
9
import { oidcService } from "../../service/public-api";
10
import { useCurrentOrg } from "../organizations/orgs-query";
11
import { useCallback } from "react";
12
13
export type OIDCClientsQueryResults = OIDCClientConfig[];
14
15
export const useOIDCClientsQuery = () => {
16
const { data: organization, isLoading } = useCurrentOrg();
17
18
return useQuery<OIDCClientsQueryResults>({
19
queryKey: getOIDCClientsQueryKey(organization?.id ?? ""),
20
queryFn: async () => {
21
if (!organization) {
22
throw new Error("No current organization selected");
23
}
24
25
const { clientConfigs } = await oidcService.listClientConfigs({ organizationId: organization.id });
26
27
return clientConfigs;
28
},
29
enabled: !isLoading && !!organization,
30
});
31
};
32
33
export const useInvalidateOIDCClientsQuery = () => {
34
const client = useQueryClient();
35
const { data: organization } = useCurrentOrg();
36
37
return useCallback(() => {
38
if (!organization) {
39
throw new Error("No current organization selected");
40
}
41
42
client.invalidateQueries(getOIDCClientsQueryKey(organization.id));
43
}, [client, organization]);
44
};
45
46
export const getOIDCClientsQueryKey = (organizationId: string) => ["oidc-clients", { organizationId }];
47
48