mon-entreprise/source/components/TargetSelection.js

51 lines
1.1 KiB
JavaScript
Raw Normal View History

2017-11-15 09:49:55 +00:00
import React, { Component } from 'react'
import { rules } from 'Engine/rules'
import { propEq, reject } from 'ramda'
import { Link } from 'react-router-dom'
export default class TargetSelection extends Component {
state = {
targets: []
2017-11-15 09:49:55 +00:00
}
render() {
let { targets } = this.state
return (
<section id="selection">
<h2>Qu'allons-nous calculer ?</h2>
2017-11-15 09:49:55 +00:00
{this.renderOutputList()}
{targets.length !== 0 && (
2017-11-15 09:49:55 +00:00
<Link to={'/simu/' + targets.join('+')}>
<button>Valider</button>
</Link>
)}
</section>
)
}
renderOutputList() {
let salaires = rules.filter(propEq('type', 'salaire')),
{ targets } = this.state
return (
<select
multiple
value={targets}
onMouseDown={e => e.target.value != '' &&
2017-11-15 09:49:55 +00:00
this.setState({
targets: targets.find(t => t === e.target.value)
? reject(t => t === e.target.value, targets)
: [...targets, e.target.value]
})
}
>
{salaires.map(s => (
<option key={s.name} value={s.name}>
<div className="optionTitle">{s.title || s.name}</div>
<span>{s['résumé']}</span>
2017-11-15 09:49:55 +00:00
</option>
))}
</select>
)
}
}