2017-11-15 09:49:55 +00:00
|
|
|
import React, { Component } from 'react'
|
2018-03-29 07:58:20 +00:00
|
|
|
import { Trans, translate } from 'react-i18next'
|
2018-03-21 11:02:24 +00:00
|
|
|
import formValueTypes from 'Components/conversation/formValueTypes'
|
2018-02-28 16:45:13 +00:00
|
|
|
import { rules, findRuleByName } from 'Engine/rules'
|
2018-03-29 16:25:22 +00:00
|
|
|
import { propEq, path, contains, without, curry, append, ifElse } from 'ramda'
|
2017-11-16 17:11:42 +00:00
|
|
|
import './TargetSelection.css'
|
2018-01-10 16:51:35 +00:00
|
|
|
import BlueButton from './BlueButton'
|
2018-03-21 17:35:15 +00:00
|
|
|
import { Field, reduxForm, formValueSelector, change } from 'redux-form'
|
2018-03-29 09:50:34 +00:00
|
|
|
import { Link } from 'react-router-dom'
|
2018-02-28 16:45:13 +00:00
|
|
|
import { connect } from 'react-redux'
|
|
|
|
import { RuleValue } from './rule/RuleValueVignette'
|
2018-03-14 17:20:09 +00:00
|
|
|
import classNames from 'classnames'
|
2018-03-21 11:02:24 +00:00
|
|
|
import { buildValidationFunction } from './conversation/FormDecorator'
|
2018-03-15 11:18:21 +00:00
|
|
|
export let salaries = ['salaire total', 'salaire de base', 'salaire net']
|
2018-03-12 15:22:16 +00:00
|
|
|
export let popularTargetNames = [...salaries, 'aides employeur']
|
2018-04-03 13:59:34 +00:00
|
|
|
import { Circle } from 'rc-progress'
|
2017-12-07 14:19:51 +00:00
|
|
|
|
2018-03-29 07:58:20 +00:00
|
|
|
@translate()
|
2018-02-28 16:45:13 +00:00
|
|
|
@reduxForm({
|
|
|
|
form: 'conversation'
|
|
|
|
})
|
|
|
|
@connect(
|
|
|
|
state => ({
|
|
|
|
getTargetValue: dottedName =>
|
|
|
|
formValueSelector('conversation')(state, dottedName),
|
|
|
|
targets: state.analysis ? state.analysis.targets : [],
|
2018-03-29 17:26:35 +00:00
|
|
|
flatRules: state.flatRules,
|
|
|
|
conversationStarted: state.conversationStarted,
|
2018-04-05 15:08:04 +00:00
|
|
|
missingVariablesByTarget: state.missingVariablesByTarget,
|
|
|
|
activeInput: state.activeTargetInput
|
2018-02-28 16:45:13 +00:00
|
|
|
}),
|
|
|
|
dispatch => ({
|
2018-03-22 10:04:47 +00:00
|
|
|
setFormValue: (field, name) =>
|
|
|
|
dispatch(change('conversation', field, name)),
|
2018-04-05 15:08:04 +00:00
|
|
|
startConversation: () => dispatch({ type: 'START_CONVERSATION' }),
|
|
|
|
setActiveInput: name => dispatch({ type: 'SET_ACTIVE_TARGET_INPUT', name })
|
2018-02-28 16:45:13 +00:00
|
|
|
})
|
|
|
|
)
|
2017-11-15 09:49:55 +00:00
|
|
|
export default class TargetSelection extends Component {
|
|
|
|
render() {
|
2018-03-29 17:26:35 +00:00
|
|
|
let { targets, conversationStarted, colours } = this.props
|
2018-04-05 15:08:04 +00:00
|
|
|
this.firstEstimationComplete = this.props.activeInput && targets.length > 0
|
2017-11-15 09:49:55 +00:00
|
|
|
return (
|
2018-03-14 17:20:09 +00:00
|
|
|
<div id="targetSelection">
|
2018-03-12 09:38:29 +00:00
|
|
|
<section
|
2018-03-14 17:20:09 +00:00
|
|
|
id="targetsContainer"
|
2018-03-12 09:38:29 +00:00
|
|
|
style={{
|
2018-03-29 10:10:09 +00:00
|
|
|
background: colours.colour,
|
|
|
|
color: colours.textColour
|
2018-03-29 17:26:35 +00:00
|
|
|
}}>
|
2018-03-12 09:38:29 +00:00
|
|
|
{this.renderOutputList()}
|
|
|
|
</section>
|
2018-04-05 16:09:18 +00:00
|
|
|
{!this.firstEstimationComplete && <h1>Entrez un salaire mensuel </h1>}
|
2018-02-28 16:45:13 +00:00
|
|
|
|
2018-03-29 17:26:35 +00:00
|
|
|
{this.firstEstimationComplete &&
|
|
|
|
!conversationStarted && (
|
|
|
|
<div id="action">
|
|
|
|
<p>
|
|
|
|
<b>Estimation approximative</b> <br /> pour une situation par
|
|
|
|
défaut (CDI non cadre).
|
|
|
|
</p>
|
|
|
|
<BlueButton onClick={this.props.startConversation}>
|
|
|
|
Affiner le calcul
|
|
|
|
</BlueButton>
|
|
|
|
</div>
|
|
|
|
)}
|
2018-03-14 17:20:09 +00:00
|
|
|
</div>
|
2017-11-15 09:49:55 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
renderOutputList() {
|
2018-03-29 17:26:35 +00:00
|
|
|
let popularTargets = popularTargetNames.map(
|
|
|
|
curry(findRuleByName)(flatRules)
|
|
|
|
),
|
2018-04-03 13:59:34 +00:00
|
|
|
{
|
|
|
|
textColourOnWhite,
|
|
|
|
missingVariablesByTarget,
|
2018-04-05 15:08:04 +00:00
|
|
|
conversationStarted,
|
|
|
|
activeInput,
|
|
|
|
setActiveInput
|
2018-04-03 13:59:34 +00:00
|
|
|
} = this.props
|
2017-12-20 16:49:58 +00:00
|
|
|
|
2017-11-15 09:49:55 +00:00
|
|
|
return (
|
2017-11-16 17:11:42 +00:00
|
|
|
<div>
|
2018-03-22 17:54:19 +00:00
|
|
|
<ul id="targets">
|
2017-12-19 16:09:17 +00:00
|
|
|
{popularTargets.map(s => (
|
2018-03-22 17:54:19 +00:00
|
|
|
<li key={s.name}>
|
2018-04-06 09:40:31 +00:00
|
|
|
<span className="header">
|
|
|
|
{conversationStarted && (
|
|
|
|
<span
|
|
|
|
className="progressCircle"
|
|
|
|
style={{
|
|
|
|
visibility:
|
|
|
|
activeInput === s.dottedName ? 'hidden' : 'visible'
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{do {
|
|
|
|
let mv = missingVariablesByTarget[s.dottedName],
|
|
|
|
number = mv && mv.missingVariables.length,
|
|
|
|
ratio = number / 16
|
|
|
|
ratio === 0 ? (
|
|
|
|
<i className="fa fa-check" aria-hidden="true" />
|
|
|
|
) : (
|
|
|
|
<Circle
|
|
|
|
percent={100 - ratio * 100}
|
|
|
|
strokeWidth="15"
|
|
|
|
strokeColor="#5de662"
|
|
|
|
trailColor="#fff"
|
|
|
|
trailWidth="5"
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}}
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
|
|
|
|
<span className="texts">
|
|
|
|
<span className="optionTitle">
|
|
|
|
<Link to={'/règle/' + s.dottedName}>
|
|
|
|
{s.title || s.name}
|
|
|
|
</Link>
|
|
|
|
</span>
|
|
|
|
{!conversationStarted && <p>{s['résumé']}</p>}
|
2018-03-29 09:50:34 +00:00
|
|
|
</span>
|
2018-03-22 17:54:19 +00:00
|
|
|
</span>
|
|
|
|
<TargetInputOrValue
|
|
|
|
{...{
|
|
|
|
s,
|
|
|
|
targets: this.props.targets,
|
|
|
|
firstEstimationComplete: this.firstEstimationComplete,
|
2018-04-05 15:08:04 +00:00
|
|
|
activeInput,
|
|
|
|
setActiveInput,
|
2018-03-22 17:54:19 +00:00
|
|
|
setFormValue: this.props.setFormValue
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</li>
|
2017-12-19 16:09:17 +00:00
|
|
|
))}
|
2018-03-22 17:54:19 +00:00
|
|
|
</ul>
|
2017-11-16 17:11:42 +00:00
|
|
|
</div>
|
2017-11-15 09:49:55 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2018-03-21 15:12:13 +00:00
|
|
|
let validate = buildValidationFunction(formValueTypes['euros'])
|
2018-03-21 11:02:24 +00:00
|
|
|
let InputComponent = ({ input, meta: { dirty, error } }) => (
|
|
|
|
<span>
|
2018-03-21 15:12:13 +00:00
|
|
|
{dirty && error && <span className="input-error">{error}</span>}
|
2018-03-21 15:21:18 +00:00
|
|
|
<input type="number" {...input} autoFocus />
|
2018-03-21 11:02:24 +00:00
|
|
|
</span>
|
|
|
|
)
|
2018-03-21 17:35:15 +00:00
|
|
|
let TargetInputOrValue = ({
|
2018-03-21 11:02:24 +00:00
|
|
|
s,
|
|
|
|
targets,
|
|
|
|
firstEstimationComplete,
|
|
|
|
activeInput,
|
2018-03-21 17:35:15 +00:00
|
|
|
setActiveInput,
|
|
|
|
clearFormValue
|
2018-03-21 11:02:24 +00:00
|
|
|
}) => (
|
|
|
|
<span className="targetInputOrValue">
|
|
|
|
{activeInput === s.dottedName ? (
|
2018-03-21 15:12:13 +00:00
|
|
|
<Field
|
|
|
|
name={s.dottedName}
|
|
|
|
component={InputComponent}
|
|
|
|
type="text"
|
|
|
|
validate={validate}
|
|
|
|
/>
|
2018-03-21 11:02:24 +00:00
|
|
|
) : (
|
2018-03-22 10:04:47 +00:00
|
|
|
<TargetValue {...{ targets, s, activeInput, setActiveInput }} />
|
2018-03-21 11:02:24 +00:00
|
|
|
)}
|
|
|
|
{(firstEstimationComplete || s.question) && <span className="unit">€</span>}
|
|
|
|
</span>
|
|
|
|
)
|
2018-03-22 10:04:47 +00:00
|
|
|
|
|
|
|
@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)
|
2018-03-29 17:26:35 +00:00
|
|
|
}}>
|
2018-03-22 10:04:47 +00:00
|
|
|
<RuleValue value={value} />
|
|
|
|
</span>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|