import React from 'react'; import PropTypes from 'prop-types'; import { withStyles } from '@material-ui/core/styles'; import Button from '@material-ui/core/Button'; import Switch from '@material-ui/core/Switch'; import LinearProgress from '@material-ui/core/LinearProgress'; import { TextValidator, ValidatorForm } from 'react-material-ui-form-validator'; import Typography from '@material-ui/core/Typography'; import FormControlLabel from '@material-ui/core/FormControlLabel'; import isIP from '../validators/isIP'; import isHostname from '../validators/isHostname'; import or from '../validators/or'; import PasswordValidator from '../components/PasswordValidator'; const styles = theme => ({ loadingSettings: { margin: theme.spacing.unit, }, loadingSettingsDetails: { margin: theme.spacing.unit * 4, textAlign: "center" }, switchControl: { width: "100%", marginTop: theme.spacing.unit * 2, marginBottom: theme.spacing.unit }, textField: { width: "100%" }, button: { marginRight: theme.spacing.unit * 2, marginTop: theme.spacing.unit * 2, } }); class OTASettingsForm extends React.Component { componentWillMount() { ValidatorForm.addValidationRule('isIPOrHostname', or(isIP, isHostname)); } render() { const { classes, otaSettingsFetched, otaSettings, errorMessage, handleValueChange, handleCheckboxChange, onSubmit, onReset } = this.props; return (
{ !otaSettingsFetched ?
Loading...
: otaSettings ? } label="Enable OTA Updates?" /> :
{errorMessage}
}
); } } OTASettingsForm.propTypes = { classes: PropTypes.object.isRequired, otaSettingsFetched: PropTypes.bool.isRequired, otaSettings: PropTypes.object, errorMessage: PropTypes.string, onSubmit: PropTypes.func.isRequired, onReset: PropTypes.func.isRequired, handleValueChange: PropTypes.func.isRequired, handleCheckboxChange: PropTypes.func.isRequired, }; export default withStyles(styles)(OTASettingsForm);