diff --git a/source/components/conversation/FormDecorator.js b/source/components/conversation/FormDecorator.js index f477c6c2c..1db92d615 100644 --- a/source/components/conversation/FormDecorator.js +++ b/source/components/conversation/FormDecorator.js @@ -75,11 +75,11 @@ export var FormDecorator = formType => RenderField => props passées à ce dernier, car React 15.2 n'aime pas les attributes inconnus des balises html, dans notre cas. */ + //TODO hack, enables redux-form/CHANGE to update the form state before the traverse functions are run let submit = () => setTimeout(() => stepAction('fold', fieldName), 1), stepProps = { ...this.props.step, inverted, - //TODO hack, enables redux-form/CHANGE to update the form state before the traverse functions are run submit, setFormValue: (value, name = fieldName) => setFormValue(name, value) } diff --git a/source/reducers.js b/source/reducers.js index 4286eaf52..319f34bd2 100644 --- a/source/reducers.js +++ b/source/reducers.js @@ -50,10 +50,17 @@ export let reduceSteps = (tracker, flatRules, answerSource) => ( // Optimization - don't parse on each analysis if (!state.parsedRules) state.parsedRules = parseAll(flatRules) - if (![START_CONVERSATION, STEP_ACTION].includes(action.type)) return state + if ( + ![START_CONVERSATION, STEP_ACTION, '@@redux-form/CHANGE'].includes( + action.type + ) + ) + return state let targetNames = - action.type == START_CONVERSATION ? action.targetNames : state.targetNames + action.type == START_CONVERSATION + ? action.targetNames + : state.targetNames || [] let sim = targetNames.length === 1 ? findRuleByName(flatRules, targetNames[0]) : {}, @@ -66,9 +73,14 @@ export let reduceSteps = (tracker, flatRules, answerSource) => ( situationWithDefaults = assume(intermediateSituation, rulesDefaults) let analysis = analyseMany(state.parsedRules, targetNames)( - situationWithDefaults(state) - ), - nextWithDefaults = getNextSteps(situationWithDefaults(state), analysis), + situationWithDefaults(state) + ) + + if (action.type === '@@redux-form/CHANGE') { + return { ...state, analysis, situationGate: situationWithDefaults(state) } + } + + let nextWithDefaults = getNextSteps(situationWithDefaults(state), analysis), assumptionsMade = !isEmpty(rulesDefaults), done = nextWithDefaults.length == 0