import React, { Component } from 'react' import { Trans, translate } from 'react-i18next' import formValueTypes from 'Components/conversation/formValueTypes' import { rules, findRuleByName } from 'Engine/rules' import { propEq, isEmpty, curry, values } 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 { buildValidationFunction } from './conversation/FormDecorator' export let salaries = ['salaire total', 'salaire de base', 'salaire net'] export let popularTargetNames = [...salaries, 'aides employeur'] import { Circle } from 'rc-progress' @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, missingVariablesByTarget: state.missingVariablesByTarget, 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) ), { missingVariablesByTarget, conversationStarted, activeInput, setActiveInput } = this.props return (
) } } let computeRatio = (mvt, name) => !isEmpty(mvt) && values(mvt.current[name]).length / values(mvt.initial[name]).length let ProgressCircle = ({ activeInput, s, missingVariablesByTarget }) => { let isActiveInput = activeInput === s.dottedName, ratio = isActiveInput ? null : computeRatio(missingVariablesByTarget, s.dottedName) return ( {ratio === 0 ? (