La valeur calculee d'un salaire initialise la saisie

Reorganisation du code au pssage
pull/206/head
Mael 2018-03-22 11:04:47 +01:00 committed by Laurent Bossavit
parent 33b10cebda
commit 26e647d71f
1 changed files with 39 additions and 21 deletions

View File

@ -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
}}
/>
</div>
@ -188,26 +189,43 @@ let TargetInputOrValue = ({
validate={validate}
/>
) : (
<>
<span
className={classNames({
editable: s.question,
attractClick: s.question && targets.length === 0
})}
onClick={() => {
if (!s.question) return
activeInput && clearFormValue(activeInput)
setActiveInput(s.dottedName)
}}
>
{do {
let rule = targets.find(propEq('dottedName', s.dottedName)),
value = rule && rule.nodeValue
;<RuleValue value={value} />
}}
</span>
</>
<TargetValue {...{ targets, s, activeInput, setActiveInput }} />
)}
{(firstEstimationComplete || s.question) && <span className="unit"></span>}
</span>
)
@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 (
<span
className={classNames({
editable: s.question,
attractClick: s.question && targets.length === 0
})}
onClick={() => {
if (!s.question) return
if (value != null) {
setFormValue(s.dottedName, humanValue + '')
setFormValue(activeInput, '')
}
setActiveInput(s.dottedName)
}}
>
<RuleValue value={value} />
</span>
)
}
}