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-notification-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
import { MaintenanceNotification } from "@gitpod/gitpod-protocol";
11
12
export const maintenanceNotificationQueryKey = (orgId: string) => ["maintenance-notification", orgId];
13
14
export const useMaintenanceNotification = () => {
15
const { data: org } = useCurrentOrg();
16
17
const { data, isLoading } = useQuery<MaintenanceNotification>(
18
maintenanceNotificationQueryKey(org?.id || ""),
19
async () => {
20
if (!org?.id) return { enabled: false };
21
22
try {
23
const response = await organizationClient.getMaintenanceNotification({
24
organizationId: org.id,
25
});
26
return {
27
enabled: response.isEnabled,
28
message: response.message,
29
};
30
} catch (error) {
31
console.error("Failed to fetch maintenance notification settings", error);
32
return { enabled: false };
33
}
34
},
35
{
36
enabled: !!org?.id,
37
staleTime: 30 * 1000, // 30 seconds
38
refetchInterval: 60 * 1000, // 1 minute
39
},
40
);
41
42
return {
43
isNotificationEnabled: data?.enabled || false,
44
notificationMessage: data?.message,
45
isLoading,
46
};
47
};
48
49