From 5cf1affad98a0b2afb3589d4d6939507aa244a7e Mon Sep 17 00:00:00 2001 From: Chukwudumebi Onwuli <37223065+deeonwuli@users.noreply.github.com> Date: Thu, 19 Dec 2024 20:39:06 +0100 Subject: [PATCH] fix: remove repeatable program stage --- .../usecases/RemoveRepeatableProgramStageUseCase.ts | 10 ++++------ src/webapp/components/survey/hook/useSurveyForm.ts | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/domain/usecases/RemoveRepeatableProgramStageUseCase.ts b/src/domain/usecases/RemoveRepeatableProgramStageUseCase.ts index db9b9ec..5aa0080 100644 --- a/src/domain/usecases/RemoveRepeatableProgramStageUseCase.ts +++ b/src/domain/usecases/RemoveRepeatableProgramStageUseCase.ts @@ -11,17 +11,15 @@ export class RemoveRepeatableProgramStageUseCase { //Repeatable Program Stages are only applicable to Prevalence Facility forms const eventId = questionnaire.stages.find(stage => stage.id === stageId)?.instanceId; + const updatedQuestionnaire = Questionnaire.removeProgramStage(questionnaire, stageId); - if (!eventId) - return Future.error(new Error("Cannot find event Id correspoding to the stage")); + if (!eventId) { + return Future.success(updatedQuestionnaire); + } return this.surveyRepository .deleteEventSurvey(eventId, questionnaire.orgUnit.id, PREVALENCE_FACILITY_LEVEL_FORM_ID) .flatMap(() => { - const updatedQuestionnaire = Questionnaire.removeProgramStage( - questionnaire, - stageId - ); return Future.success(updatedQuestionnaire); }); } diff --git a/src/webapp/components/survey/hook/useSurveyForm.ts b/src/webapp/components/survey/hook/useSurveyForm.ts index a7b6ce6..44538f4 100644 --- a/src/webapp/components/survey/hook/useSurveyForm.ts +++ b/src/webapp/components/survey/hook/useSurveyForm.ts @@ -195,7 +195,7 @@ export function useSurveyForm(formType: SURVEY_FORM_TYPES, eventId: string | und }, err => { setLoading(false); - setError(err.message); + setError(`Cannot find event Id correspoding to the stage: ${err.message}`); } ); }