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-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 { maintenanceModeQueryKey } from "./maintenance-mode-query";
11
12
export interface SetMaintenanceModeArgs {
13
enabled: boolean;
14
}
15
16
export const useSetMaintenanceModeMutation = () => {
17
const { data: org } = useCurrentOrg();
18
const queryClient = useQueryClient();
19
const organizationId = org?.id ?? "";
20
21
return useMutation<boolean, Error, SetMaintenanceModeArgs>({
22
mutationFn: async ({ enabled }) => {
23
if (!organizationId) {
24
throw new Error("No organization selected");
25
}
26
27
try {
28
const response = await organizationClient.setOrganizationMaintenanceMode({
29
organizationId,
30
enabled,
31
});
32
return response.enabled;
33
} catch (error) {
34
console.error("Failed to set maintenance mode", error);
35
throw error;
36
}
37
},
38
onSuccess: (result) => {
39
// Update the cache
40
queryClient.setQueryData(maintenanceModeQueryKey(organizationId), result);
41
},
42
});
43
};
44
45