Passer donne la valeur par défaut, pas null

Fixes #610
pull/603/head
Mael 2019-08-03 15:30:19 +02:00
parent 18cbe0623f
commit f0dd2ca416
2 changed files with 22 additions and 12 deletions

View File

@ -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<StepAction> => dispatch => {
dispatch(clearFields('conversation', false, false, question))
dispatch(change('conversation', dottedName, value))
dispatch({
type: 'STEP_ACTION',
name: 'fold',
step: question
step: dottedName
})
}

View File

@ -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(
</>
)}
<button
onClick={goToNext}
onClick={setDefault}
className="ui__ simple small skip button right">
Passer
</button>