Use swagger api for AirGap Subnet Registration (#3206)

This commit is contained in:
Cesar N
2024-01-19 12:17:23 -08:00
committed by GitHub
parent a5175a35ec
commit abd66780f4

View File

@@ -35,7 +35,9 @@ import { modalStyleUtils } from "../Common/FormComponents/common/styleLibrary";
import TooltipWrapper from "../Common/TooltipWrapper/TooltipWrapper"; import TooltipWrapper from "../Common/TooltipWrapper/TooltipWrapper";
import CopyToClipboard from "react-copy-to-clipboard"; import CopyToClipboard from "react-copy-to-clipboard";
import RegisterHelpBox from "./RegisterHelpBox"; 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 OfflineRegistration = () => {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
@@ -52,21 +54,22 @@ const OfflineRegistration = () => {
const offlineRegUrl = `https://subnet.min.io/cluster/register?token=${subnetRegToken}`; const offlineRegUrl = `https://subnet.min.io/cluster/register?token=${subnetRegToken}`;
const [licenseKey, setLicenseKey] = useState(""); const [licenseKey, setLicenseKey] = useState("");
const [loadingSave, setLoadingSave] = useState<boolean>(false);
const [isSaving, invokeApplyLicenseApi] = useApi(
() => {
dispatch(fetchLicenseInfo());
dispatch(setServerNeedsRestart(true));
},
(err) => {
dispatch(setErrorSnackMessage(err));
},
);
const applyAirGapLicense = () => { const applyAirGapLicense = () => {
invokeApplyLicenseApi("PUT", `/api/v1/configs/subnet`, { setLoadingSave(true);
key_values: [{ key: "license", value: licenseKey }], api.configs
}); .setConfig("subnet", {
key_values: [{ key: "license", value: licenseKey }],
})
.then((_) => {
dispatch(fetchLicenseInfo());
dispatch(setServerNeedsRestart(true));
})
.catch(async (res: HttpResponse<SetConfigResponse, ApiError>) => {
dispatch(setErrorSnackMessage(errorToHandler(res.error)));
})
.finally(() => setLoadingSave(false));
}; };
return ( return (
@@ -159,7 +162,7 @@ const OfflineRegistration = () => {
</label> </label>
<CommentBox <CommentBox
value={licenseKey} value={licenseKey}
disabled={isSaving} disabled={loadingSave}
label={""} label={""}
id={"licenseKey"} id={"licenseKey"}
name={"licenseKey"} name={"licenseKey"}
@@ -174,7 +177,7 @@ const OfflineRegistration = () => {
id={"apply-license-key"} id={"apply-license-key"}
onClick={applyAirGapLicense} onClick={applyAirGapLicense}
variant={"callAction"} variant={"callAction"}
disabled={!licenseKey || isSaving} disabled={!licenseKey || loadingSave}
label={"Apply Cluster License"} label={"Apply Cluster License"}
/> />
</Box> </Box>