Path: blob/main/components/dashboard/src/data/maintenance-mode/maintenance-mode-mutation.ts
2501 views
/**1* Copyright (c) 2025 Gitpod GmbH. All rights reserved.2* Licensed under the GNU Affero General Public License (AGPL).3* See License.AGPL.txt in the project root for license information.4*/56import { useMutation, useQueryClient } from "@tanstack/react-query";7import { useCurrentOrg } from "../organizations/orgs-query";8import { organizationClient } from "../../service/public-api";9import { maintenanceModeQueryKey } from "./maintenance-mode-query";1011export interface SetMaintenanceModeArgs {12enabled: boolean;13}1415export const useSetMaintenanceModeMutation = () => {16const { data: org } = useCurrentOrg();17const queryClient = useQueryClient();18const organizationId = org?.id ?? "";1920return useMutation<boolean, Error, SetMaintenanceModeArgs>({21mutationFn: async ({ enabled }) => {22if (!organizationId) {23throw new Error("No organization selected");24}2526try {27const response = await organizationClient.setOrganizationMaintenanceMode({28organizationId,29enabled,30});31return response.enabled;32} catch (error) {33console.error("Failed to set maintenance mode", error);34throw error;35}36},37onSuccess: (result) => {38// Update the cache39queryClient.setQueryData(maintenanceModeQueryKey(organizationId), result);40},41});42};434445