import classNames from 'classnames' import InputSuggestions from 'Components/conversation/InputSuggestions' import PeriodSwitch from 'Components/PeriodSwitch' import withColours from 'Components/utils/withColours' import withLanguage from 'Components/utils/withLanguage' import { encodeRuleName, findRuleByDottedName } from 'Engine/rules' import { compose, propEq } from 'ramda' import React, { Component } from 'react' import emoji from 'react-easy-emoji' import { Trans, translate } from 'react-i18next' import { connect } from 'react-redux' import { withRouter } from 'react-router' import { Link } from 'react-router-dom' import { change, Field, formValueSelector, reduxForm } from 'redux-form' import { analysisWithDefaultsSelector, blockingInputControlsSelector, flatRulesSelector, noUserInputSelector, situationBranchesSelector } from 'Selectors/analyseSelectors' import { normalizeBasePath } from '../utils' import AnimatedTargetValue from './AnimatedTargetValue' import CurrencyInput from './CurrencyInput/CurrencyInput' import ProgressCircle from './ProgressCircle' import './TargetSelection.css' export default compose( translate(), reduxForm({ form: 'conversation', destroyOnUnmount: false }), withColours, withRouter, 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, mainTargetNames: state.simulationConfig.objectifs }), dispatch => ({ setFormValue: (field, name) => dispatch(change('conversation', field, name)), setActiveInput: name => dispatch({ type: 'SET_ACTIVE_TARGET_INPUT', name }) }) ) )( class TargetSelection extends Component { render() { let { colours } = this.props return (
{this.renderOutputList()}
) } renderOutputList() { let displayedTargets = this.props.mainTargetNames.map(target => findRuleByDottedName(this.props.flatRules, target) ), { conversationStarted, activeInput, setActiveInput, analysis, noUserInput, blockingInputControls, match, keepFormValues } = this.props, targets = analysis ? analysis.targets : [] return (
) } } ) let Header = ({ target, conversationStarted, isActiveInput, blockingInputControls, match }) => { const ruleLink = normalizeBasePath(match.path).replace(/simulation\/$/, '') + 'règle/' + encodeRuleName(target.dottedName) return ( {conversationStarted && !blockingInputControls && ( )} {target.title || target.name} {!conversationStarted &&

{target['résumé']}

}
) } let CurrencyField = withColours(props => { return ( ) }) let TargetInputOrValue = withLanguage( ({ target, targets, activeInput, setActiveInput, language, noUserInput, keepFormValues, blockingInputControls }) => ( {activeInput === target.dottedName ? ( ) : ( )} {target.dottedName.includes('rémunération . total') && } ) ) const TargetValue = connect( state => ({ situation: situationBranchesSelector(state) }), dispatch => ({ setFormValue: (field, name) => dispatch(change('conversation', field, name)) }) )( class TargetValue extends Component { render() { let { targets, target, noUserInput, blockingInputControls, situation } = this.props let targetWithValue = targets && targets.find(propEq('dottedName', target.dottedName)), value = situation[target.dottedName] || (targetWithValue && targetWithValue.nodeValue) console.log(target.dottedName, situation[target.dottedName]) return (
) } showField(value) { let { target, setFormValue, activeInput, setActiveInput, keepFormValues } = this.props return () => { if (!target.question) return if (value != null) setFormValue(target.dottedName, Math.floor(value) + '') if (activeInput && !keepFormValues) setFormValue(activeInput, '') setActiveInput(target.dottedName) } } } ) const AidesGlimpse = compose( withColours, withRouter, connect(state => ({ analysis: analysisWithDefaultsSelector(state) })) )( class AidesGlimpse extends Component { render() { let targets = this.props.analysis.targets, aides = targets && targets.find( t => t.dottedName === 'contrat salarié . aides employeur' ) if (!aides || !aides.nodeValue) return null return (
{' '} - {' '} d'aides {emoji(aides.icon)}
) } } )