mon-entreprise/source/components/SimpleSimulation.js

81 lines
2.2 KiB
JavaScript
Raw Normal View History

import Answers from 'Components/AnswerList'
import Conversation from 'Components/conversation/Conversation'
import { ScrollToElement } from 'Components/utils/Scroll'
import withColours from 'Components/utils/withColours'
import { compose, isEmpty } from 'ramda'
import React from 'react'
import { connect } from 'react-redux'
import {
nextStepsSelector,
2019-01-17 14:34:44 +00:00
noUserInputSelector,
blockingInputControlsSelector,
validInputEnteredSelector
} from 'Selectors/analyseSelectors'
import Animate from 'Ui/animate'
export default compose(
withColours,
connect(state => ({
2019-01-17 14:34:44 +00:00
conversationStarted: state.conversationStarted,
previousAnswers: state.conversationSteps.foldedSteps,
noNextSteps: nextStepsSelector(state).length == 0,
2019-01-17 14:34:44 +00:00
noUserInput: noUserInputSelector(state),
blockingInputControls: blockingInputControlsSelector(state),
validInputEntered: validInputEnteredSelector(state)
}))
)(
2019-01-17 14:34:44 +00:00
class Simulation extends React.Component {
state = {
displayAnswers: false
}
render() {
let {
noNextSteps,
previousAnswers,
noUserInput,
2019-01-17 14:34:44 +00:00
conversationStarted,
hideUntilUserInput,
blockingInputControls
} = this.props
2019-01-17 14:34:44 +00:00
let arePreviousAnswers = previousAnswers.length > 0,
displayConversation = conversationStarted && !blockingInputControls
return (
<>
{this.state.displayAnswers && (
<Answers onClose={() => this.setState({ displayAnswers: false })} />
)}
{!isEmpty(previousAnswers) && (
<button
className="ui__ button small plain"
2019-01-17 14:34:44 +00:00
style={{
visibility: arePreviousAnswers ? 'visible' : 'hidden'
}}>
onClick={() => this.setState({ displayAnswers: true })}> Mes
réponses
</button>
)}
2019-01-17 14:34:44 +00:00
{displayConversation && (
<>
<Conversation
textColourOnWhite={this.props.colours.textColourOnWhite}
/>
{noNextSteps && (
<>
<h2>Plus de questions ! </h2>
<p>Vous avez atteint l'estimation la plus précise.</p>
{this.props.customEndMessage && (
<p>{this.props.customEndMessage}</p>
)}
</>
)}
</>
)}
<Animate.fromBottom>{this.props.targets}</Animate.fromBottom>
{!noUserInput && this.props.explication}
</>
)
}
}
)