|
| 1 | +import React, { useState } from "react"; |
| 2 | +import ModalWrapper from "../../Common/ModalWrapper/ModalWrapper"; |
| 3 | +import { createStyles, Theme, withStyles } from "@material-ui/core/styles"; |
| 4 | +import { modalBasic } from "../../Common/FormComponents/common/styleLibrary"; |
| 5 | +import InputBoxWrapper from "../../Common/FormComponents/InputBoxWrapper/InputBoxWrapper"; |
| 6 | +import SelectWrapper from "../../Common/FormComponents/SelectWrapper/SelectWrapper"; |
| 7 | +import Grid from "@material-ui/core/Grid"; |
| 8 | +import { factorForDropdown } from "../../../../common/utils"; |
| 9 | +import { Button, LinearProgress } from "@material-ui/core"; |
| 10 | + |
| 11 | +interface IAddZoneProps { |
| 12 | + classes: any; |
| 13 | + open: boolean; |
| 14 | + onCloseZoneAndReload: (shouldReload: boolean) => void; |
| 15 | +} |
| 16 | + |
| 17 | +const styles = (theme: Theme) => |
| 18 | + createStyles({ |
| 19 | + errorBlock: { |
| 20 | + color: "red", |
| 21 | + }, |
| 22 | + buttonContainer: { |
| 23 | + textAlign: "right", |
| 24 | + }, |
| 25 | + multiContainer: { |
| 26 | + display: "flex", |
| 27 | + alignItems: "center" as const, |
| 28 | + justifyContent: "flex-start" as const, |
| 29 | + }, |
| 30 | + sizeFactorContainer: { |
| 31 | + marginLeft: 8, |
| 32 | + }, |
| 33 | + ...modalBasic, |
| 34 | + }); |
| 35 | + |
| 36 | +const AddZoneModal = ({ |
| 37 | + classes, |
| 38 | + open, |
| 39 | + onCloseZoneAndReload, |
| 40 | +}: IAddZoneProps) => { |
| 41 | + const [addSending, setAddSending] = useState<boolean>(false); |
| 42 | + const [zoneName, setZoneName] = useState<string>(""); |
| 43 | + const [numberOfInstances, setNumberOfInstances] = useState<number>(0); |
| 44 | + const [volumesPerInstance, setVolumesPerInstance] = useState<number>(0); |
| 45 | + const [sizeFactor, setSizeFactor] = useState<string>("GiB"); |
| 46 | + const [volumeConfiguration, setVolumeConfig] = useState<string>(""); |
| 47 | + const [storageClass, setStorageClass] = useState<string>(""); |
| 48 | + return ( |
| 49 | + <ModalWrapper |
| 50 | + onClose={() => onCloseZoneAndReload(false)} |
| 51 | + modalOpen={open} |
| 52 | + title="Add Zone" |
| 53 | + > |
| 54 | + <form |
| 55 | + noValidate |
| 56 | + autoComplete="off" |
| 57 | + onSubmit={(e: React.FormEvent<HTMLFormElement>) => { |
| 58 | + e.preventDefault(); |
| 59 | + setAddSending(true); |
| 60 | + }} |
| 61 | + > |
| 62 | + <Grid item xs={12}> |
| 63 | + <InputBoxWrapper |
| 64 | + id="zone_name" |
| 65 | + name="zone_name" |
| 66 | + type="string" |
| 67 | + onChange={(e: React.ChangeEvent<HTMLInputElement>) => { |
| 68 | + setZoneName(e.target.value); |
| 69 | + }} |
| 70 | + label="Name" |
| 71 | + value={zoneName} |
| 72 | + /> |
| 73 | + </Grid> |
| 74 | + <Grid item xs={12}> |
| 75 | + <InputBoxWrapper |
| 76 | + id="number_instances" |
| 77 | + name="number_instances" |
| 78 | + type="number" |
| 79 | + onChange={(e: React.ChangeEvent<HTMLInputElement>) => { |
| 80 | + setNumberOfInstances(parseInt(e.target.value)); |
| 81 | + }} |
| 82 | + label="Volumes per Server" |
| 83 | + value={numberOfInstances.toString(10)} |
| 84 | + /> |
| 85 | + </Grid> |
| 86 | + <Grid item xs={12}> |
| 87 | + <InputBoxWrapper |
| 88 | + id="volumes_per_instance" |
| 89 | + name="volumes_per_instance" |
| 90 | + type="number" |
| 91 | + onChange={(e: React.ChangeEvent<HTMLInputElement>) => { |
| 92 | + setVolumesPerInstance(parseInt(e.target.value)); |
| 93 | + }} |
| 94 | + label="Volumes per Instance" |
| 95 | + value={volumesPerInstance.toString(10)} |
| 96 | + /> |
| 97 | + </Grid> |
| 98 | + <Grid item xs={12}> |
| 99 | + <div className={classes.multiContainer}> |
| 100 | + <div> |
| 101 | + <InputBoxWrapper |
| 102 | + id="volume_size" |
| 103 | + name="volume_size" |
| 104 | + onChange={(e: React.ChangeEvent<HTMLInputElement>) => { |
| 105 | + setVolumeConfig(e.target.value); |
| 106 | + }} |
| 107 | + label="Size" |
| 108 | + value={volumeConfiguration} |
| 109 | + /> |
| 110 | + </div> |
| 111 | + <div className={classes.sizeFactorContainer}> |
| 112 | + <SelectWrapper |
| 113 | + label="" |
| 114 | + id="size_factor" |
| 115 | + name="size_factor" |
| 116 | + value={sizeFactor} |
| 117 | + onChange={(e: React.ChangeEvent<{ value: unknown }>) => { |
| 118 | + setSizeFactor(e.target.value as string); |
| 119 | + }} |
| 120 | + options={factorForDropdown()} |
| 121 | + /> |
| 122 | + </div> |
| 123 | + </div> |
| 124 | + <Grid item xs={12}> |
| 125 | + <InputBoxWrapper |
| 126 | + id="storage_class" |
| 127 | + name="storage_class" |
| 128 | + type="string" |
| 129 | + onChange={(e: React.ChangeEvent<HTMLInputElement>) => { |
| 130 | + setStorageClass(e.target.value); |
| 131 | + }} |
| 132 | + label="Volumes per Server" |
| 133 | + value={storageClass} |
| 134 | + /> |
| 135 | + </Grid> |
| 136 | + <Grid item xs={12} className={classes.buttonContainer}> |
| 137 | + <Button |
| 138 | + type="submit" |
| 139 | + variant="contained" |
| 140 | + color="primary" |
| 141 | + disabled={addSending} |
| 142 | + > |
| 143 | + Save |
| 144 | + </Button> |
| 145 | + </Grid> |
| 146 | + {addSending && ( |
| 147 | + <Grid item xs={12}> |
| 148 | + <LinearProgress /> |
| 149 | + </Grid> |
| 150 | + )} |
| 151 | + </Grid> |
| 152 | + </form> |
| 153 | + </ModalWrapper> |
| 154 | + ); |
| 155 | +}; |
| 156 | + |
| 157 | +export default withStyles(styles)(AddZoneModal); |
0 commit comments