import classNames from 'classnames' import { T } from 'Components' import InputSuggestions from 'Components/conversation/InputSuggestions' import PercentageField from 'Components/PercentageField' import PeriodSwitch from 'Components/PeriodSwitch' import RuleLink from 'Components/RuleLink' import withColours from 'Components/utils/withColours' import withSitePaths from 'Components/utils/withSitePaths' import { encodeRuleName } from 'Engine/rules' import { serialiseUnit } from 'Engine/units' import { compose, isEmpty, isNil, propEq } from 'ramda' import React, { memo, useEffect, useState } from 'react' import emoji from 'react-easy-emoji' import { useTranslation } 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, flatRulesSelector } from 'Selectors/analyseSelectors' import Animate from 'Ui/animate' import AnimatedTargetValue from 'Ui/AnimatedTargetValue' import CurrencyInput from './CurrencyInput/CurrencyInput' import './TargetSelection.css' export default compose( withColours, reduxForm({ form: 'conversation', destroyOnUnmount: false }), connect( state => ({ getTargetValue: dottedName => formValueSelector('conversation')(state, dottedName), analysis: analysisWithDefaultsSelector(state), flatRules: flatRulesSelector(state), activeInput: state.activeTargetInput, objectifs: state.simulation?.config.objectifs || [], secondaryObjectives: state.simulation?.config['objectifs secondaires'] || [] }), dispatch => ({ setFormValue: (field, name) => dispatch(change('conversation', field, name)), setActiveInput: name => dispatch({ type: 'SET_ACTIVE_TARGET_INPUT', name }) }) ), memo )(function TargetSelection({ secondaryObjectives, analysis, getTargetValue, setFormValue, colours, activeInput, setActiveInput, objectifs }) { const [initialRender, setInitialRender] = useState(true) useEffect(() => { let targets = getTargets() // Initialize defaultValue for target that can't be computed targets .filter( target => (!target.formule || isEmpty(target.formule)) && (!isNil(target.defaultValue) || !isNil(target.explanation?.defaultValue)) && !getTargetValue(target.dottedName) ) .forEach(target => { setFormValue( target.dottedName, !isNil(target.defaultValue) ? target.defaultValue : target.explanation?.defaultValue ) }) if (initialRender) { setInitialRender(false) } }, []) const getTargets = () => { if (!analysis) return [] return analysis.targets.filter( t => !secondaryObjectives.includes(t.dottedName) && t.dottedName !== 'contrat salarié . aides employeur' ) } let targets = getTargets() return (
{target.summary}
) }) let CurrencyField = withColours(props => { return (