Separate warning out of absolute range

This commit is contained in:
Julia Friesel
2018-08-26 19:34:52 +02:00
parent 2a07ce4ef2
commit 8a6f943e5f
5 changed files with 55 additions and 70 deletions
@@ -8,7 +8,14 @@ import styles, {iconStyles} from '../../../styles'
export default class ActionButtonFooter extends Component {
render() {
const { symptom, cycleDay, saveAction, saveDisabled, navigate} = this.props
const {
symptom,
cycleDay,
saveAction,
saveDisabled,
navigate,
autoShowDayView = true}
= this.props
const navigateToOverView = () => navigate('CycleDay', {cycleDay})
const buttons = [
{
@@ -28,7 +35,7 @@ export default class ActionButtonFooter extends Component {
title: 'Save',
action: () => {
saveAction()
navigateToOverView()
if (autoShowDayView) navigateToOverView()
},
disabledCondition: saveDisabled,
icon: 'content-save-outline'
+44 -20
View File
@@ -17,6 +17,7 @@ import { temperature as tempLabels } from '../labels/labels'
import { scaleObservable } from '../../../local-storage'
import { shared } from '../../labels'
import ActionButtonFooter from './action-button-footer'
import config from '../../../config'
const minutes = ChronoUnit.MINUTES
@@ -49,6 +50,47 @@ export default class Temp extends Component {
}
}
saveTemperature = () => {
const dataToSave = {
value: Number(this.state.temperature),
exclude: this.state.exclude,
time: this.state.time
}
saveSymptom('temperature', this.cycleDay, dataToSave)
this.props.navigate('CycleDay', {cycleDay: this.cycleDay})
}
checkRangeAndSave = () => {
const value = Number(this.state.temperature)
const absolute = {
min: config.temperatureScale.min,
max: config.temperatureScale.max
}
const scale = scaleObservable.value
let warningMsg
if (value < absolute.min || value > absolute.max) {
warningMsg = tempLabels.outOfAbsoluteRangeWarning
} else if (value < scale.min || value > scale.max) {
warningMsg = tempLabels.outOfRangeWarning
}
if (warningMsg) {
Alert.alert(
shared.warning,
warningMsg,
[
{ text: shared.cancel },
{ text: shared.save, onPress: this.saveTemperature}
]
)
} else {
this.saveTemperature()
}
}
render() {
return (
<View style={{ flex: 1 }}>
@@ -98,20 +140,14 @@ export default class Temp extends Component {
<ActionButtonFooter
symptom='temperature'
cycleDay={this.cycleDay}
saveAction={() => {
const dataToSave = {
value: Number(this.state.temperature),
exclude: this.state.exclude,
time: this.state.time
}
saveSymptom('temperature', this.cycleDay, dataToSave)
}}
saveAction={() => this.checkRangeAndSave()}
saveDisabled={
this.state.temperature === '' ||
isNaN(Number(this.state.temperature)) ||
isInvalidTime(this.state.time)
}
navigate={this.props.navigate}
autoShowDayView={false}
/>
</View>
)
@@ -119,18 +155,6 @@ export default class Temp extends Component {
}
class TempInput extends Component {
checkRange = () => {
const value = Number(this.props.value)
if (isNaN(value)) return
const scale = scaleObservable.value
if (value < scale.min || value > scale.max) {
Alert.alert(
shared.warning,
tempLabels.outOfRangeWarning,
)
}
}
render() {
const style = [styles.temperatureTextInput]
if (this.props.isSuggestion) {