From 24fdf3487bfaed2a36925786f3a734fff6051476 Mon Sep 17 00:00:00 2001 From: Daniel Valdivia <18384552+dvaldivia@users.noreply.github.com> Date: Mon, 6 Feb 2023 13:51:39 -0800 Subject: [PATCH] Move Register Component to Redux (#2630) Signed-off-by: Daniel Valdivia <18384552+dvaldivia@users.noreply.github.com> --- .../Console/Support/ApiKeyRegister.tsx | 16 +- .../Support/ClusterRegistrationForm.tsx | 116 +++ .../Console/Support/OfflineRegistration.tsx | 159 +++++ .../Console/Support/OnlineRegistration.tsx | 190 +++++ .../src/screens/Console/Support/Register.tsx | 665 ++---------------- .../Console/Support/RegisterOperator.tsx | 5 +- .../Console/Support/RegisterStatus.tsx | 5 +- .../Console/Support/SubnetMFAToken.tsx | 110 +++ .../screens/Console/Support/registerSlice.ts | 132 ++++ .../screens/Console/Support/registerThunks.ts | 211 ++++++ .../src/screens/Console/Support/utils.tsx | 7 +- portal-ui/src/store.ts | 2 + restapi/admin_subnet.go | 39 +- 13 files changed, 1042 insertions(+), 615 deletions(-) create mode 100644 portal-ui/src/screens/Console/Support/ClusterRegistrationForm.tsx create mode 100644 portal-ui/src/screens/Console/Support/OfflineRegistration.tsx create mode 100644 portal-ui/src/screens/Console/Support/OnlineRegistration.tsx create mode 100644 portal-ui/src/screens/Console/Support/SubnetMFAToken.tsx create mode 100644 portal-ui/src/screens/Console/Support/registerSlice.ts create mode 100644 portal-ui/src/screens/Console/Support/registerThunks.ts diff --git a/portal-ui/src/screens/Console/Support/ApiKeyRegister.tsx b/portal-ui/src/screens/Console/Support/ApiKeyRegister.tsx index 043d2558f..fbbb0d313 100644 --- a/portal-ui/src/screens/Console/Support/ApiKeyRegister.tsx +++ b/portal-ui/src/screens/Console/Support/ApiKeyRegister.tsx @@ -30,11 +30,12 @@ import { spacingUtils } from "../Common/FormComponents/common/styleLibrary"; import { Theme } from "@mui/material/styles"; import createStyles from "@mui/styles/createStyles"; import withStyles from "@mui/styles/withStyles"; +import { useNavigate } from "react-router-dom"; +import { IAM_PAGES } from "../../../common/SecureComponent/permissions"; interface IApiKeyRegister { classes: any; registerEndpoint: string; - afterRegister: () => void; } const styles = (theme: Theme) => @@ -45,11 +46,9 @@ const styles = (theme: Theme) => ...spacingUtils, }); -const ApiKeyRegister = ({ - classes, - registerEndpoint, - afterRegister, -}: IApiKeyRegister) => { +const ApiKeyRegister = ({ classes, registerEndpoint }: IApiKeyRegister) => { + const navigate = useNavigate(); + const [showApiKeyModal, setShowApiKeyModal] = useState(false); const [apiKey, setApiKey] = useState(""); const [loading, setLoading] = useState(false); @@ -67,8 +66,7 @@ const ApiKeyRegister = ({ .then((resp: SubnetLoginResponse) => { setLoading(false); if (resp && resp.registered) { - reset(); - afterRegister(); + navigate(IAM_PAGES.LICENSE); } }) .catch((err: ErrorResponseHandler) => { @@ -76,7 +74,7 @@ const ApiKeyRegister = ({ setLoading(false); reset(); }); - }, [afterRegister, apiKey, dispatch, loading, registerEndpoint]); + }, [apiKey, dispatch, loading, registerEndpoint, navigate]); useEffect(() => { if (fromModal) { diff --git a/portal-ui/src/screens/Console/Support/ClusterRegistrationForm.tsx b/portal-ui/src/screens/Console/Support/ClusterRegistrationForm.tsx new file mode 100644 index 000000000..d9f420738 --- /dev/null +++ b/portal-ui/src/screens/Console/Support/ClusterRegistrationForm.tsx @@ -0,0 +1,116 @@ +// This file is part of MinIO Console Server +// Copyright (c) 2023 MinIO, Inc. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +import React from "react"; +import { Box } from "@mui/material"; +import { FormTitle } from "./utils"; +import SelectWrapper from "../Common/FormComponents/SelectWrapper/SelectWrapper"; +import { setLoading, setSelectedSubnetOrganization } from "./registerSlice"; +import { Button } from "mds"; +import RegisterHelpBox from "./RegisterHelpBox"; +import { useSelector } from "react-redux"; +import { AppState, useAppDispatch } from "../../../store"; +import { callRegister } from "./registerThunks"; + +const ClusterRegistrationForm = () => { + const dispatch = useAppDispatch(); + + const subnetAccessToken = useSelector( + (state: AppState) => state.register.subnetAccessToken + ); + const selectedSubnetOrganization = useSelector( + (state: AppState) => state.register.selectedSubnetOrganization + ); + const subnetOrganizations = useSelector( + (state: AppState) => state.register.subnetOrganizations + ); + const loading = useSelector((state: AppState) => state.register.loading); + + return ( + + + + + + + + dispatch(setSelectedSubnetOrganization(e.target.value as string)) + } + label="Select an organization" + value={selectedSubnetOrganization} + options={subnetOrganizations.map((organization) => ({ + label: organization.company, + value: organization.accountId.toString(), + }))} + /> + +