|
| 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, { useEffect, useState } from "react"; |
| 18 | +import { createStyles, Theme, withStyles } from "@material-ui/core/styles"; |
| 19 | +import Grid from "@material-ui/core/Grid"; |
| 20 | +import { containerForHeader } from "../../Common/FormComponents/common/styleLibrary"; |
| 21 | +import { Button, Typography } from "@material-ui/core"; |
| 22 | +import { niceBytes } from "../../../../common/utils"; |
| 23 | +import Moment from "react-moment"; |
| 24 | +import { Link } from "react-router-dom"; |
| 25 | +import Paper from "@material-ui/core/Paper"; |
| 26 | +import { ITenant } from "../ListTenants/types"; |
| 27 | +import { LicenseInfo } from "../../License/types"; |
| 28 | +import api from "../../../../common/api"; |
| 29 | + |
| 30 | +interface ISubnetLicenseTenant { |
| 31 | + classes: any; |
| 32 | + tenant: ITenant | null; |
| 33 | + loadingActivateProduct: any; |
| 34 | + loadingLicenseInfo: boolean; |
| 35 | + licenseInfo: LicenseInfo | undefined; |
| 36 | + activateProduct: any; |
| 37 | +} |
| 38 | + |
| 39 | +const styles = (theme: Theme) => |
| 40 | + createStyles({ |
| 41 | + paperContainer: { |
| 42 | + padding: "15px 15px 15px 50px", |
| 43 | + }, |
| 44 | + licenseInfoValue: { |
| 45 | + textTransform: "none", |
| 46 | + fontSize: 14, |
| 47 | + fontWeight: "bold", |
| 48 | + }, |
| 49 | + licenseContainer: { |
| 50 | + position: "relative", |
| 51 | + padding: "20px 52px 0px 28px", |
| 52 | + background: "#032F51", |
| 53 | + boxShadow: "0px 3px 7px #00000014", |
| 54 | + "& h2": { |
| 55 | + color: "#FFF", |
| 56 | + marginBottom: 67, |
| 57 | + }, |
| 58 | + "& a": { |
| 59 | + textDecoration: "none", |
| 60 | + }, |
| 61 | + "& h3": { |
| 62 | + color: "#FFFFFF", |
| 63 | + marginBottom: "30px", |
| 64 | + fontWeight: "bold", |
| 65 | + }, |
| 66 | + "& h6": { |
| 67 | + color: "#FFFFFF !important", |
| 68 | + }, |
| 69 | + }, |
| 70 | + licenseInfo: { color: "#FFFFFF", position: "relative" }, |
| 71 | + licenseInfoTitle: { |
| 72 | + textTransform: "none", |
| 73 | + color: "#BFBFBF", |
| 74 | + fontSize: 11, |
| 75 | + }, |
| 76 | + verifiedIcon: { |
| 77 | + width: 96, |
| 78 | + position: "absolute", |
| 79 | + right: 0, |
| 80 | + bottom: 29, |
| 81 | + }, |
| 82 | + noUnderLine: { |
| 83 | + textDecoration: "none", |
| 84 | + }, |
| 85 | + ...containerForHeader(theme.spacing(4)), |
| 86 | + }); |
| 87 | + |
| 88 | +const SubnetLicenseTenant = ({ |
| 89 | + classes, |
| 90 | + tenant, |
| 91 | + loadingActivateProduct, |
| 92 | + loadingLicenseInfo, |
| 93 | + licenseInfo, |
| 94 | + activateProduct, |
| 95 | +}: ISubnetLicenseTenant) => { |
| 96 | + return ( |
| 97 | + <Paper |
| 98 | + className={ |
| 99 | + tenant && tenant.subnet_license ? classes.licenseContainer : "" |
| 100 | + } |
| 101 | + > |
| 102 | + {tenant && tenant.subnet_license ? ( |
| 103 | + <React.Fragment> |
| 104 | + <Grid container className={classes.licenseInfo}> |
| 105 | + <Grid item xs={6}> |
| 106 | + <Typography |
| 107 | + variant="button" |
| 108 | + display="block" |
| 109 | + gutterBottom |
| 110 | + className={classes.licenseInfoTitle} |
| 111 | + > |
| 112 | + License |
| 113 | + </Typography> |
| 114 | + <Typography |
| 115 | + variant="overline" |
| 116 | + display="block" |
| 117 | + gutterBottom |
| 118 | + className={classes.licenseInfoValue} |
| 119 | + > |
| 120 | + Commercial License |
| 121 | + </Typography> |
| 122 | + <Typography |
| 123 | + variant="button" |
| 124 | + display="block" |
| 125 | + gutterBottom |
| 126 | + className={classes.licenseInfoTitle} |
| 127 | + > |
| 128 | + Organization |
| 129 | + </Typography> |
| 130 | + <Typography |
| 131 | + variant="overline" |
| 132 | + display="block" |
| 133 | + gutterBottom |
| 134 | + className={classes.licenseInfoValue} |
| 135 | + > |
| 136 | + {tenant.subnet_license.organization} |
| 137 | + </Typography> |
| 138 | + <Typography |
| 139 | + variant="button" |
| 140 | + display="block" |
| 141 | + gutterBottom |
| 142 | + className={classes.licenseInfoTitle} |
| 143 | + > |
| 144 | + Registered Capacity |
| 145 | + </Typography> |
| 146 | + <Typography |
| 147 | + variant="overline" |
| 148 | + display="block" |
| 149 | + gutterBottom |
| 150 | + className={classes.licenseInfoValue} |
| 151 | + > |
| 152 | + {niceBytes( |
| 153 | + (tenant.subnet_license.storage_capacity * 1099511627776) // 1 Terabyte = 1099511627776 Bytes |
| 154 | + .toString(10) |
| 155 | + )} |
| 156 | + </Typography> |
| 157 | + <Typography |
| 158 | + variant="button" |
| 159 | + display="block" |
| 160 | + gutterBottom |
| 161 | + className={classes.licenseInfoTitle} |
| 162 | + > |
| 163 | + Expiry Date |
| 164 | + </Typography> |
| 165 | + <Typography |
| 166 | + variant="overline" |
| 167 | + display="block" |
| 168 | + gutterBottom |
| 169 | + className={classes.licenseInfoValue} |
| 170 | + > |
| 171 | + <Moment format="YYYY-MM-DD"> |
| 172 | + {tenant.subnet_license.expires_at} |
| 173 | + </Moment> |
| 174 | + </Typography> |
| 175 | + </Grid> |
| 176 | + <Grid item xs={6}> |
| 177 | + <Typography |
| 178 | + variant="button" |
| 179 | + display="block" |
| 180 | + gutterBottom |
| 181 | + className={classes.licenseInfoTitle} |
| 182 | + > |
| 183 | + Subscription Plan |
| 184 | + </Typography> |
| 185 | + <Typography |
| 186 | + variant="overline" |
| 187 | + display="block" |
| 188 | + gutterBottom |
| 189 | + className={classes.licenseInfoValue} |
| 190 | + > |
| 191 | + {tenant.subnet_license.plan} |
| 192 | + </Typography> |
| 193 | + <Typography |
| 194 | + variant="button" |
| 195 | + display="block" |
| 196 | + gutterBottom |
| 197 | + className={classes.licenseInfoTitle} |
| 198 | + > |
| 199 | + Requester |
| 200 | + </Typography> |
| 201 | + <Typography |
| 202 | + variant="overline" |
| 203 | + display="block" |
| 204 | + gutterBottom |
| 205 | + className={classes.licenseInfoValue} |
| 206 | + > |
| 207 | + {tenant.subnet_license.email} |
| 208 | + </Typography> |
| 209 | + </Grid> |
| 210 | + <img |
| 211 | + className={classes.verifiedIcon} |
| 212 | + src={"/verified.svg"} |
| 213 | + alt="verified" |
| 214 | + /> |
| 215 | + </Grid> |
| 216 | + </React.Fragment> |
| 217 | + ) : ( |
| 218 | + !loadingLicenseInfo && ( |
| 219 | + <Grid className={classes.paperContainer}> |
| 220 | + {!licenseInfo && ( |
| 221 | + <Link |
| 222 | + to={"/license"} |
| 223 | + onClick={(e) => { |
| 224 | + e.stopPropagation(); |
| 225 | + }} |
| 226 | + className={classes.noUnderLine} |
| 227 | + > |
| 228 | + <Button |
| 229 | + className={classes.licenseButton} |
| 230 | + variant="contained" |
| 231 | + color="primary" |
| 232 | + > |
| 233 | + Activate Product |
| 234 | + </Button> |
| 235 | + </Link> |
| 236 | + )} |
| 237 | + {licenseInfo && tenant && ( |
| 238 | + <Button |
| 239 | + disabled={loadingActivateProduct} |
| 240 | + className={classes.licenseButton} |
| 241 | + variant="contained" |
| 242 | + color="primary" |
| 243 | + onClick={() => activateProduct(tenant.namespace, tenant.name)} |
| 244 | + > |
| 245 | + Attach License |
| 246 | + </Button> |
| 247 | + )} |
| 248 | + </Grid> |
| 249 | + ) |
| 250 | + )} |
| 251 | + </Paper> |
| 252 | + ); |
| 253 | +}; |
| 254 | + |
| 255 | +export default withStyles(styles)(SubnetLicenseTenant); |
0 commit comments