From 4b0a04e70a95a208c3959af6d69efeda0c83823c Mon Sep 17 00:00:00 2001 From: 9sneha-n <9sneha.n@gmail.com> Date: Thu, 17 Oct 2024 12:56:17 +0530 Subject: [PATCH 1/6] fix: create event tracker fix --- .../disease-outbreak/SaveDiseaseOutbreak.ts | 9 ++++--- src/webapp/pages/form-page/useForm.ts | 27 +++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/domain/usecases/utils/disease-outbreak/SaveDiseaseOutbreak.ts b/src/domain/usecases/utils/disease-outbreak/SaveDiseaseOutbreak.ts index c43aee08..098de46c 100644 --- a/src/domain/usecases/utils/disease-outbreak/SaveDiseaseOutbreak.ts +++ b/src/domain/usecases/utils/disease-outbreak/SaveDiseaseOutbreak.ts @@ -17,12 +17,13 @@ export function saveDiseaseOutbreak( teamMemberRepository: TeamMemberRepository; roleRepository: RoleRepository; }, - diseaseOutbreakEventBaseAttrs: DiseaseOutbreakEventBaseAttrs + diseaseOutbreakEvent: DiseaseOutbreakEventBaseAttrs ): FutureData { return repositories.diseaseOutbreakEventRepository - .save(diseaseOutbreakEventBaseAttrs) - .flatMap(() => { - return saveIncidentManagerTeamMemberRole(repositories, diseaseOutbreakEventBaseAttrs); + .save(diseaseOutbreakEvent) + .flatMap((diseaseOutbreakId: Id) => { + const diseaseOutbreakEventWithId = { ...diseaseOutbreakEvent, id: diseaseOutbreakId }; + return saveIncidentManagerTeamMemberRole(repositories, diseaseOutbreakEventWithId); }); } diff --git a/src/webapp/pages/form-page/useForm.ts b/src/webapp/pages/form-page/useForm.ts index 09c89371..c257b191 100644 --- a/src/webapp/pages/form-page/useForm.ts +++ b/src/webapp/pages/form-page/useForm.ts @@ -69,7 +69,8 @@ export function useForm(formType: FormType, id?: Id): State { const currentEventTracker = getCurrentEventTracker(); useEffect(() => { - if (currentEventTrackerState?.id === currentEventTracker?.id) return; + if (currentEventTracker?.id && currentEventTrackerState?.id === currentEventTracker?.id) + return; compositionRoot.getWithOptions.execute(formType, currentEventTracker, id).run( formData => { @@ -337,20 +338,18 @@ export function useForm(formType: FormType, id?: Id): State { id: currentEventTracker.id, }); break; + + case "incident-action-plan": + case "incident-response-action": + goTo(RouteName.INCIDENT_ACTION_PLAN, { + id: currentEventTracker.id, + }); + break; default: - switch (formType) { - case "incident-action-plan": - case "incident-response-action": - goTo(RouteName.INCIDENT_ACTION_PLAN, { - id: currentEventTracker.id, - }); - break; - default: - goTo(RouteName.EVENT_TRACKER, { - id: currentEventTracker.id, - }); - break; - } + goTo(RouteName.EVENT_TRACKER, { + id: currentEventTracker.id, + }); + break; } } else { goTo(RouteName.DASHBOARD); From 3bcf57d7df60507d36ac7a4d4b56669cbccf6f28 Mon Sep 17 00:00:00 2001 From: 9sneha-n <9sneha.n@gmail.com> Date: Thu, 17 Oct 2024 13:21:25 +0530 Subject: [PATCH 2/6] fix: remove unused state --- src/webapp/pages/form-page/useForm.ts | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/webapp/pages/form-page/useForm.ts b/src/webapp/pages/form-page/useForm.ts index c257b191..b23b5617 100644 --- a/src/webapp/pages/form-page/useForm.ts +++ b/src/webapp/pages/form-page/useForm.ts @@ -62,15 +62,14 @@ export function useForm(formType: FormType, id?: Id): State { const [globalMessage, setGlobalMessage] = useState>(); const [formState, setFormState] = useState({ kind: "loading" }); const [configurableForm, setConfigurableForm] = useState(); - const [currentEventTrackerState, setCurrentEventTrackerState] = - useState>(); + const [formLabels, setFormLabels] = useState(); const [isLoading, setIsLoading] = useState(false); const currentEventTracker = getCurrentEventTracker(); useEffect(() => { - if (currentEventTracker?.id && currentEventTrackerState?.id === currentEventTracker?.id) - return; + // if (currentEventTracker?.id && currentEventTrackerState?.id === currentEventTracker?.id) + // return; compositionRoot.getWithOptions.execute(formType, currentEventTracker, id).run( formData => { @@ -80,7 +79,6 @@ export function useForm(formType: FormType, id?: Id): State { kind: "loaded", data: mapEntityToFormState(formData, !!id), }); - setCurrentEventTrackerState(currentEventTracker); }, error => { setFormState({ @@ -91,16 +89,9 @@ export function useForm(formType: FormType, id?: Id): State { text: i18n.t(`An error occurred while loading form: ${error.message}`), type: "error", }); - setCurrentEventTrackerState(currentEventTracker); } ); - }, [ - compositionRoot.getWithOptions, - formType, - id, - currentEventTracker, - currentEventTrackerState?.id, - ]); + }, [compositionRoot.getWithOptions, formType, id, currentEventTracker]); const handleAddNew = useCallback(() => { if (formState.kind !== "loaded" || !configurableForm) return; From 7f38e7d6c38657c1ff8a86093351a7079c2e67a0 Mon Sep 17 00:00:00 2001 From: 9sneha-n <9sneha.n@gmail.com> Date: Thu, 17 Oct 2024 13:22:28 +0530 Subject: [PATCH 3/6] chore: fix warn --- src/webapp/pages/form-page/useForm.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/webapp/pages/form-page/useForm.ts b/src/webapp/pages/form-page/useForm.ts index b23b5617..01a2e6e1 100644 --- a/src/webapp/pages/form-page/useForm.ts +++ b/src/webapp/pages/form-page/useForm.ts @@ -20,7 +20,6 @@ import { addNewResponseActionSection, getAnotherResponseActionSection, } from "./incident-action/mapIncidentActionToInitialFormState"; -import { DiseaseOutbreakEvent } from "../../../domain/entities/disease-outbreak-event/DiseaseOutbreakEvent"; export type GlobalMessage = { text: string; From 83eb705fe7f59bd385602babfe2c2cd231305939 Mon Sep 17 00:00:00 2001 From: 9sneha-n <9sneha.n@gmail.com> Date: Thu, 17 Oct 2024 15:57:12 +0530 Subject: [PATCH 4/6] feat: risk custom question fix --- src/webapp/pages/form-page/mapFormStateToEntityData.ts | 3 ++- .../risk-assessment/mapRiskAssessmentToInitialFormState.ts | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/webapp/pages/form-page/mapFormStateToEntityData.ts b/src/webapp/pages/form-page/mapFormStateToEntityData.ts index a8643690..00c4f746 100644 --- a/src/webapp/pages/form-page/mapFormStateToEntityData.ts +++ b/src/webapp/pages/form-page/mapFormStateToEntityData.ts @@ -460,8 +460,9 @@ function mapFormStateToRiskAssessmentQuestionnaire( formData.options, index.toString() ); + const idWithoutIdentifier = customSection.id.replace("additionalQuestions", ""); return { - id: customSection.id.replace("additionalQuestions", ""), + id: idWithoutIdentifier.length < 11 ? "" : idWithoutIdentifier, //TO DO : Temp fix question: allFields.find(field => field.id.includes(`custom-question${index}`)) ?.value as string, likelihood: likelihoodOption, diff --git a/src/webapp/pages/form-page/risk-assessment/mapRiskAssessmentToInitialFormState.ts b/src/webapp/pages/form-page/risk-assessment/mapRiskAssessmentToInitialFormState.ts index 1c52f5ac..8114f08c 100644 --- a/src/webapp/pages/form-page/risk-assessment/mapRiskAssessmentToInitialFormState.ts +++ b/src/webapp/pages/form-page/risk-assessment/mapRiskAssessmentToInitialFormState.ts @@ -754,7 +754,7 @@ function getRiskAssessmentCustomQuestionSection( options; const riskAssesssmentQuestionFormSection: FormSectionState = { title: title, - id: questionId ? `${id}${questionId}` : `${id}`, + id: questionId ? `${id}${questionId}` : `${id}${index}`, isVisible: true, fields: [ { From 958402c03adeaaab8c6b5691239cfcf9425b8104 Mon Sep 17 00:00:00 2001 From: 9sneha-n <9sneha.n@gmail.com> Date: Thu, 17 Oct 2024 18:05:40 +0530 Subject: [PATCH 5/6] fix: update the incident action plan --- .../incident-action-plan/useIncidentActionPlan.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/webapp/pages/incident-action-plan/useIncidentActionPlan.ts b/src/webapp/pages/incident-action-plan/useIncidentActionPlan.ts index 0674fed2..59b750eb 100644 --- a/src/webapp/pages/incident-action-plan/useIncidentActionPlan.ts +++ b/src/webapp/pages/incident-action-plan/useIncidentActionPlan.ts @@ -15,6 +15,8 @@ import { IncidentActionPlan, } from "../../../domain/entities/incident-action-plan/IncidentActionPlan"; import { Option } from "../../components/utils/option"; +import { useCurrentEventTracker } from "../../contexts/current-event-tracker-context"; +import { DiseaseOutbreakEvent } from "../../../domain/entities/disease-outbreak-event/DiseaseOutbreakEvent"; export type IncidentActionFormSummaryData = { subTitle: string; @@ -28,6 +30,7 @@ export type UIIncidentActionOptions = { export function useIncidentActionPlan(id: Id) { const { compositionRoot } = useAppContext(); + const { changeCurrentEventTracker, getCurrentEventTracker } = useCurrentEventTracker(); const [incidentAction, setIncidentAction] = useState(); const [actionPlanSummary, setActionPlanSummary] = useState(); @@ -87,7 +90,15 @@ export function useIncidentActionPlan(id: Id) { incidentActionPlan => { const incidentActionExists = !!incidentActionPlan?.actionPlan?.id; const incidentActionOptions = incidentActionPlan?.incidentActionOptions; - + const currentEventTracker = getCurrentEventTracker(); + if (incidentActionExists && currentEventTracker) { + const updatedEventTracker = new DiseaseOutbreakEvent({ + ...currentEventTracker, + incidentActionPlan: incidentActionPlan, + }); + + changeCurrentEventTracker(updatedEventTracker); + } setIncidentActionExists(incidentActionExists); setIncidentActionOptions(mapIncidentActionOptionsToTable(incidentActionOptions)); setIncidentAction(getIncidentActionFormSummary(incidentActionPlan)); @@ -99,7 +110,7 @@ export function useIncidentActionPlan(id: Id) { setGlobalMessage(`Event tracker with id: ${id} does not exist`); } ); - }, [compositionRoot, id]); + }, [compositionRoot, id, changeCurrentEventTracker, getCurrentEventTracker]); return { incidentActionExists: incidentActionExists, From 8a23e178c2b1496dc2a9efc578145563ed15314b Mon Sep 17 00:00:00 2001 From: 9sneha-n <9sneha.n@gmail.com> Date: Tue, 22 Oct 2024 22:44:27 +0530 Subject: [PATCH 6/6] fix: parse index in risk custom question --- src/webapp/pages/form-page/mapFormStateToEntityData.ts | 4 ++-- .../risk-assessment/mapRiskAssessmentToInitialFormState.ts | 2 +- src/webapp/pages/form-page/useForm.ts | 3 --- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/webapp/pages/form-page/mapFormStateToEntityData.ts b/src/webapp/pages/form-page/mapFormStateToEntityData.ts index 00c4f746..1ff9e1cf 100644 --- a/src/webapp/pages/form-page/mapFormStateToEntityData.ts +++ b/src/webapp/pages/form-page/mapFormStateToEntityData.ts @@ -460,9 +460,9 @@ function mapFormStateToRiskAssessmentQuestionnaire( formData.options, index.toString() ); - const idWithoutIdentifier = customSection.id.replace("additionalQuestions", ""); + return { - id: idWithoutIdentifier.length < 11 ? "" : idWithoutIdentifier, //TO DO : Temp fix + id: customSection.id.replace("additionalQuestions", "").replace(`_${index}`, ""), question: allFields.find(field => field.id.includes(`custom-question${index}`)) ?.value as string, likelihood: likelihoodOption, diff --git a/src/webapp/pages/form-page/risk-assessment/mapRiskAssessmentToInitialFormState.ts b/src/webapp/pages/form-page/risk-assessment/mapRiskAssessmentToInitialFormState.ts index 8114f08c..26c79130 100644 --- a/src/webapp/pages/form-page/risk-assessment/mapRiskAssessmentToInitialFormState.ts +++ b/src/webapp/pages/form-page/risk-assessment/mapRiskAssessmentToInitialFormState.ts @@ -754,7 +754,7 @@ function getRiskAssessmentCustomQuestionSection( options; const riskAssesssmentQuestionFormSection: FormSectionState = { title: title, - id: questionId ? `${id}${questionId}` : `${id}${index}`, + id: questionId ? `${id}${questionId}` : `${id}_${index}`, isVisible: true, fields: [ { diff --git a/src/webapp/pages/form-page/useForm.ts b/src/webapp/pages/form-page/useForm.ts index 01a2e6e1..80945f9c 100644 --- a/src/webapp/pages/form-page/useForm.ts +++ b/src/webapp/pages/form-page/useForm.ts @@ -67,9 +67,6 @@ export function useForm(formType: FormType, id?: Id): State { const currentEventTracker = getCurrentEventTracker(); useEffect(() => { - // if (currentEventTracker?.id && currentEventTrackerState?.id === currentEventTracker?.id) - // return; - compositionRoot.getWithOptions.execute(formType, currentEventTracker, id).run( formData => { setConfigurableForm(formData);