Skip to content

Commit abd6678

Browse files
authored
Use swagger api for AirGap Subnet Registration (#3206)
1 parent a5175a3 commit abd6678

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

web-app/src/screens/Console/Support/OfflineRegistration.tsx

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ import { modalStyleUtils } from "../Common/FormComponents/common/styleLibrary";
3535
import TooltipWrapper from "../Common/TooltipWrapper/TooltipWrapper";
3636
import CopyToClipboard from "react-copy-to-clipboard";
3737
import RegisterHelpBox from "./RegisterHelpBox";
38-
import useApi from "../Common/Hooks/useApi";
38+
import { api } from "api";
39+
import { ApiError, HttpResponse, SetConfigResponse } from "api/consoleApi";
40+
import { errorToHandler } from "api/errors";
3941

4042
const OfflineRegistration = () => {
4143
const dispatch = useAppDispatch();
@@ -52,21 +54,22 @@ const OfflineRegistration = () => {
5254
const offlineRegUrl = `https://subnet.min.io/cluster/register?token=${subnetRegToken}`;
5355

5456
const [licenseKey, setLicenseKey] = useState("");
55-
56-
const [isSaving, invokeApplyLicenseApi] = useApi(
57-
() => {
58-
dispatch(fetchLicenseInfo());
59-
dispatch(setServerNeedsRestart(true));
60-
},
61-
(err) => {
62-
dispatch(setErrorSnackMessage(err));
63-
},
64-
);
57+
const [loadingSave, setLoadingSave] = useState<boolean>(false);
6558

6659
const applyAirGapLicense = () => {
67-
invokeApplyLicenseApi("PUT", `/api/v1/configs/subnet`, {
68-
key_values: [{ key: "license", value: licenseKey }],
69-
});
60+
setLoadingSave(true);
61+
api.configs
62+
.setConfig("subnet", {
63+
key_values: [{ key: "license", value: licenseKey }],
64+
})
65+
.then((_) => {
66+
dispatch(fetchLicenseInfo());
67+
dispatch(setServerNeedsRestart(true));
68+
})
69+
.catch(async (res: HttpResponse<SetConfigResponse, ApiError>) => {
70+
dispatch(setErrorSnackMessage(errorToHandler(res.error)));
71+
})
72+
.finally(() => setLoadingSave(false));
7073
};
7174

7275
return (
@@ -159,7 +162,7 @@ const OfflineRegistration = () => {
159162
</label>
160163
<CommentBox
161164
value={licenseKey}
162-
disabled={isSaving}
165+
disabled={loadingSave}
163166
label={""}
164167
id={"licenseKey"}
165168
name={"licenseKey"}
@@ -174,7 +177,7 @@ const OfflineRegistration = () => {
174177
id={"apply-license-key"}
175178
onClick={applyAirGapLicense}
176179
variant={"callAction"}
177-
disabled={!licenseKey || isSaving}
180+
disabled={!licenseKey || loadingSave}
178181
label={"Apply Cluster License"}
179182
/>
180183
</Box>

0 commit comments

Comments
 (0)