mon-entreprise/source/components/Controls.js

79 lines
2.2 KiB
JavaScript
Raw Normal View History

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'
import React from 'react'
import emoji from 'react-easy-emoji'
import { connect } from 'react-redux'
2019-04-03 09:16:09 +00:00
import animate from 'Ui/animate'
import './Controls.css'
2018-10-02 14:52:27 +00:00
import withColours from './utils/withColours'
function Controls({
controls,
startConversation,
2018-10-02 16:14:01 +00:00
hideControl,
2018-10-02 14:52:27 +00:00
foldedSteps,
hiddenControls,
language
}) {
if (!controls?.length) return null
/* TODO controls are not translated yet, since our translation system doesn't handle nested yaml properties of base.yaml */
if (language === 'en') return null
return (
2018-09-11 15:33:11 +00:00
<div id="controlsBlock">
2019-04-03 09:16:09 +00:00
<ul style={{ margin: 0, padding: 0 }}>
{controls.map(({ level, test, message, solution, evaluated }) =>
hiddenControls.includes(test) ? null : (
2019-04-03 09:16:09 +00:00
<li key={test}>
<animate.appear className="control">
{emoji(level == 'avertissement' ? '⚠️' : '')}
<div className="controlText ui__ card">
{message ? (
createMarkdownDiv(message)
) : (
<span id="controlExplanation">{makeJsx(evaluated)}</span>
)}
2019-04-03 09:16:09 +00:00
{solution && !foldedSteps.includes(solution.cible) && (
<div>
<button
key={solution.cible}
className="ui__ link-button"
onClick={() => startConversation(solution.cible)}>
{solution.texte}
</button>
</div>
)}
<button
className="hide"
aria-label="close"
onClick={() => hideControl(test)}>
×
</button>
</div>
</animate.appear>
</li>
)
)}
</ul>
</div>
)
}
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)