diff --git a/source/actions/actions.js b/source/actions/actions.js index 395706a18..ea25b89e7 100644 --- a/source/actions/actions.js +++ b/source/actions/actions.js @@ -8,7 +8,7 @@ import type { SetSituationBranchAction } from 'Types/ActionsTypes' // $FlowFixMe -import { clearFields, reset } from 'redux-form' +import { change, reset } from 'redux-form' import { deletePersistedSimulation } from '../storage/persistSimulation' import type { Thunk } from 'Types/ActionsTypes' @@ -25,14 +25,15 @@ export const goToQuestion = (question: string): StepAction => ({ name: 'unfold', step: question }) -export const skipQuestion = ( - question: string +export const validateStepWithValue = ( + dottedName, + value: any ): Thunk => dispatch => { - dispatch(clearFields('conversation', false, false, question)) + dispatch(change('conversation', dottedName, value)) dispatch({ type: 'STEP_ACTION', name: 'fold', - step: question + step: dottedName }) } diff --git a/source/components/Distribution.js b/source/components/Distribution.js index 1fab70429..aa9d7b3cf 100644 --- a/source/components/Distribution.js +++ b/source/components/Distribution.js @@ -113,17 +113,17 @@ class Distribution extends Component {
- + + Cotisations - + {total.partPatronale + total.partSalariale}
= - +
) @@ -154,7 +154,7 @@ let ChartItemBar = ({ styles, colour, montant, total }) => ( margin-left: 1em; color: var(--textColourOnWhite); `}> - + {montant}
diff --git a/source/components/PeriodSwitch.js b/source/components/PeriodSwitch.js index d536666e6..a03983edb 100644 --- a/source/components/PeriodSwitch.js +++ b/source/components/PeriodSwitch.js @@ -52,8 +52,8 @@ export default compose( return }) return ( -
-
+ + -
-
+ + ) }) diff --git a/source/components/SchemeComparaison.js b/source/components/SchemeComparaison.js index 5fe06573b..d13cdc5e3 100644 --- a/source/components/SchemeComparaison.js +++ b/source/components/SchemeComparaison.js @@ -626,7 +626,7 @@ const RuleValueLink = compose( sitePaths.documentation.index + '/' + encodeRuleName(rule.dottedName) }> (value, language) => +export let numberFormatter = ({ + style, + maximumFractionDigits, + minimumFractionDigits = 0, + language +}) => value => NumberFormat(language, { style, currency: 'EUR', - maximumFractionDigits: numFractionDigits, - minimumFractionDigits: numFractionDigits + maximumFractionDigits, + minimumFractionDigits }).format(value) // let booleanTranslations = { true: '✅', false: '❌' } @@ -34,7 +39,8 @@ export default withLanguage( nodeValue: value, unit, nilValueSymbol, - numFractionDigits, + maximumFractionDigits, + minimumFractionDigits, children, negative, language, @@ -63,11 +69,24 @@ export default withLanguage( nodeValue.nom ) : valueType === 'boolean' ? ( booleanTranslations[language][nodeValue] - ) : unit === '€' ? ( - numberFormatter('currency', numFractionDigits)(nodeValue, language) + ) : unitText === '€' ? ( + numberFormatter({ + style: 'currency', + maximumFractionDigits, + minimumFractionDigits, + language + })(nodeValue) + ) : unitText === '%' ? ( + numberFormatter({ style: 'percent', maximumFractionDigits: 3 })( + nodeValue + ) ) : ( <> - {numberFormatter('decimal', numFractionDigits)(nodeValue)} + {numberFormatter({ + style: 'decimal', + minimumFractionDigits, + maximumFractionDigits + })(nodeValue)}   {unitText} diff --git a/source/components/conversation/Conversation.js b/source/components/conversation/Conversation.js index 70847684e..42e0547ff 100644 --- a/source/components/conversation/Conversation.js +++ b/source/components/conversation/Conversation.js @@ -1,4 +1,8 @@ -import { goToQuestion, resetSimulation, skipQuestion } from 'Actions/actions' +import { + goToQuestion, + resetSimulation, + validateStepWithValue +} from 'Actions/actions' import { T } from 'Components' import QuickLinks from 'Components/QuickLinks' import { getInputComponent } from 'Engine/generateQuestions' @@ -15,6 +19,7 @@ import { import * as Animate from 'Ui/animate' import Aide from './Aide' import './conversation.css' +import { findRuleByDottedName } from 'Engine/rules' export default compose( reduxForm({ @@ -28,7 +33,7 @@ export default compose( previousAnswers: state.conversationSteps.foldedSteps, nextSteps: nextStepsSelector(state) }), - { resetSimulation, skipQuestion, goToQuestion } + { resetSimulation, validateStepWithValue, goToQuestion } ) )(function Conversation({ nextSteps, @@ -37,14 +42,18 @@ export default compose( customEndMessages, flatRules, resetSimulation, - skipQuestion, - goToQuestion + goToQuestion, + validateStepWithValue }) { - const goToNext = () => skipQuestion(nextSteps[0]) + const setDefault = () => + validateStepWithValue( + currentQuestion, + findRuleByDottedName(flatRules, currentQuestion).defaultValue + ) const goToPrevious = () => goToQuestion(previousAnswers.slice(-1)[0]) const handleKeyDown = ({ key }) => { if (['Escape'].includes(key)) { - goToNext() + setDefault() } } return nextSteps.length ? ( @@ -67,7 +76,7 @@ export default compose( )} diff --git a/source/components/conversation/FormDecorator.js b/source/components/conversation/FormDecorator.js index 6afc10a29..87a0555d2 100644 --- a/source/components/conversation/FormDecorator.js +++ b/source/components/conversation/FormDecorator.js @@ -35,12 +35,25 @@ export var FormDecorator = formType => RenderField => helpVisible: false } render() { - let { stepAction, fieldName, inversion, setFormValue } = this.props + let { + stepAction, + fieldName, + inversion, + setFormValue, + unit + } = this.props let submit = cause => stepAction('fold', fieldName, cause), stepProps = { ...this.props, submit, - setFormValue: (value, name = fieldName) => setFormValue(name, value) + setFormValue: (value, name = fieldName) => + setFormValue(name, value), + ...(unit === '%' + ? { + format: x => (x == null ? null : x * 100), + normalize: x => (x == null ? null : x / 100) + } + : {}) } return ( diff --git a/source/components/conversation/Input.js b/source/components/conversation/Input.js index 7319ff83a..be4fd7eb2 100644 --- a/source/components/conversation/Input.js +++ b/source/components/conversation/Input.js @@ -55,7 +55,6 @@ export default compose( /> {suffixed && (