Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/dashboard/src/data/billing-mode/org-billing-mode-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 { BillingMode } from "@gitpod/gitpod-protocol/lib/billing-mode";
8
import { useQuery } from "@tanstack/react-query";
9
import { getGitpodService } from "../../service/service";
10
import { useCurrentOrg } from "../organizations/orgs-query";
11
12
type OrgBillingModeQueryResult = BillingMode;
13
14
export const useOrgBillingMode = () => {
15
const organization = useCurrentOrg().data;
16
17
return useQuery<OrgBillingModeQueryResult>({
18
queryKey: getOrgBillingModeQueryKey(organization?.id ?? ""),
19
queryFn: async () => {
20
if (!organization) {
21
throw new Error("No current organization selected");
22
}
23
return await getGitpodService().server.getBillingModeForTeam(organization.id);
24
},
25
enabled: !!organization,
26
});
27
};
28
29
export const getOrgBillingModeQueryKey = (organizationId: string) => ["billing-mode", { organizationId }];
30
31