import classNames from 'classnames' import InputSuggestions from 'Components/conversation/InputSuggestions' import withLanguage from 'Components/utils/withLanguage' import { findRuleByDottedName } from 'Engine/rules' import { propEq } from 'ramda' import React, { Component } from 'react' import { Trans, translate } from 'react-i18next' import { connect } from 'react-redux' import { Link } from 'react-router-dom' import { change, Field, formValueSelector, reduxForm } from 'redux-form' import { analysisWithDefaultsSelector, blockingInputControlsSelector, flatRulesSelector, noUserInputSelector } from 'Selectors/analyseSelectors' import Controls from './Controls' import CurrencyInput from './CurrencyInput/CurrencyInput' import AnimatedTargetValue from './AnimatedTargetValue' import ProgressCircle from './ProgressCircle' import './TargetSelection.css' let salaries = [ 'contrat salarié . salaire . total', 'contrat salarié . salaire . brut de base', 'contrat salarié . salaire . net à payer' ] let displayedTargetNames = [...salaries, 'contrat salarié . aides employeur'] export let popularTargetNames = [ ...displayedTargetNames, 'contrat salarié . salaire . net imposable' ] @translate() @reduxForm({ form: 'conversation', destroyOnUnmount: false }) @connect( state => ({ getTargetValue: dottedName => formValueSelector('conversation')(state, dottedName), analysis: analysisWithDefaultsSelector(state), blockingInputControls: blockingInputControlsSelector(state), flatRules: flatRulesSelector(state), noUserInput: noUserInputSelector(state), conversationStarted: state.conversationStarted, activeInput: state.activeTargetInput }), dispatch => ({ setFormValue: (field, name) => dispatch(change('conversation', field, name)), setActiveInput: name => dispatch({ type: 'SET_ACTIVE_TARGET_INPUT', name }) }) ) export default class TargetSelection extends Component { render() { let { colours, noUserInput, blockingInputControls } = this.props return (
{this.renderOutputList()}
{noUserInput && (

Entrez un salaire mensuel

)} {blockingInputControls && ( )}
) } renderOutputList() { let displayedTargets = displayedTargetNames.map(target => findRuleByDottedName(this.props.flatRules, target) ), { conversationStarted, activeInput, setActiveInput, analysis, noUserInput, blockingInputControls } = this.props, targets = analysis ? analysis.targets : [] return (
) } } let Header = ({ target, conversationStarted, isActiveInput, blockingInputControls }) => { return ( {conversationStarted && !blockingInputControls && ( )} {target.title || target.name} {!conversationStarted &&

{target['résumé']}

}
) } let CurrencyField = props => { return ( ) } let TargetInputOrValue = withLanguage( ({ target, targets, activeInput, setActiveInput, language, noUserInput, blockingInputControls }) => ( {activeInput === target.dottedName ? ( ) : ( )} ) ) @connect( () => ({}), dispatch => ({ setFormValue: (field, name) => dispatch(change('conversation', field, name)) }) ) class TargetValue extends Component { render() { let { targets, target, noUserInput, blockingInputControls } = this.props let targetWithValue = targets && targets.find(propEq('dottedName', target.dottedName)), value = targetWithValue && targetWithValue.nodeValue return ( ) } showField(value) { let { target, setFormValue, activeInput, setActiveInput } = this.props return () => { if (!target.question) return if (value != null) setFormValue(target.dottedName, Math.floor(value) + '') if (activeInput) setFormValue(activeInput, '') setActiveInput(target.dottedName) } } }