From abd66780f4c34b7bb8e0f729f6ed30cb4262a514 Mon Sep 17 00:00:00 2001 From: Cesar N <11819101+cesnietor@users.noreply.github.com> Date: Fri, 19 Jan 2024 12:17:23 -0800 Subject: [PATCH] Use swagger api for AirGap Subnet Registration (#3206) --- .../Console/Support/OfflineRegistration.tsx | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/web-app/src/screens/Console/Support/OfflineRegistration.tsx b/web-app/src/screens/Console/Support/OfflineRegistration.tsx index 134df12ae..f9ea4ec21 100644 --- a/web-app/src/screens/Console/Support/OfflineRegistration.tsx +++ b/web-app/src/screens/Console/Support/OfflineRegistration.tsx @@ -35,7 +35,9 @@ import { modalStyleUtils } from "../Common/FormComponents/common/styleLibrary"; import TooltipWrapper from "../Common/TooltipWrapper/TooltipWrapper"; import CopyToClipboard from "react-copy-to-clipboard"; import RegisterHelpBox from "./RegisterHelpBox"; -import useApi from "../Common/Hooks/useApi"; +import { api } from "api"; +import { ApiError, HttpResponse, SetConfigResponse } from "api/consoleApi"; +import { errorToHandler } from "api/errors"; const OfflineRegistration = () => { const dispatch = useAppDispatch(); @@ -52,21 +54,22 @@ const OfflineRegistration = () => { const offlineRegUrl = `https://subnet.min.io/cluster/register?token=${subnetRegToken}`; const [licenseKey, setLicenseKey] = useState(""); - - const [isSaving, invokeApplyLicenseApi] = useApi( - () => { - dispatch(fetchLicenseInfo()); - dispatch(setServerNeedsRestart(true)); - }, - (err) => { - dispatch(setErrorSnackMessage(err)); - }, - ); + const [loadingSave, setLoadingSave] = useState(false); const applyAirGapLicense = () => { - invokeApplyLicenseApi("PUT", `/api/v1/configs/subnet`, { - key_values: [{ key: "license", value: licenseKey }], - }); + setLoadingSave(true); + api.configs + .setConfig("subnet", { + key_values: [{ key: "license", value: licenseKey }], + }) + .then((_) => { + dispatch(fetchLicenseInfo()); + dispatch(setServerNeedsRestart(true)); + }) + .catch(async (res: HttpResponse) => { + dispatch(setErrorSnackMessage(errorToHandler(res.error))); + }) + .finally(() => setLoadingSave(false)); }; return ( @@ -159,7 +162,7 @@ const OfflineRegistration = () => { { id={"apply-license-key"} onClick={applyAirGapLicense} variant={"callAction"} - disabled={!licenseKey || isSaving} + disabled={!licenseKey || loadingSave} label={"Apply Cluster License"} />