2017-01-10 18:22:44 +00:00
import React , { Component } from 'react'
2017-02-09 12:58:12 +00:00
import classNames from 'classnames'
2017-04-18 17:37:38 +00:00
import { Link } from 'react-router-dom'
2017-03-15 15:26:00 +00:00
import { connect } from 'react-redux'
2017-03-16 18:30:30 +00:00
import R from 'ramda'
2017-03-27 13:32:03 +00:00
import './Results.css'
2017-01-10 18:22:44 +00:00
2017-03-13 12:35:38 +00:00
let fmt = new Intl . NumberFormat ( 'fr-FR' ) . format
let humanFigure = decimalDigits => value => fmt ( value . toFixed ( decimalDigits ) )
2017-03-15 15:26:00 +00:00
@ connect (
state => ( {
2017-04-18 17:37:38 +00:00
pointedOutObjectives : state . pointedOutObjectives ,
analysedSituation : state . analysedSituation ,
conversationStarted : ! R . isEmpty ( state . form )
2017-03-15 15:26:00 +00:00
} )
)
2017-01-10 18:22:44 +00:00
export default class Results extends Component {
render ( ) {
2017-04-18 17:37:38 +00:00
let { analysedSituation , pointedOutObjectives , conversationStarted } = this . props
2017-04-06 16:34:00 +00:00
// On travaille pour l'instant sur un objectif qui est une somme de plusieurs variables, et c'est ces variables que nous affichons comme résultats. D'où ce chemin :
2017-03-16 18:30:30 +00:00
let explanation = R . path ( [ 'formule' , 'explanation' , 'explanation' ] ) ( analysedSituation )
if ( ! explanation ) return null
2017-01-10 18:22:44 +00:00
return (
2017-04-18 17:37:38 +00:00
< section id = "results" className = { classNames ( { started : conversationStarted } ) } >
2017-03-13 14:38:47 +00:00
< div id = "results-titles" >
< h2 > Vos obligations < / h 2 >
2017-04-18 17:37:38 +00:00
{ conversationStarted &&
< div > Cliquez pour comprendre chaque calcul & nbsp ; < i className = "fa fa-hand-o-right" aria - hidden = "true" > < / i > < / d i v > }
2017-03-13 14:38:47 +00:00
< / d i v >
2017-01-10 18:22:44 +00:00
< ul >
2017-03-16 18:30:30 +00:00
{ explanation . map (
2017-04-06 16:34:00 +00:00
( { variableName , nodeValue , explanation : { name , type , 'non applicable si' : nonApplicable , formule : { nodeValue : computedValue } } } ) =>
2017-02-09 12:58:12 +00:00
do {
let
2017-03-20 11:17:49 +00:00
unsatisfied = nodeValue == null ,
2017-04-06 16:34:00 +00:00
nonApplicableValue = nonApplicable ? nonApplicable . nodeValue : false ,
irrelevant = nonApplicableValue === true || computedValue == 0 ,
number = nonApplicableValue == false && computedValue != null ,
2017-03-20 11:17:49 +00:00
pointedOut = pointedOutObjectives . find ( objective => objective == variableName )
2017-03-01 19:27:35 +00:00
2017-03-16 18:30:30 +00:00
; < li key = { name } className = { classNames ( { unsatisfied , irrelevant , number , pointedOut } ) } >
2017-02-13 14:18:44 +00:00
< Link to = { "/regle/" + name } className = "understand" >
2017-03-13 14:38:47 +00:00
< div className = "rule-box" >
< div className = "rule-type" >
{ type }
< / d i v >
< div className = "rule-name" >
{ name }
< / d i v >
< p >
2017-04-18 17:37:38 +00:00
{ conversationStarted && (
irrelevant ?
"Vous n'êtes pas concerné"
: unsatisfied ?
'En attente de vos réponses...'
: < span className = "figure" > { humanFigure ( 2 ) ( computedValue ) + '€' } < / s p a n >
) }
2017-03-13 14:38:47 +00:00
< / p >
< / d i v >
2017-02-13 12:28:49 +00:00
< / L i n k >
2017-03-15 15:26:00 +00:00
< div className = "pointer" > • < / d i v >
2017-02-09 12:58:12 +00:00
< / l i >
}
2017-01-10 18:22:44 +00:00
) }
< / u l >
< / s e c t i o n >
)
}
}