From 0d8c3163e31615e8e553eeef7fbe218299b7d194 Mon Sep 17 00:00:00 2001 From: Jalil Arfaoui Date: Thu, 30 May 2024 22:24:36 +0200 Subject: [PATCH] fix: La conversation repasse sur les questions des objectifs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit filtre les objectifs exclusifs et la liste noire des réponses enregistrées --- .../engine/détermineLesProchainesQuestions.ts | 4 +++- .../domaine/estObjectifExclusifDeLaSimulation.ts | 8 ++++++++ site/source/domaine/estQuestionEnListeNoire.ts | 10 ++++++++++ .../auto-entrepreneur/simulationConfig.ts | 1 - site/source/store/reducers/simulation.reducer.ts | 13 ++++++++++--- 5 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 site/source/domaine/estObjectifExclusifDeLaSimulation.ts create mode 100644 site/source/domaine/estQuestionEnListeNoire.ts diff --git a/site/source/domaine/engine/détermineLesProchainesQuestions.ts b/site/source/domaine/engine/détermineLesProchainesQuestions.ts index ccd9528f7..c1e5027c8 100644 --- a/site/source/domaine/engine/détermineLesProchainesQuestions.ts +++ b/site/source/domaine/engine/détermineLesProchainesQuestions.ts @@ -42,7 +42,9 @@ export const détermineLesProchainesQuestions = ( filter( (step) => (!liste.length || liste.some((name) => step.startsWith(name))) && - (!listeNoire.length || !listeNoire.some((name) => step === name)) + (!listeNoire.length || !listeNoire.some((name) => step === name)) && + (!config['objectifs exclusifs']?.length || + !config['objectifs exclusifs'].includes(step)) ), sort((a: DottedName, b: DottedName) => Order.number(score(a), score(b))), filter( diff --git a/site/source/domaine/estObjectifExclusifDeLaSimulation.ts b/site/source/domaine/estObjectifExclusifDeLaSimulation.ts new file mode 100644 index 000000000..4b8873215 --- /dev/null +++ b/site/source/domaine/estObjectifExclusifDeLaSimulation.ts @@ -0,0 +1,8 @@ +import { DottedName } from 'modele-social' + +import { SimulationConfig } from '@/domaine/SimulationConfig' + +export const estObjectifExclusifDeLaSimulation = + (config: SimulationConfig) => + (question: DottedName): boolean => + config['objectifs exclusifs']?.includes(question) ?? false diff --git a/site/source/domaine/estQuestionEnListeNoire.ts b/site/source/domaine/estQuestionEnListeNoire.ts new file mode 100644 index 000000000..896eb6d8c --- /dev/null +++ b/site/source/domaine/estQuestionEnListeNoire.ts @@ -0,0 +1,10 @@ +import { DottedName } from 'modele-social' + +import { SimulationConfig } from '@/domaine/SimulationConfig' + +export const estQuestionEnListeNoire = + (config: SimulationConfig) => + (question: DottedName): boolean => + config.questions?.['liste noire']?.some((préfixe) => + question.startsWith(préfixe) + ) ?? false diff --git a/site/source/pages/simulateurs/auto-entrepreneur/simulationConfig.ts b/site/source/pages/simulateurs/auto-entrepreneur/simulationConfig.ts index 42cd079e3..3bb33d7c3 100644 --- a/site/source/pages/simulateurs/auto-entrepreneur/simulationConfig.ts +++ b/site/source/pages/simulateurs/auto-entrepreneur/simulationConfig.ts @@ -39,7 +39,6 @@ export const configAutoEntrepreneur: SimulationConfig = { ], 'non prioritaires': ['établissement . commune'], 'liste noire': [ - 'entreprise . activités', 'entreprise . activités . revenus mixtes', 'entreprise . charges', "entreprise . chiffre d'affaires", diff --git a/site/source/store/reducers/simulation.reducer.ts b/site/source/store/reducers/simulation.reducer.ts index cf4075555..86f9e0d8d 100644 --- a/site/source/store/reducers/simulation.reducer.ts +++ b/site/source/store/reducers/simulation.reducer.ts @@ -1,5 +1,7 @@ import { DottedName } from 'modele-social' +import { estObjectifExclusifDeLaSimulation } from '@/domaine/estObjectifExclusifDeLaSimulation' +import { estQuestionEnListeNoire } from '@/domaine/estQuestionEnListeNoire' import { SimulationConfig } from '@/domaine/SimulationConfig' import { Situation } from '@/domaine/Situation' import { updateSituation } from '@/domaine/updateSituation' @@ -55,11 +57,16 @@ export function simulationReducer( } case 'ENREGISTRE_LA_RÉPONSE': { - const answeredQuestions = state.answeredQuestions.includes( + const déjàDansLesQuestionsRépondues = state.answeredQuestions.includes( action.fieldName ) - ? state.answeredQuestions - : [...state.answeredQuestions, action.fieldName] + + const answeredQuestions = + déjàDansLesQuestionsRépondues || + estQuestionEnListeNoire(state.config)(action.fieldName) || + estObjectifExclusifDeLaSimulation(state.config)(action.fieldName) + ? state.answeredQuestions + : [...state.answeredQuestions, action.fieldName] return { ...state,