2017-04-18 17:37:38 +00:00
import React , { Component } from 'react'
import './CDD.css'
2017-05-02 15:24:28 +00:00
import { reduxForm , formValueSelector , reset } from 'redux-form'
2017-04-18 17:37:38 +00:00
import { connect } from 'react-redux'
import './conversation/conversation.css'
import { START _CONVERSATION } from '../actions'
import Aide from './Aide'
import R from 'ramda'
2017-04-24 18:03:38 +00:00
import { Redirect , Link , withRouter } from 'react-router-dom'
2017-04-18 17:37:38 +00:00
import { createMarkdownDiv } from '../engine/marked'
import './Simulateur.css'
import classNames from 'classnames'
2017-05-09 14:33:35 +00:00
import { findRuleByName , decodeRuleName } from '../engine/rules'
2017-05-07 17:45:44 +00:00
import { capitalise0 } from '../utils'
2017-04-18 17:37:38 +00:00
let situationSelector = formValueSelector ( 'conversation' )
2017-04-24 18:03:38 +00:00
@ withRouter
2017-04-18 17:37:38 +00:00
@ reduxForm ( { form : 'conversation' , destroyOnUnmount : false } )
@ connect (
state => ( {
situation : variableName => situationSelector ( state , variableName ) ,
foldedSteps : state . foldedSteps ,
unfoldedSteps : state . unfoldedSteps ,
themeColours : state . themeColours ,
analysedSituation : state . analysedSituation ,
} ) ,
dispatch => ( {
startConversation : rootVariable => dispatch ( { type : START _CONVERSATION , rootVariable } ) ,
2017-05-02 15:24:28 +00:00
resetForm : rootVariable => dispatch ( reset ( 'conversation' ) )
2017-04-18 17:37:38 +00:00
} )
)
export default class extends React . Component {
componentWillMount ( ) {
let {
match : {
params : {
2017-05-09 14:33:35 +00:00
name : encodedName
2017-04-18 17:37:38 +00:00
}
}
2017-05-09 14:33:35 +00:00
} = this . props ,
name = decodeRuleName ( encodedName )
2017-04-18 17:37:38 +00:00
2017-05-09 14:33:35 +00:00
this . encodedName = encodedName
2017-05-07 17:45:44 +00:00
this . name = name
this . rule = findRuleByName ( name )
2017-04-18 17:37:38 +00:00
// C'est ici que la génération du formulaire, et donc la traversée des variables commence
2017-05-09 14:33:35 +00:00
if ( this . rule . formule )
2017-05-07 17:45:44 +00:00
this . props . startConversation ( name )
2017-04-18 17:37:38 +00:00
}
render ( ) {
2017-05-09 14:33:35 +00:00
if ( ! this . rule . formule ) return < Redirect to = "/404" / >
2017-04-18 17:37:38 +00:00
let
2017-04-24 18:03:38 +00:00
started = ! this . props . match . params . intro ,
2017-04-18 17:37:38 +00:00
{ foldedSteps , unfoldedSteps , situation } = this . props ,
sim = path =>
2017-05-07 17:45:44 +00:00
R . path ( R . unless ( R . is ( Array ) , R . of ) ( path ) ) ( this . rule . simulateur || { } ) ,
2017-05-02 15:24:28 +00:00
reinitalise = ( ) => {
2017-05-10 14:09:36 +00:00
this . props . resetForm ( this . name ) ;
this . props . startConversation ( this . name ) ;
2017-05-02 15:24:28 +00:00
}
2017-04-18 17:37:38 +00:00
return (
< div id = "sim" className = { classNames ( { started } ) } >
2017-05-07 17:45:44 +00:00
< h1 > { sim ( 'titre' ) || capitalise0 ( this . rule [ 'titre' ] || this . rule [ 'nom' ] ) } < / h 1 >
{ sim ( 'sous-titre' ) &&
< div id = "simSubtitle" > { sim ( 'sous-titre' ) } < / d i v >
}
{ sim ( [ 'introduction' , 'notes' ] ) &&
< div className = "intro centered" >
{ sim ( [ 'introduction' , 'notes' ] ) . map ( ( { icône , texte , titre } ) =>
< div key = { titre } >
< i title = { titre } className = { "fa " + icône } aria - hidden = "true" > < / i >
< span >
{ texte }
< / s p a n >
< / d i v >
) }
< / d i v >
}
2017-04-18 17:37:38 +00:00
{
// Tant que le bouton 'C'est parti' n'est pas cliqué, on affiche l'intro
2017-04-24 18:03:38 +00:00
! started ?
2017-04-18 17:37:38 +00:00
< div >
< div className = "action centered" >
2017-05-18 13:01:34 +00:00
{ createMarkdownDiv ( sim ( [ 'introduction' , 'motivation' ] ) ) || < p > Simulez cette règle en quelques clics < / p > }
2017-05-09 14:33:35 +00:00
< button onClick = { ( ) => this . props . history . push ( ` /simu/ ${ this . encodedName } ` ) } >
2017-05-07 17:45:44 +00:00
C ' est parti !
2017-04-18 17:37:38 +00:00
< / b u t t o n >
< / d i v >
< div className = "remarks centered" >
< p >
2017-05-05 15:28:49 +00:00
Pour simplifier , les résultats sont calculés par mois de contrat , et pour un temps complet .
2017-04-18 17:37:38 +00:00
< / p >
< p >
2017-05-18 13:01:34 +00:00
N 'hésitez pas à nous écrire <Link to="/contact"><i className="fa fa-envelope-open-o" aria-hidden="true" style={{margin: ' 0 . 3 em ' } } > < / i > < / L i n k > ! L a l o i f r a n ç a i s e e s t t r è s c i b l é e , e t d o n c c o m p l e x e . N o u s p o u v o n s l a r e n d r e p l u s t r a n s p a r e n t e .
2017-04-18 17:37:38 +00:00
< / p >
< / d i v >
< / d i v >
: (
< div >
< div id = "conversation" >
< div id = "questions-answers" >
{ ! R . isEmpty ( foldedSteps ) &&
< div id = "foldedSteps" >
2017-05-10 17:27:28 +00:00
< div className = "header" >
< h3 > Vos réponses < / h 3 >
2017-05-02 15:24:28 +00:00
< button onClick = { reinitalise } >
< i className = "fa fa-trash" aria - hidden = "true" > < / i >
Tout effacer
< / b u t t o n >
< / d i v >
2017-04-18 17:37:38 +00:00
{ foldedSteps
. map ( step => (
< step . component
key = { step . name }
{ ... step }
step = { step }
answer = { situation ( step . name ) }
/ >
) ) }
< / d i v >
}
< div id = "unfoldedSteps" >
{ ! R . isEmpty ( unfoldedSteps ) && do {
2017-04-28 15:03:34 +00:00
let step = R . head ( unfoldedSteps )
2017-04-18 17:37:38 +00:00
; < step . component
key = { step . name }
2017-04-28 15:03:34 +00:00
step = { R . dissoc ( 'component' , step ) }
2017-04-18 17:37:38 +00:00
unfolded = { true }
answer = { situation ( step . name ) }
/ >
} }
< / d i v >
{ unfoldedSteps . length == 0 &&
2017-05-07 17:45:44 +00:00
< Conclusion / > }
2017-04-18 17:37:38 +00:00
< / d i v >
< Aide / >
< / d i v >
< / d i v >
) }
< / d i v >
)
}
}
2017-05-07 17:45:44 +00:00
class Conclusion extends Component {
render ( ) {
return (
< div id = "fin" >
< img src = { require ( '../images/fin.png' ) } / >
< p >
Nous n ' avons plus de questions : votre simulation est terminée .
< / p >
< p >
Cliquez sur les obligations en bas pour comprendre vos résultats .
< / p >
< p >
Une remarque ? < Link to = "/contact" > Écrivez - nous ! < / L i n k >
< / p >
< / d i v >
)
}
}