2017-04-18 17:37:38 +00:00
|
|
|
import React, {Component} from 'react'
|
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 {START_CONVERSATION} from '../actions'
|
|
|
|
import R from 'ramda'
|
2017-04-24 18:03:38 +00:00
|
|
|
import {Redirect, Link, withRouter} from 'react-router-dom'
|
2017-05-18 14:04:23 +00:00
|
|
|
import Aide from './Aide'
|
|
|
|
import {createMarkdownDiv} from 'Engine/marked'
|
|
|
|
import {findRuleByName, decodeRuleName} from 'Engine/rules'
|
|
|
|
import 'Components/conversation/conversation.css'
|
|
|
|
import 'Components/Simulateur.css'
|
2017-04-18 17:37:38 +00:00
|
|
|
import classNames from 'classnames'
|
2017-05-07 17:45:44 +00:00
|
|
|
import {capitalise0} from '../utils'
|
2017-05-18 14:04:23 +00:00
|
|
|
import Satisfaction from 'Components/Satisfaction'
|
2017-05-07 17:45:44 +00:00
|
|
|
|
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-18 14:04:23 +00:00
|
|
|
resetForm: () => 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,
|
2017-05-18 14:04:23 +00:00
|
|
|
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-18 14:04:23 +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'])}</h1>
|
|
|
|
{sim('sous-titre') &&
|
|
|
|
<div id="simSubtitle">{sim('sous-titre')}</div>
|
|
|
|
}
|
|
|
|
{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}
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
}
|
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
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<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 14:04:23 +00:00
|
|
|
N'hésitez pas à nous écrire <Link to="/contact">
|
|
|
|
<i className="fa fa-envelope-open-o" aria-hidden="true" style={{margin: '0 .3em'}}></i>
|
|
|
|
</Link> ! La loi française est très ciblée, et donc complexe. Nous pouvons la rendre plus transparente.
|
2017-04-18 17:37:38 +00:00
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
: (
|
|
|
|
<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</h3>
|
2017-05-02 15:24:28 +00:00
|
|
|
<button onClick={reinitalise}>
|
|
|
|
<i className="fa fa-trash" aria-hidden="true"></i>
|
|
|
|
Tout effacer
|
|
|
|
</button>
|
|
|
|
</div>
|
2017-04-18 17:37:38 +00:00
|
|
|
{foldedSteps
|
|
|
|
.map(step => (
|
|
|
|
<step.component
|
|
|
|
key={step.name}
|
|
|
|
{...step}
|
|
|
|
step={step}
|
|
|
|
answer={situation(step.name)}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
<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)}
|
|
|
|
/>
|
|
|
|
}}
|
|
|
|
</div>
|
|
|
|
{unfoldedSteps.length == 0 &&
|
2017-05-18 14:04:23 +00:00
|
|
|
<Conclusion simu={this.name}/>}
|
2017-04-18 17:37:38 +00:00
|
|
|
</div>
|
|
|
|
<Aide />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2017-05-07 17:45:44 +00:00
|
|
|
|
|
|
|
class Conclusion extends Component {
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div id="fin">
|
|
|
|
<img src={require('../images/fin.png')} />
|
2017-05-18 14:04:23 +00:00
|
|
|
<div id="fin-text">
|
|
|
|
<p>
|
|
|
|
Votre simulation est terminée !
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
N'hésitez pas à modifier vos réponses, ou cliquez sur vos résultats pour comprendre le calcul.
|
|
|
|
</p>
|
|
|
|
<Satisfaction simu={this.props.simu}/>
|
|
|
|
</div>
|
2017-05-07 17:45:44 +00:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|