Première intégration des contrôles

Un contrôle sur chaque salaire, pour éviter de lancer le moteur sur des
inversions qui n'ont pas de sens.
pull/269/head
Mael 2018-06-29 16:14:00 +00:00
parent 8cebf7240b
commit 6512b04b7a
6 changed files with 82 additions and 30 deletions

View File

@ -0,0 +1,4 @@
.controls {
text-align: center;
font-size: 150%;
}

View File

@ -0,0 +1,6 @@
import React from 'react'
import './Controls.css'
export default ({ blockingInputControls }) => (
<p className="controls">{blockingInputControls[0].message}</p>
)

View File

@ -1,6 +1,9 @@
import React, { Component } from 'react'
import { connect } from 'react-redux'
import { noUserInputSelector } from 'Selectors/analyseSelectors'
import {
noUserInputSelector,
analysisWithDefaultsSelector
} from 'Selectors/analyseSelectors'
import Conversation from './conversation/Conversation'
import FoldedSteps, { GoToAnswers } from './conversation/FoldedSteps'
import GoToExplanations from './GoToExplanations'
@ -14,11 +17,17 @@ import withColours from './withColours'
@withColours
@connect(state => ({
noUserInput: noUserInputSelector(state),
analysis: analysisWithDefaultsSelector(state),
conversationStarted: state.conversationStarted
}))
export default class Simu extends Component {
render() {
let { colours, conversationStarted, noUserInput } = this.props
let {
colours,
conversationStarted,
noUserInput,
analysis: { blockingInputControls }
} = this.props
return (
<div id="simu">
@ -32,10 +41,10 @@ export default class Simu extends Component {
<Conversation textColourOnWhite={colours.textColourOnWhite} />
</>
)}
{!noUserInput && <GoToExplanations />}
{!noUserInput && !blockingInputControls && <GoToExplanations />}
</div>
{!noUserInput && <ResultView />}
<Sondage />
{!noUserInput && !blockingInputControls && <ResultView />}
{!blockingInputControls && <Sondage />}
</div>
)
}

View File

@ -18,6 +18,7 @@ import ProgressCircle from './ProgressCircle/ProgressCircle'
import { RuleValue } from './rule/RuleValueVignette'
import './TargetSelection.css'
import withLanguage from './withLanguage'
import Controls from './Controls'
let salaries = [
'contrat salarié . salaire . total',
@ -55,7 +56,7 @@ export let popularTargetNames = [
)
export default class TargetSelection extends Component {
render() {
let { conversationStarted, colours, noUserInput } = this.props
let { conversationStarted, colours, noUserInput, analysis } = this.props
return (
<div id="targetSelection">
<section
@ -67,12 +68,18 @@ export default class TargetSelection extends Component {
{this.renderOutputList()}
</section>
{noUserInput && (
<h1>
<p className="controls">
<Trans i18nKey="enterSalary">Entrez un salaire mensuel</Trans>
</h1>
</p>
)}
{analysis &&
analysis.blockingInputControls && (
<Controls blockingInputControls={analysis.blockingInputControls} />
)}
{!noUserInput &&
!(analysis && analysis.blockingInputControls) &&
!conversationStarted && (
<div id="action">
<p>
@ -122,7 +129,9 @@ export default class TargetSelection extends Component {
activeInput,
setActiveInput,
setFormValue: this.props.setFormValue,
noUserInput
noUserInput,
blockingInputControls:
analysis && analysis.blockingInputControls
}}
/>
</div>
@ -175,7 +184,15 @@ let CurrencyField = props => {
}
let TargetInputOrValue = withLanguage(
({ target, targets, activeInput, setActiveInput, language, noUserInput }) => (
({
target,
targets,
activeInput,
setActiveInput,
language,
noUserInput,
blockingInputControls
}) => (
<span className="targetInputOrValue">
{activeInput === target.dottedName ? (
<Field
@ -185,7 +202,14 @@ let TargetInputOrValue = withLanguage(
/>
) : (
<TargetValue
{...{ targets, target, activeInput, setActiveInput, noUserInput }}
{...{
targets,
target,
activeInput,
setActiveInput,
noUserInput,
blockingInputControls
}}
/>
)}
</span>
@ -200,28 +224,32 @@ let TargetInputOrValue = withLanguage(
class TargetValue extends Component {
render() {
let {
targets,
target,
setFormValue,
activeInput,
setActiveInput,
noUserInput
} = this.props,
targetWithValue = targets.find(propEq('dottedName', target.dottedName)),
targets,
target,
setFormValue,
activeInput,
setActiveInput,
noUserInput,
blockingInputControls
} = this.props
let targetWithValue =
targets && targets.find(propEq('dottedName', target.dottedName)),
value = targetWithValue && targetWithValue.nodeValue
return (
<span
className={classNames({
editable: target.question,
attractClick: target.question && noUserInput
attractClick:
target.question && (noUserInput || blockingInputControls)
})}
onClick={() => {
if (!target.question) return
if (value != null) {
if (value != null)
setFormValue(target.dottedName, Math.floor(value) + '')
setFormValue(activeInput, '')
}
if (activeInput) setFormValue(activeInput, '')
setActiveInput(target.dottedName)
}}>
<RuleValue value={value} />

View File

@ -194,10 +194,6 @@ export let treatRuleRoot = (rules, rule) => {
}
})(rule)
// let evaluateControl = () => {
//evaluate with situation
//return message or null
//}
let controls =
rule['contrôles'] &&
rule['contrôles'].map(control => {
@ -215,6 +211,7 @@ export let treatRuleRoot = (rules, rule) => {
return {
level: control['niveau'],
test: control['si'],
message: control['message'],
testExpression,
...(!otherVariables.length ? { isInputControl: true } : {})
}

View File

@ -677,12 +677,12 @@
salaire médian: 2300
SMIC: 1500
contrôles:
- si: brut de base < 300
message: Entrez un salaire mensuel
niveau: bloquant
# - si: brut de base < smic mensuel
# message: Le salaire saisi semble inférieur au SMIC.
# niveau: avertissement
- si: brut de base < 200
message: Le simulateur ne prend pour l'instant que des salaires mensuels
niveau: bloquant
- si: brut de base > 100000
message: N'avez-vous pas saisi un zéro de trop ?
niveau: information
@ -865,6 +865,10 @@
description: |
C'est le montant que le salarié touche à la fin du mois.
formule: salaire . net - avantages en nature . montant
contrôles:
- si: net à payer < 200
message: Entrez un salaire mensuel
niveau: bloquant
- espace: contrat salarié
nom: coût du travail
@ -891,6 +895,10 @@
Des [aides différées](/règle/aides employeur) peuvent venir diminuer ce montant.
formule: salaire . total sans réduction - réductions de cotisations
contrôles:
- si: total < 400
message: Entrez un salaire mensuel
niveau: bloquant
- espace: contrat salarié
nom: réductions de cotisations