import React, { Component } from 'react' import { Trans, translate } from 'react-i18next' import formValueTypes from 'Components/conversation/formValueTypes' import { findRuleByName } from 'Engine/rules' import { propEq, curry } from 'ramda' import './TargetSelection.css' import BlueButton from './BlueButton' import { Field, reduxForm, formValueSelector, change } from 'redux-form' import { Link } from 'react-router-dom' import { connect } from 'react-redux' import { RuleValue } from './rule/RuleValueVignette' import classNames from 'classnames' import ProgressCircle from './ProgressCircle/ProgressCircle' import InputSuggestions from 'Components/conversation/InputSuggestions' import { buildValidationFunction } from './conversation/FormDecorator' export let salaries = ['salaire total', 'salaire de base', 'salaire net'] export let popularTargetNames = [...salaries, 'aides employeur'] @translate() @reduxForm({ form: 'conversation', destroyOnUnmount: false }) @connect( state => ({ getTargetValue: dottedName => formValueSelector('conversation')(state, dottedName), targets: state.analysis ? state.analysis.targets : [], flatRules: state.flatRules, conversationStarted: state.conversationStarted, activeInput: state.activeTargetInput }), dispatch => ({ setFormValue: (field, name) => dispatch(change('conversation', field, name)), startConversation: () => dispatch({ type: 'START_CONVERSATION' }), setActiveInput: name => dispatch({ type: 'SET_ACTIVE_TARGET_INPUT', name }) }) ) export default class TargetSelection extends Component { render() { let { targets, conversationStarted, colours, activeInput } = this.props this.firstEstimationComplete = activeInput && targets.length > 0 return (
{this.renderOutputList()}
{!this.firstEstimationComplete && (

Entrez un salaire mensuel

)} {this.firstEstimationComplete && !conversationStarted && (

Estimation approximative {' '}
pour une situation par défaut (CDI non cadre).

Affiner le calcul
)}
) } renderOutputList() { let popularTargets = popularTargetNames.map( curry(findRuleByName)(this.props.flatRules) ), { conversationStarted, activeInput, setActiveInput, targets } = this.props return (
) } } let Header = ({ target, conversationStarted, isActiveInput }) => { return ( {conversationStarted && ( )} {target.title || target.name} {!conversationStarted &&

{target['résumé']}

}
) } let validate = buildValidationFunction(formValueTypes['euros']) let InputComponent = ({ input, meta: { dirty, error } }) => ( {dirty && error && {error}} ) let TargetInputOrValue = ({ target, targets, firstEstimationComplete, activeInput, setActiveInput }) => ( {activeInput === target.dottedName ? ( ) : ( )} {(firstEstimationComplete || target.question) && ( )} ) @connect( () => ({}), dispatch => ({ setFormValue: (field, name) => dispatch(change('conversation', field, name)) }) ) class TargetValue extends Component { render() { let { targets, target, setFormValue, activeInput, setActiveInput } = this.props, targetWithValue = targets.find(propEq('dottedName', target.dottedName)), value = targetWithValue && targetWithValue.nodeValue, humanValue = value != null && value.toFixed(0) return ( { if (!target.question) return if (value != null) { setFormValue(target.dottedName, humanValue + '') setFormValue(activeInput, '') } setActiveInput(target.dottedName) }}> ) } }