import R from 'ramda' import React, {Component} from 'react' import Helmet from 'react-helmet' import {reset} from 'redux-form' import {connect} from 'react-redux' import {Redirect, Link, withRouter} from 'react-router-dom' import classNames from 'classnames' import {START_CONVERSATION} from '../actions' import {createMarkdownDiv} from 'Engine/marked' import {rules, findRuleByName, decodeRuleName} from 'Engine/rules' import './conversation/conversation.css' import './Simulateur.css' import {capitalise0} from '../utils' import Conversation from './conversation/Conversation' import {makeQuestion} from 'Engine/generateQuestions' import ReactPiwik from './Tracker' @withRouter @connect( state => ({ currentQuestion: state.currentQuestion, foldedSteps: state.foldedSteps, extraSteps: state.extraSteps, themeColours: state.themeColours, analysedSituation: state.analysedSituation, situationGate: state.situationGate, }), dispatch => ({ startConversation: rootVariable => dispatch({type: START_CONVERSATION, rootVariable}), resetForm: () => dispatch(reset('conversation')) }) ) export default class extends Component { state = { started: false } componentWillMount() { let { match: { params: { name: encodedName } } } = this.props, name = decodeRuleName(encodedName), existingConversation = this.props.foldedSteps.length > 0 this.encodedName = encodedName this.name = name this.rule = findRuleByName(rules, name) // C'est ici que la génération du formulaire, et donc la traversée des variables commence if (!existingConversation) this.props.startConversation(name) } render(){ if (!this.rule.formule) return let {started} = this.state, {foldedSteps, extraSteps, currentQuestion, situationGate, themeColours} = this.props, sim = path => R.path(R.unless(R.is(Array), R.of)(path))(this.rule.simulateur || {}), reinitalise = () => { ReactPiwik.push(['trackEvent', 'restart', '']) this.props.resetForm(this.name) this.props.startConversation(this.name) }, title = sim('titre') || capitalise0(this.rule['titre'] || this.rule['nom']) let buildAnyStep = unfolded => accessor => question => { let step = makeQuestion(rules)(question) return } let buildStep = buildAnyStep(false) let buildUnfoldedStep = buildAnyStep(true) return (
{title} {sim('sous-titre') && }

{title}

{sim('sous-titre') &&
{sim('sous-titre')}
} {!started && sim(['introduction', 'notes']) &&
{sim(['introduction', 'notes']).map( ({icône, texte, titre}) =>
{texte}
)}
} { (started || !sim(['introduction', 'notes'])) && }
) } }