github.com/minio/console@v1.4.1/web-app/src/screens/Console/License/License.tsx (about) 1 // This file is part of MinIO Console Server 2 // Copyright (c) 2021 MinIO, Inc. 3 // 4 // This program is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Affero General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // This program is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Affero General Public License for more details. 13 // 14 // You should have received a copy of the GNU Affero General Public License 15 // along with this program. If not, see <http://www.gnu.org/licenses/>. 16 17 import React, { Fragment, useCallback, useEffect, useState } from "react"; 18 import { ArrowIcon, Button, PageLayout, ProgressBar, Grid } from "mds"; 19 import { SubnetInfo } from "./types"; 20 import api from "../../../common/api"; 21 import { IAM_PAGES } from "../../../common/SecureComponent/permissions"; 22 import LicensePlans from "./LicensePlans"; 23 import { useNavigate } from "react-router-dom"; 24 import RegistrationStatusBanner from "../Support/RegistrationStatusBanner"; 25 import withSuspense from "../Common/Components/withSuspense"; 26 import { getLicenseConsent } from "./utils"; 27 import PageHeaderWrapper from "../Common/PageHeaderWrapper/PageHeaderWrapper"; 28 import HelpMenu from "../HelpMenu"; 29 import { setHelpName } from "../../../systemSlice"; 30 import { useAppDispatch } from "../../../store"; 31 32 const LicenseConsentModal = withSuspense( 33 React.lazy(() => import("./LicenseConsentModal")), 34 ); 35 36 const License = () => { 37 const navigate = useNavigate(); 38 const [activateProductModal, setActivateProductModal] = 39 useState<boolean>(false); 40 41 const [licenseInfo, setLicenseInfo] = useState<SubnetInfo>(); 42 const [currentPlanID, setCurrentPlanID] = useState<number>(0); 43 const [loadingLicenseInfo, setLoadingLicenseInfo] = useState<boolean>(false); 44 const [initialLicenseLoading, setInitialLicenseLoading] = 45 useState<boolean>(true); 46 useState<boolean>(false); 47 const [clusterRegistered, setClusterRegistered] = useState<boolean>(false); 48 49 const [isLicenseConsentOpen, setIsLicenseConsentOpen] = 50 useState<boolean>(false); 51 52 const closeModalAndFetchLicenseInfo = () => { 53 setActivateProductModal(false); 54 fetchLicenseInfo(); 55 }; 56 57 const dispatch = useAppDispatch(); 58 useEffect(() => { 59 dispatch(setHelpName("license")); 60 // eslint-disable-next-line react-hooks/exhaustive-deps 61 }, []); 62 63 const isRegistered = licenseInfo && clusterRegistered; 64 65 const isAgplConsentDone = getLicenseConsent(); 66 67 useEffect(() => { 68 const shouldConsent = 69 !isRegistered && !isAgplConsentDone && !initialLicenseLoading; 70 71 if (shouldConsent && !loadingLicenseInfo) { 72 setIsLicenseConsentOpen(true); 73 } 74 }, [ 75 isRegistered, 76 isAgplConsentDone, 77 initialLicenseLoading, 78 loadingLicenseInfo, 79 ]); 80 81 const fetchLicenseInfo = useCallback(() => { 82 if (loadingLicenseInfo) { 83 return; 84 } 85 setLoadingLicenseInfo(true); 86 api 87 .invoke("GET", `/api/v1/subnet/info`) 88 .then((res: SubnetInfo) => { 89 if (res) { 90 if (res.plan === "STANDARD") { 91 setCurrentPlanID(1); 92 } else if (res.plan === "ENTERPRISE") { 93 setCurrentPlanID(2); 94 } else { 95 setCurrentPlanID(1); 96 } 97 setLicenseInfo(res); 98 } 99 setClusterRegistered(true); 100 setLoadingLicenseInfo(false); 101 }) 102 .catch(() => { 103 setClusterRegistered(false); 104 setLoadingLicenseInfo(false); 105 }); 106 }, [loadingLicenseInfo]); 107 108 useEffect(() => { 109 if (initialLicenseLoading) { 110 fetchLicenseInfo(); 111 setInitialLicenseLoading(false); 112 } 113 }, [fetchLicenseInfo, initialLicenseLoading, setInitialLicenseLoading]); 114 115 if (loadingLicenseInfo) { 116 return ( 117 <Grid item xs={12}> 118 <ProgressBar /> 119 </Grid> 120 ); 121 } 122 123 return ( 124 <Fragment> 125 <PageHeaderWrapper 126 label="MinIO License and Support plans" 127 actions={ 128 <Fragment> 129 {!isRegistered && ( 130 <Button 131 id={"login-with-subnet"} 132 onClick={() => navigate(IAM_PAGES.REGISTER_SUPPORT)} 133 style={{ 134 fontSize: "14px", 135 display: "flex", 136 alignItems: "center", 137 textDecoration: "none", 138 }} 139 icon={<ArrowIcon />} 140 variant={"callAction"} 141 > 142 Register your cluster 143 </Button> 144 )} 145 <HelpMenu /> 146 </Fragment> 147 } 148 /> 149 150 <PageLayout> 151 <Grid item xs={12}> 152 {isRegistered && ( 153 <RegistrationStatusBanner email={licenseInfo?.email} /> 154 )} 155 </Grid> 156 157 <LicensePlans 158 activateProductModal={activateProductModal} 159 closeModalAndFetchLicenseInfo={closeModalAndFetchLicenseInfo} 160 licenseInfo={licenseInfo} 161 currentPlanID={currentPlanID} 162 setActivateProductModal={setActivateProductModal} 163 /> 164 165 <LicenseConsentModal 166 isOpen={isLicenseConsentOpen} 167 onClose={() => { 168 setIsLicenseConsentOpen(false); 169 }} 170 /> 171 </PageLayout> 172 </Fragment> 173 ); 174 }; 175 176 export default License;