Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/dashboard/src/data/organizations/org-settings-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 { useQuery, useQueryClient } from "@tanstack/react-query";
8
import { organizationClient } from "../../service/public-api";
9
import { OrganizationSettings } from "@gitpod/public-api/lib/gitpod/v1/organization_pb";
10
import { useCallback } from "react";
11
import { useCurrentOrg } from "./orgs-query";
12
13
export function useOrgSettingsQueryInvalidator() {
14
const organizationId = useCurrentOrg().data?.id;
15
const queryClient = useQueryClient();
16
return useCallback(() => {
17
queryClient.invalidateQueries(getQueryKey(organizationId));
18
}, [organizationId, queryClient]);
19
}
20
21
export function useOrgSettingsQuery() {
22
const organizationId = useCurrentOrg().data?.id;
23
return useQuery<OrganizationSettings | null, Error, OrganizationSettings | undefined>(
24
getQueryKey(organizationId),
25
async () => {
26
if (!organizationId) {
27
return null;
28
}
29
30
const settings = await organizationClient.getOrganizationSettings({ organizationId });
31
return settings.settings || new OrganizationSettings();
32
},
33
{
34
select: (data) => data || undefined,
35
},
36
);
37
}
38
39
export function getQueryKey(organizationId?: string) {
40
return ["getOrganizationSettings", organizationId || "undefined"];
41
}
42
43