2018-11-09 11:36:29 +00:00
|
|
|
|
import { hideControl, startConversation } from 'Actions/actions'
|
|
|
|
|
import withLanguage from 'Components/utils/withLanguage'
|
|
|
|
|
import { makeJsx } from 'Engine/evaluation'
|
|
|
|
|
import { createMarkdownDiv } from 'Engine/marked'
|
|
|
|
|
import { compose } from 'ramda'
|
2018-06-29 16:14:00 +00:00
|
|
|
|
import React from 'react'
|
2018-09-11 14:14:46 +00:00
|
|
|
|
import emoji from 'react-easy-emoji'
|
|
|
|
|
import { connect } from 'react-redux'
|
2018-11-09 11:36:29 +00:00
|
|
|
|
import './Controls.css'
|
2018-10-02 14:52:27 +00:00
|
|
|
|
import withColours from './utils/withColours'
|
2018-09-12 17:12:59 +00:00
|
|
|
|
|
|
|
|
|
function Controls({
|
|
|
|
|
blockingInputControls,
|
|
|
|
|
controls,
|
|
|
|
|
startConversation,
|
2018-10-02 16:14:01 +00:00
|
|
|
|
hideControl,
|
2018-10-02 14:52:27 +00:00
|
|
|
|
foldedSteps,
|
2018-10-02 16:14:01 +00:00
|
|
|
|
colours,
|
2018-10-04 13:55:52 +00:00
|
|
|
|
hiddenControls,
|
|
|
|
|
language
|
2018-09-12 17:12:59 +00:00
|
|
|
|
}) {
|
2018-10-04 13:55:52 +00:00
|
|
|
|
/* TODO controls are not translated yet, since our translation system doesn't handle nested yaml properties of base.yaml */
|
|
|
|
|
if (language === 'en')
|
|
|
|
|
return blockingInputControls?.[0]?.message ==
|
|
|
|
|
'Entrez un salaire mensuel' ? (
|
|
|
|
|
<p className="blockingControl">
|
|
|
|
|
Enter a <b>monthly</b> salary.
|
|
|
|
|
</p>
|
|
|
|
|
) : null
|
|
|
|
|
|
2018-09-11 14:14:46 +00:00
|
|
|
|
return (
|
2018-09-11 15:33:11 +00:00
|
|
|
|
<div id="controlsBlock">
|
2018-09-11 14:14:46 +00:00
|
|
|
|
{blockingInputControls && (
|
2018-09-11 16:45:54 +00:00
|
|
|
|
<p className="blockingControl">{blockingInputControls[0].message}</p>
|
|
|
|
|
)}
|
2018-10-02 14:52:27 +00:00
|
|
|
|
{!blockingInputControls && (
|
|
|
|
|
<>
|
|
|
|
|
<ul>
|
2018-10-02 16:14:01 +00:00
|
|
|
|
{controls.map(
|
|
|
|
|
({ level, test, message, solution, evaluated }) =>
|
|
|
|
|
hiddenControls.includes(test) ? null : (
|
|
|
|
|
<li
|
|
|
|
|
key={test}
|
|
|
|
|
className="control"
|
2018-11-09 11:36:29 +00:00
|
|
|
|
style={{
|
|
|
|
|
background: colours.lighterColour
|
|
|
|
|
}}>
|
2018-10-02 14:52:27 +00:00
|
|
|
|
{emoji(level == 'avertissement' ? '⚠️' : 'ℹ️')}
|
|
|
|
|
<div className="controlText">
|
|
|
|
|
{message && createMarkdownDiv(message)}
|
|
|
|
|
{!message && (
|
|
|
|
|
<span id="controlExplanation">
|
|
|
|
|
{makeJsx(evaluated)}
|
|
|
|
|
</span>
|
2018-09-13 13:55:55 +00:00
|
|
|
|
)}
|
2018-10-02 14:52:27 +00:00
|
|
|
|
{solution &&
|
|
|
|
|
!foldedSteps.includes(solution.cible) && (
|
|
|
|
|
<div id="solution">
|
|
|
|
|
{/*emoji('💡')*/}
|
|
|
|
|
<button
|
|
|
|
|
key={solution.cible}
|
|
|
|
|
className="ui__ link-button"
|
|
|
|
|
onClick={() => startConversation(solution.cible)}>
|
|
|
|
|
{solution.texte}
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
2018-10-02 16:28:56 +00:00
|
|
|
|
<button
|
|
|
|
|
className="hide"
|
|
|
|
|
aria-label="close"
|
|
|
|
|
onClick={() => hideControl(test)}>
|
|
|
|
|
×
|
|
|
|
|
</button>
|
2018-10-02 16:14:01 +00:00
|
|
|
|
</li>
|
|
|
|
|
)
|
|
|
|
|
)}
|
2018-10-02 14:52:27 +00:00
|
|
|
|
</ul>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
2018-09-11 14:14:46 +00:00
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-09 11:36:29 +00:00
|
|
|
|
export default compose(
|
|
|
|
|
connect(
|
|
|
|
|
(state, props) => ({
|
|
|
|
|
foldedSteps: state.conversationSteps.foldedSteps,
|
|
|
|
|
key: props.language,
|
|
|
|
|
hiddenControls: state.hiddenControls
|
|
|
|
|
}),
|
|
|
|
|
dispatch => ({
|
|
|
|
|
startConversation: cible => dispatch(startConversation(cible)),
|
|
|
|
|
hideControl: id => dispatch(hideControl(id))
|
|
|
|
|
})
|
|
|
|
|
),
|
|
|
|
|
withColours,
|
|
|
|
|
withLanguage
|
|
|
|
|
)(Controls)
|