import React, {Fragment} from 'react'; import PropTypes from 'prop-types'; import { withStyles } from 'material-ui/styles'; import Button from 'material-ui/Button'; import { LinearProgress } from 'material-ui/Progress'; import Checkbox from 'material-ui/Checkbox'; import { FormControlLabel } from 'material-ui/Form'; import { TextValidator, ValidatorForm } from 'react-material-ui-form-validator'; import Typography from 'material-ui/Typography'; import List, { ListItem, ListItemText, ListItemSecondaryAction, ListItemAvatar } from 'material-ui/List'; import { isNetworkOpen, networkSecurityMode } from '../constants/WiFiSecurityModes'; import Avatar from 'material-ui/Avatar'; import IconButton from 'material-ui/IconButton'; import LockIcon from 'material-ui-icons/Lock'; import LockOpenIcon from 'material-ui-icons/LockOpen'; import DeleteIcon from 'material-ui-icons/Delete'; import isIP from '../validators/isIP'; import isHostname from '../validators/isHostname'; import optional from '../validators/optional'; const styles = theme => ({ loadingSettings: { margin: theme.spacing.unit, }, loadingSettingsDetails: { margin: theme.spacing.unit * 4, textAlign: "center" }, textField: { width: "100%" }, checkboxControl: { width: "100%" }, button: { marginRight: theme.spacing.unit * 2, marginTop: theme.spacing.unit * 2, } }); class WiFiSettingsForm extends React.Component { componentWillMount() { ValidatorForm.addValidationRule('isIP', isIP); ValidatorForm.addValidationRule('isHostname', isHostname); ValidatorForm.addValidationRule('isOptionalIP', optional(isIP)); } renderSelectedNetwork() { const { selectedNetwork, deselectNetwork } = this.props; return ( {isNetworkOpen(selectedNetwork) ? : } ); } render() { const { classes, formRef, wifiSettingsFetched, wifiSettings, errorMessage, selectedNetwork, handleValueChange, handleCheckboxChange, onSubmit, onReset } = this.props; return (
{ !wifiSettingsFetched ?
Loading...
: wifiSettings ? { selectedNetwork ? this.renderSelectedNetwork() : } { !isNetworkOpen(selectedNetwork) && } } label="Static IP Config?" /> { wifiSettings.static_ip_config && } :
{errorMessage}
}
); } } WiFiSettingsForm.propTypes = { classes: PropTypes.object.isRequired, wifiSettingsFetched: PropTypes.bool.isRequired, wifiSettings: PropTypes.object, errorMessage: PropTypes.string, deselectNetwork: PropTypes.func, selectedNetwork: PropTypes.object, onSubmit: PropTypes.func.isRequired, onReset: PropTypes.func.isRequired, handleValueChange: PropTypes.func.isRequired, handleCheckboxChange: PropTypes.func.isRequired }; export default withStyles(styles)(WiFiSettingsForm);