import React, { Component } from 'react' import { Trans, translate } from 'react-i18next' import { connect } from 'react-redux' import { rules, findRuleByName } from 'Engine/rules' import { reject, propEq, curry, pipe, equals, filter, contains, length } from 'ramda' import { Link } from 'react-router-dom' import './TargetSelection.css' import BlueButton from './BlueButton' import { Field, reduxForm, formValueSelector } from 'redux-form' import { connect } from 'react-redux' import { RuleValue } from './rule/RuleValueVignette' export let salaries = ['salaire net', 'salaire de base', 'salaire total'] let popularTargetNames = [...salaries, 'aides employeur'] @translate() @reduxForm({ form: 'conversation' }) @connect( state => ({ getTargetValue: dottedName => formValueSelector('conversation')(state, dottedName), targets: state.analysis ? state.analysis.targets : [], flatRules: state.flatRules }), dispatch => ({ startConversation: (targetNames, fromScratch = false) => dispatch({ type: 'START_CONVERSATION', targetNames, fromScratch }) }) ) export default class TargetSelection extends Component { state = { targets: [], activeInput: null } componentWillMount() { this.props.startConversation(popularTargetNames) } render() { let { targets } = this.state, ready = targets.length > 0 console.log('yayayay', this.props.targets) if (this.props.targets.length == 0) return null return (

Entrez un salaire mensuel

{this.renderOutputList()} {false && (

Vous pouvez faire plusieurs choix

Valider
)}
) } renderOutputList() { let popularTargets = popularTargetNames.map( curry(findRuleByName)(flatRules) ), { targets } = this.state, textColourOnWhite = this.props.colours.textColourOnWhite, // You can't select 3 salaries, as one must be an input in the next step optionDisabled = name => contains('salaire', name) && pipe( reject(equals(name)), filter(contains('salaire')), length, equals(2) )(targets), optionIsChecked = s => targets.includes(s.name) return (
{popularTargets.map(s => (
this.setState({ targets: targets.find(t => t === s.name) ? reject(t => t === s.name, targets) : [...targets, s.name] }) } /> {s.name.includes('salaire') && this.state.activeInput === s.dottedName ? ( ) : ( this.setState({ activeInput: s.dottedName }) }> {do { let rule = this.props.targets.find( propEq('dottedName', s.dottedName) ), value = rule && rule.nodeValue ; }} )}

{s['résumé']}

))}
) } }