Fork of the excellent esp8266-react - https://github.com/rjwats/esp8266-react
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
2.2 KiB

  1. import React from 'react';
  2. import { TextValidator, ValidatorForm } from 'react-material-ui-form-validator';
  3. import { Checkbox } from '@material-ui/core';
  4. import SaveIcon from '@material-ui/icons/Save';
  5. import { RestFormProps, BlockFormControlLabel, PasswordValidator, FormButton, FormActions } from '../components';
  6. import {isIP,isHostname,or} from '../validators';
  7. import { OTASettings } from './types';
  8. type OTASettingsFormProps = RestFormProps<OTASettings>;
  9. class OTASettingsForm extends React.Component<OTASettingsFormProps> {
  10. componentDidMount() {
  11. ValidatorForm.addValidationRule('isIPOrHostname', or(isIP, isHostname));
  12. }
  13. render() {
  14. const { data, handleValueChange, saveData, loadData } = this.props;
  15. return (
  16. <ValidatorForm onSubmit={saveData}>
  17. <BlockFormControlLabel
  18. control={
  19. <Checkbox
  20. checked={data.enabled}
  21. onChange={handleValueChange("enabled")}
  22. />
  23. }
  24. label="Enable OTA Updates?"
  25. />
  26. <TextValidator
  27. validators={['required', 'isNumber', 'minNumber:1025', 'maxNumber:65535']}
  28. errorMessages={['Port is required', "Must be a number", "Must be greater than 1024 ", "Max value is 65535"]}
  29. name="port"
  30. label="Port"
  31. fullWidth
  32. variant="outlined"
  33. value={data.port}
  34. type="number"
  35. onChange={handleValueChange('port')}
  36. margin="normal"
  37. />
  38. <PasswordValidator
  39. validators={['required', 'matchRegexp:^.{1,64}$']}
  40. errorMessages={['OTA Password is required', 'OTA Point Password must be 64 characters or less']}
  41. name="password"
  42. label="Password"
  43. fullWidth
  44. variant="outlined"
  45. value={data.password}
  46. onChange={handleValueChange('password')}
  47. margin="normal"
  48. />
  49. <FormActions>
  50. <FormButton startIcon={<SaveIcon />} variant="contained" color="primary" type="submit">
  51. Save
  52. </FormButton>
  53. <FormButton variant="contained" color="secondary" onClick={loadData}>
  54. Reset
  55. </FormButton>
  56. </FormActions>
  57. </ValidatorForm>
  58. );
  59. }
  60. }
  61. export default OTASettingsForm;