mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
valiadtion in sensor fields, auto refresh after change #84
This commit is contained in:
@@ -240,7 +240,13 @@ class EMSESPDataForm extends Component<
|
|||||||
redirectingAuthorizedFetch(WRITE_SENSOR_ENDPOINT, {
|
redirectingAuthorizedFetch(WRITE_SENSOR_ENDPOINT, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
sensor: edit_Sensor
|
// because input field with type=number doens't like negative values, force it here
|
||||||
|
sensor: {
|
||||||
|
no: edit_Sensor?.no,
|
||||||
|
id: edit_Sensor?.id,
|
||||||
|
temp: edit_Sensor?.temp,
|
||||||
|
offset: Number(edit_Sensor?.offset)
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
@@ -251,6 +257,7 @@ class EMSESPDataForm extends Component<
|
|||||||
this.props.enqueueSnackbar('Sensor updated', {
|
this.props.enqueueSnackbar('Sensor updated', {
|
||||||
variant: 'success'
|
variant: 'success'
|
||||||
});
|
});
|
||||||
|
this.props.loadData();
|
||||||
} else if (response.status === 204) {
|
} else if (response.status === 204) {
|
||||||
this.props.enqueueSnackbar('Sensor change failed', {
|
this.props.enqueueSnackbar('Sensor change failed', {
|
||||||
variant: 'error'
|
variant: 'error'
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
import React, { RefObject } from 'react';
|
import React, { RefObject } from 'react';
|
||||||
import { ValidatorForm } from 'react-material-ui-form-validator';
|
import { ValidatorForm, TextValidator } from 'react-material-ui-form-validator';
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogTitle,
|
DialogTitle,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
DialogActions,
|
DialogActions
|
||||||
FormHelperText,
|
|
||||||
OutlinedInput,
|
|
||||||
InputAdornment
|
|
||||||
} from '@material-ui/core';
|
} from '@material-ui/core';
|
||||||
|
|
||||||
import { FormButton } from '../components';
|
import { FormButton } from '../components';
|
||||||
@@ -49,23 +46,32 @@ class SensorForm extends React.Component<SensorFormProps> {
|
|||||||
Editing Sensor #{sensor.no}
|
Editing Sensor #{sensor.no}
|
||||||
</DialogTitle>
|
</DialogTitle>
|
||||||
<DialogContent dividers>
|
<DialogContent dividers>
|
||||||
<FormHelperText>Name (no spaces)</FormHelperText>
|
<TextValidator
|
||||||
<OutlinedInput
|
validators={['matchRegexp:^([a-zA-Z0-9_.-]{0,19})$']}
|
||||||
id="id"
|
errorMessages={['Not a valid name']}
|
||||||
value={sensor.id}
|
|
||||||
autoFocus
|
|
||||||
fullWidth
|
fullWidth
|
||||||
|
variant="outlined"
|
||||||
|
value={sensor.id}
|
||||||
onChange={handleSensorChange('id')}
|
onChange={handleSensorChange('id')}
|
||||||
|
margin="normal"
|
||||||
|
label="Name"
|
||||||
|
name="id"
|
||||||
/>
|
/>
|
||||||
|
<TextValidator
|
||||||
<FormHelperText>Custom Offset</FormHelperText>
|
validators={['isFloat', 'minFloat:-5', 'maxFloat:5']}
|
||||||
<OutlinedInput
|
errorMessages={[
|
||||||
id="offset"
|
'Must be a number',
|
||||||
|
'Must be greater than -5',
|
||||||
|
'Max value is +5'
|
||||||
|
]}
|
||||||
|
label="Custom Offset (°C)"
|
||||||
|
name="offset"
|
||||||
value={sensor.offset}
|
value={sensor.offset}
|
||||||
fullWidth
|
fullWidth
|
||||||
type="number"
|
variant="outlined"
|
||||||
|
InputProps={{ inputProps: { min: '-5', max: '5', step: '0.1' } }}
|
||||||
|
margin="normal"
|
||||||
onChange={handleSensorChange('offset')}
|
onChange={handleSensorChange('offset')}
|
||||||
endAdornment={<InputAdornment position="end">°C</InputAdornment>}
|
|
||||||
/>
|
/>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
<DialogActions>
|
<DialogActions>
|
||||||
|
|||||||
Reference in New Issue
Block a user