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-24 09:33:50 +00:00
|
|
|
import { reset, change, formValueSelector } from 'redux-form'
|
2017-11-13 14:50:48 +00:00
|
|
|
import { connect } from 'react-redux'
|
2017-11-24 09:33:50 +00:00
|
|
|
import { withRouter } from 'react-router-dom'
|
2017-07-02 17:12:02 +00:00
|
|
|
|
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-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-11-15 10:12:58 +00:00
|
|
|
import Results from 'Components/Results'
|
|
|
|
|
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-16 09:43:36 +00:00
|
|
|
situationGate: state.situationGate,
|
2017-11-21 19:52:05 +00:00
|
|
|
targetNames: state.targetNames,
|
|
|
|
inputInversions: formValueSelector('conversation')(state, 'inversions')
|
2017-04-18 17:37:38 +00:00
|
|
|
}),
|
|
|
|
dispatch => ({
|
2017-11-15 10:12:58 +00:00
|
|
|
startConversation: targetNames =>
|
2017-11-24 09:33:50 +00:00
|
|
|
dispatch({ type: START_CONVERSATION, targetNames }),
|
|
|
|
resetForm: () => dispatch(reset('conversation')),
|
|
|
|
resetFormField: name => dispatch(change('conversation', name, ''))
|
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-24 09:33:50 +00:00
|
|
|
let {
|
|
|
|
match: { params: { targets: encodedTargets } },
|
|
|
|
targetNames: pastTargetNames,
|
|
|
|
resetFormField
|
|
|
|
} = this.props,
|
2017-11-15 10:12:58 +00:00
|
|
|
targetNames = encodedTargets.split('+').map(decodeRuleName)
|
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))
|
2017-04-18 17:37:38 +00:00
|
|
|
|
2017-11-24 09:33:50 +00:00
|
|
|
this.targetRules.map(({ dottedName }) => resetFormField(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
|
2017-11-24 09:33:50 +00:00
|
|
|
if (
|
|
|
|
this.props.foldedSteps.length === 0 ||
|
|
|
|
!R.equals(targetNames, pastTargetNames)
|
|
|
|
)
|
2017-11-17 12:06:24 +00:00
|
|
|
this.props.startConversation(targetNames)
|
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,
|
2017-11-16 09:43:36 +00:00
|
|
|
themeColours,
|
2017-11-21 19:52:05 +00:00
|
|
|
targetNames,
|
|
|
|
inputInversions
|
2017-11-13 14:50:48 +00:00
|
|
|
} = 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-15 10:12:58 +00:00
|
|
|
this.props.startConversation(this.targets)
|
2017-11-13 14:50:48 +00:00
|
|
|
}
|
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-24 09:33:50 +00:00
|
|
|
<title>
|
|
|
|
Simulateur d'embauche :{' '}
|
|
|
|
{R.pluck('title', this.targetRules).join(', ')}
|
|
|
|
</title>
|
|
|
|
<meta
|
|
|
|
name="description"
|
|
|
|
content={R.pluck('description', this.targetRules).join(' - ')}
|
|
|
|
/>
|
2017-05-19 09:25:13 +00:00
|
|
|
</Helmet>
|
2017-11-15 10:12:58 +00:00
|
|
|
<Results />
|
2017-11-13 14:50:48 +00:00
|
|
|
<Conversation
|
|
|
|
{...{
|
|
|
|
reinitalise,
|
|
|
|
currentQuestion:
|
|
|
|
currentQuestion &&
|
2017-11-24 09:33:50 +00:00
|
|
|
this.buildStep({ unfolded: true })(
|
|
|
|
situationGate,
|
|
|
|
targetNames,
|
|
|
|
inputInversions
|
|
|
|
)(currentQuestion),
|
2017-11-13 14:50:48 +00:00
|
|
|
foldedSteps: R.map(
|
2017-11-24 09:33:50 +00:00
|
|
|
this.buildStep({ unfolded: false })(
|
|
|
|
situationGate,
|
|
|
|
targetNames,
|
|
|
|
inputInversions
|
|
|
|
),
|
2017-11-13 14:50:48 +00:00
|
|
|
foldedSteps
|
|
|
|
),
|
|
|
|
extraSteps: R.map(
|
2017-11-24 09:33:50 +00:00
|
|
|
this.buildStep({ unfolded: true })(
|
|
|
|
situationGate,
|
|
|
|
targetNames,
|
|
|
|
inputInversions
|
|
|
|
),
|
2017-11-13 14:50:48 +00:00
|
|
|
extraSteps
|
|
|
|
),
|
|
|
|
textColourOnWhite: themeColours.textColourOnWhite
|
|
|
|
}}
|
|
|
|
/>
|
2017-05-07 17:45:44 +00:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
2017-11-13 14:50:48 +00:00
|
|
|
|
2017-11-24 09:33:50 +00:00
|
|
|
buildStep = ({ unfolded }) => (
|
|
|
|
situationGate,
|
|
|
|
targetNames,
|
|
|
|
inputInversions
|
|
|
|
) => question => {
|
2017-11-16 09:43:36 +00:00
|
|
|
let step = makeQuestion(rules, targetNames)(question)
|
2017-11-21 18:05:45 +00:00
|
|
|
|
2017-11-24 09:33:50 +00:00
|
|
|
let fieldName =
|
|
|
|
(unfolded &&
|
|
|
|
inputInversions &&
|
|
|
|
R.path(step.name.split('.'), inputInversions)) ||
|
|
|
|
step.name
|
2017-11-21 18:05:45 +00:00
|
|
|
|
2017-11-13 14:50:48 +00:00
|
|
|
return (
|
|
|
|
<step.component
|
|
|
|
key={step.name}
|
|
|
|
{...step}
|
|
|
|
unfolded={unfolded}
|
|
|
|
step={step}
|
2017-11-21 09:06:30 +00:00
|
|
|
situationGate={situationGate}
|
2017-11-21 18:05:45 +00:00
|
|
|
fieldName={fieldName}
|
2017-11-23 17:36:00 +00:00
|
|
|
inverted={step.name !== fieldName}
|
2017-11-13 14:50:48 +00:00
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
2017-05-07 17:45:44 +00:00
|
|
|
}
|