Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/dashboard/src/data/maintenance-mode/maintenance-mode-query.ts
2501 views
1
/**
2
* Copyright (c) 2025 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 } from "@tanstack/react-query";
8
import { useCurrentOrg } from "../organizations/orgs-query";
9
import { organizationClient } from "../../service/public-api";
10
11
export const maintenanceModeQueryKey = (orgId: string) => ["maintenance-mode", orgId];
12
13
export const useMaintenanceMode = () => {
14
const { data: org } = useCurrentOrg();
15
16
const { data: isMaintenanceMode = false, isLoading } = useQuery(
17
maintenanceModeQueryKey(org?.id || ""),
18
async () => {
19
if (!org?.id) return false;
20
21
try {
22
const response = await organizationClient.getOrganizationMaintenanceMode({
23
organizationId: org.id,
24
});
25
return response.enabled;
26
} catch (error) {
27
console.error("Failed to fetch maintenance mode status", error);
28
return false;
29
}
30
},
31
{
32
enabled: !!org?.id,
33
staleTime: 30 * 1000, // 30 seconds
34
refetchInterval: 60 * 1000, // 1 minute
35
},
36
);
37
38
return {
39
isMaintenanceMode,
40
isLoading,
41
};
42
};
43
44