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-mutation.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 { useMutation, useQueryClient } 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
import { maintenanceNotificationQueryKey } from "./maintenance-notification-query";
12
13
export interface SetMaintenanceNotificationArgs {
14
isEnabled: boolean;
15
customMessage?: string;
16
}
17
18
export const useSetMaintenanceNotificationMutation = () => {
19
const { data: org } = useCurrentOrg();
20
const queryClient = useQueryClient();
21
const organizationId = org?.id ?? "";
22
23
return useMutation<MaintenanceNotification, Error, SetMaintenanceNotificationArgs>({
24
mutationFn: async ({ isEnabled, customMessage }) => {
25
if (!organizationId) {
26
throw new Error("No organization selected");
27
}
28
29
try {
30
const response = await organizationClient.setMaintenanceNotification({
31
organizationId,
32
isEnabled,
33
customMessage,
34
});
35
36
const result: MaintenanceNotification = {
37
enabled: response.isEnabled,
38
message: response.message,
39
};
40
41
return result;
42
} catch (error) {
43
console.error("Failed to set maintenance notification", error);
44
throw error;
45
}
46
},
47
onSuccess: (result) => {
48
// Update the cache
49
queryClient.setQueryData(maintenanceNotificationQueryKey(organizationId), result);
50
},
51
});
52
};
53
54