diff --git a/source/components/TargetSelection.js b/source/components/TargetSelection.js index a0fd86210..e494aec4b 100644 --- a/source/components/TargetSelection.js +++ b/source/components/TargetSelection.js @@ -26,7 +26,8 @@ export let popularTargetNames = [...salaries, 'aides employeur'] conversationTargetNames: state.conversationTargetNames }), dispatch => ({ - clearFormValue: field => dispatch(change('conversation', field, '')), + setFormValue: (field, name) => + dispatch(change('conversation', field, name)), setConversationTargets: (targetNames, fromScratch = false) => dispatch({ type: 'SET_CONVERSATION_TARGETS', targetNames, fromScratch }) }) @@ -152,7 +153,7 @@ export default class TargetSelection extends Component { activeInput: this.state.activeInput, setActiveInput: name => this.setState({ activeInput: name }), - clearFormValue: this.props.clearFormValue + setFormValue: this.props.setFormValue }} /> @@ -188,26 +189,43 @@ let TargetInputOrValue = ({ validate={validate} /> ) : ( - <> - { - if (!s.question) return - activeInput && clearFormValue(activeInput) - setActiveInput(s.dottedName) - }} - > - {do { - let rule = targets.find(propEq('dottedName', s.dottedName)), - value = rule && rule.nodeValue - ; - }} - - + )} {(firstEstimationComplete || s.question) && } ) + +@connect( + () => ({}), + dispatch => ({ + setFormValue: (field, name) => dispatch(change('conversation', field, name)) + }) +) +class TargetValue extends Component { + render() { + let { targets, s, setFormValue, activeInput, setActiveInput } = this.props, + rule = targets.find(propEq('dottedName', s.dottedName)), + value = rule && rule.nodeValue, + humanValue = value != null && value.toFixed(0) + + return ( + { + if (!s.question) return + if (value != null) { + setFormValue(s.dottedName, humanValue + '') + setFormValue(activeInput, '') + } + + setActiveInput(s.dottedName) + }} + > + + + ) + } +}