| 
									
										
										
										
											2020-02-09 10:21:13 +00:00
										 |  |  | import React, { Fragment } from 'react'; | 
					
						
							|  |  |  | import { TextValidator, ValidatorForm, SelectValidator } from 'react-material-ui-form-validator'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import MenuItem from '@material-ui/core/MenuItem'; | 
					
						
							|  |  |  | import SaveIcon from '@material-ui/icons/Save'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import {PasswordValidator, RestFormProps, FormActions, FormButton} from '../components'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-29 20:58:09 +01:00
										 |  |  | import { isAPEnabled } from './APModes'; | 
					
						
							| 
									
										
										
										
											2020-05-30 09:47:24 +01:00
										 |  |  | import { APSettings, APProvisionMode } from './types'; | 
					
						
							| 
									
										
										
										
											2020-02-09 10:21:13 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | type APSettingsFormProps = RestFormProps<APSettings>; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class APSettingsForm extends React.Component<APSettingsFormProps> { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   render() { | 
					
						
							|  |  |  |     const { data, handleValueChange, saveData, loadData } = this.props; | 
					
						
							|  |  |  |     return ( | 
					
						
							|  |  |  |       <ValidatorForm onSubmit={saveData} ref="APSettingsForm"> | 
					
						
							|  |  |  |         <SelectValidator name="provision_mode" | 
					
						
							| 
									
										
										
										
											2020-06-29 00:25:58 +01:00
										 |  |  |           label="Provide Access Point…" | 
					
						
							| 
									
										
										
										
											2020-02-09 10:21:13 +00:00
										 |  |  |           value={data.provision_mode} | 
					
						
							|  |  |  |           fullWidth | 
					
						
							|  |  |  |           variant="outlined" | 
					
						
							|  |  |  |           onChange={handleValueChange('provision_mode')} | 
					
						
							|  |  |  |           margin="normal"> | 
					
						
							| 
									
										
										
										
											2020-05-30 09:47:24 +01:00
										 |  |  |           <MenuItem value={APProvisionMode.AP_MODE_ALWAYS}>Always</MenuItem> | 
					
						
							|  |  |  |           <MenuItem value={APProvisionMode.AP_MODE_DISCONNECTED}>When WiFi Disconnected</MenuItem> | 
					
						
							|  |  |  |           <MenuItem value={APProvisionMode.AP_NEVER}>Never</MenuItem> | 
					
						
							| 
									
										
										
										
											2020-02-09 10:21:13 +00:00
										 |  |  |         </SelectValidator> | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           isAPEnabled(data) && | 
					
						
							|  |  |  |           <Fragment> | 
					
						
							|  |  |  |             <TextValidator | 
					
						
							|  |  |  |               validators={['required', 'matchRegexp:^.{1,32}$']} | 
					
						
							|  |  |  |               errorMessages={['Access Point SSID is required', 'Access Point SSID must be 32 characters or less']} | 
					
						
							|  |  |  |               name="ssid" | 
					
						
							|  |  |  |               label="Access Point SSID" | 
					
						
							|  |  |  |               fullWidth | 
					
						
							|  |  |  |               variant="outlined" | 
					
						
							|  |  |  |               value={data.ssid} | 
					
						
							|  |  |  |               onChange={handleValueChange('ssid')} | 
					
						
							|  |  |  |               margin="normal" | 
					
						
							|  |  |  |             /> | 
					
						
							|  |  |  |             <PasswordValidator | 
					
						
							|  |  |  |               validators={['required', 'matchRegexp:^.{1,64}$']} | 
					
						
							|  |  |  |               errorMessages={['Access Point Password is required', 'Access Point Password must be 64 characters or less']} | 
					
						
							|  |  |  |               name="password" | 
					
						
							|  |  |  |               label="Access Point Password" | 
					
						
							|  |  |  |               fullWidth | 
					
						
							|  |  |  |               variant="outlined" | 
					
						
							|  |  |  |               value={data.password} | 
					
						
							|  |  |  |               onChange={handleValueChange('password')} | 
					
						
							|  |  |  |               margin="normal" | 
					
						
							|  |  |  |             /> | 
					
						
							|  |  |  |           </Fragment> | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         <FormActions> | 
					
						
							|  |  |  |           <FormButton startIcon={<SaveIcon />} variant="contained" color="primary" type="submit"> | 
					
						
							|  |  |  |             Save | 
					
						
							|  |  |  |           </FormButton> | 
					
						
							|  |  |  |           <FormButton variant="contained" color="secondary" onClick={loadData}> | 
					
						
							|  |  |  |             Reset | 
					
						
							|  |  |  |           </FormButton> | 
					
						
							|  |  |  |         </FormActions> | 
					
						
							|  |  |  |       </ValidatorForm> | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default APSettingsForm; |