2017-07-02 17:12:02 +00:00
|
|
|
import R from 'ramda'
|
2017-11-13 14:50:48 +00:00
|
|
|
import React, { Component } from 'react'
|
2017-07-02 17:12:02 +00:00
|
|
|
import Helmet from 'react-helmet'
|
2017-11-13 14:50:48 +00:00
|
|
|
import { reset } from 'redux-form'
|
|
|
|
import { connect } from 'react-redux'
|
|
|
|
import { Redirect, withRouter } from 'react-router-dom'
|
2017-07-02 17:12:02 +00:00
|
|
|
import classNames from 'classnames'
|
|
|
|
|
2017-11-13 14:50:48 +00:00
|
|
|
import { START_CONVERSATION } from '../actions'
|
|
|
|
import { rules, findRuleByName, decodeRuleName } from 'Engine/rules'
|
2017-07-01 15:49:32 +00:00
|
|
|
import './conversation/conversation.css'
|
|
|
|
import './Simulateur.css'
|
2017-11-13 14:50:48 +00:00
|
|
|
import { capitalise0 } from '../utils'
|
2017-09-28 12:59:10 +00:00
|
|
|
import Conversation from './conversation/Conversation'
|
2017-11-13 14:50:48 +00:00
|
|
|
import { makeQuestion } from 'Engine/generateQuestions'
|
2017-09-28 12:59:10 +00:00
|
|
|
|
2017-10-18 09:24:50 +00:00
|
|
|
import ReactPiwik from './Tracker'
|
2017-05-07 17:45:44 +00:00
|
|
|
|
2017-04-24 18:03:38 +00:00
|
|
|
@withRouter
|
2017-04-18 17:37:38 +00:00
|
|
|
@connect(
|
|
|
|
state => ({
|
2017-11-04 14:39:40 +00:00
|
|
|
currentQuestion: state.currentQuestion,
|
2017-04-18 17:37:38 +00:00
|
|
|
foldedSteps: state.foldedSteps,
|
2017-09-21 13:46:59 +00:00
|
|
|
extraSteps: state.extraSteps,
|
2017-04-18 17:37:38 +00:00
|
|
|
themeColours: state.themeColours,
|
2017-11-13 14:50:48 +00:00
|
|
|
situationGate: state.situationGate
|
2017-04-18 17:37:38 +00:00
|
|
|
}),
|
|
|
|
dispatch => ({
|
2017-11-13 14:50:48 +00:00
|
|
|
startConversation: (targetNames, firstInput) =>
|
|
|
|
dispatch({ type: START_CONVERSATION, targetNames, firstInput}),
|
2017-05-18 14:04:23 +00:00
|
|
|
resetForm: () => dispatch(reset('conversation'))
|
2017-04-18 17:37:38 +00:00
|
|
|
})
|
|
|
|
)
|
2017-10-18 09:24:50 +00:00
|
|
|
export default class extends Component {
|
2017-10-18 09:33:31 +00:00
|
|
|
state = {
|
|
|
|
started: false
|
|
|
|
}
|
2017-04-18 17:37:38 +00:00
|
|
|
componentWillMount() {
|
2017-11-13 14:50:48 +00:00
|
|
|
let { match: { params: { targets: encodedTargets, firstInput: encodedFirstInput } } } = this.props,
|
|
|
|
targetNames = encodedTargets.split('+').map(decodeRuleName),
|
2017-08-01 14:31:50 +00:00
|
|
|
existingConversation = this.props.foldedSteps.length > 0
|
2017-04-18 17:37:38 +00:00
|
|
|
|
2017-11-13 14:50:48 +00:00
|
|
|
this.targetNames = targetNames
|
|
|
|
this.targetRules = targetNames.map(name => findRuleByName(rules, name))
|
|
|
|
this.firstInput = findRuleByName(rules, decodeRuleName(encodedFirstInput)).dottedName
|
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-11-13 14:50:48 +00:00
|
|
|
// if (!existingConversation)
|
|
|
|
//TODO
|
|
|
|
this.props.startConversation(targetNames, this.firstInput)
|
2017-04-18 17:37:38 +00:00
|
|
|
}
|
2017-11-13 14:50:48 +00:00
|
|
|
render() {
|
|
|
|
//TODO
|
|
|
|
// if (!this.targets.formule && !R.path(['simulateur', 'objectifs'], this.rule))
|
|
|
|
// return <Redirect to={'/regle/' + this.name} />
|
2017-04-18 17:37:38 +00:00
|
|
|
|
2017-11-13 14:50:48 +00:00
|
|
|
let {
|
|
|
|
foldedSteps,
|
|
|
|
extraSteps,
|
|
|
|
currentQuestion,
|
|
|
|
situationGate,
|
|
|
|
themeColours
|
|
|
|
} = this.props,
|
2017-05-02 15:24:28 +00:00
|
|
|
reinitalise = () => {
|
2017-10-18 09:24:50 +00:00
|
|
|
ReactPiwik.push(['trackEvent', 'restart', ''])
|
2017-05-18 14:04:23 +00:00
|
|
|
this.props.resetForm(this.name)
|
2017-11-13 14:50:48 +00:00
|
|
|
this.props.startConversation(this.targets, this.firstInput)
|
|
|
|
}
|
2017-11-04 14:26:09 +00:00
|
|
|
|
2017-04-18 17:37:38 +00:00
|
|
|
return (
|
2017-11-13 14:50:48 +00:00
|
|
|
<div id="sim">
|
2017-05-19 09:25:13 +00:00
|
|
|
<Helmet>
|
2017-11-13 14:50:48 +00:00
|
|
|
<title>Titre à mettre</title>
|
2017-05-19 09:25:13 +00:00
|
|
|
</Helmet>
|
2017-11-13 14:50:48 +00:00
|
|
|
<h1>Titre et sous titres à mettre TODO</h1>
|
2017-05-07 17:45:44 +00:00
|
|
|
|
2017-11-13 14:50:48 +00:00
|
|
|
<Conversation
|
|
|
|
{...{
|
|
|
|
reinitalise,
|
|
|
|
currentQuestion:
|
|
|
|
currentQuestion &&
|
|
|
|
this.buildStep({ unfolded: true })(situationGate)(currentQuestion),
|
|
|
|
foldedSteps: R.map(
|
|
|
|
this.buildStep({ unfolded: false })(situationGate),
|
|
|
|
foldedSteps
|
|
|
|
),
|
|
|
|
extraSteps: R.map(
|
|
|
|
this.buildStep({ unfolded: true })(situationGate),
|
|
|
|
extraSteps
|
|
|
|
),
|
|
|
|
textColourOnWhite: themeColours.textColourOnWhite
|
|
|
|
}}
|
|
|
|
/>
|
2017-05-07 17:45:44 +00:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
2017-11-13 14:50:48 +00:00
|
|
|
|
|
|
|
buildStep = ({ unfolded }) => accessor => question => {
|
|
|
|
let step = makeQuestion(rules)(question)
|
|
|
|
return (
|
|
|
|
<step.component
|
|
|
|
key={step.name}
|
|
|
|
{...step}
|
|
|
|
unfolded={unfolded}
|
|
|
|
step={step}
|
|
|
|
answer={accessor(step.name)}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
2017-05-07 17:45:44 +00:00
|
|
|
}
|