@@ -35,7 +35,9 @@ import { modalStyleUtils } from "../Common/FormComponents/common/styleLibrary";
35
35
import TooltipWrapper from "../Common/TooltipWrapper/TooltipWrapper" ;
36
36
import CopyToClipboard from "react-copy-to-clipboard" ;
37
37
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" ;
39
41
40
42
const OfflineRegistration = ( ) => {
41
43
const dispatch = useAppDispatch ( ) ;
@@ -52,21 +54,22 @@ const OfflineRegistration = () => {
52
54
const offlineRegUrl = `https://subnet.min.io/cluster/register?token=${ subnetRegToken } ` ;
53
55
54
56
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 ) ;
65
58
66
59
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 ) ) ;
70
73
} ;
71
74
72
75
return (
@@ -159,7 +162,7 @@ const OfflineRegistration = () => {
159
162
</ label >
160
163
< CommentBox
161
164
value = { licenseKey }
162
- disabled = { isSaving }
165
+ disabled = { loadingSave }
163
166
label = { "" }
164
167
id = { "licenseKey" }
165
168
name = { "licenseKey" }
@@ -174,7 +177,7 @@ const OfflineRegistration = () => {
174
177
id = { "apply-license-key" }
175
178
onClick = { applyAirGapLicense }
176
179
variant = { "callAction" }
177
- disabled = { ! licenseKey || isSaving }
180
+ disabled = { ! licenseKey || loadingSave }
178
181
label = { "Apply Cluster License" }
179
182
/>
180
183
</ Box >
0 commit comments