Skip to content

Commit

Permalink
fix: update the incident action plan
Browse files Browse the repository at this point in the history
  • Loading branch information
9sneha-n committed Oct 17, 2024
1 parent 83eb705 commit 958402c
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/webapp/pages/incident-action-plan/useIncidentActionPlan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,6 +30,7 @@ export type UIIncidentActionOptions = {

export function useIncidentActionPlan(id: Id) {
const { compositionRoot } = useAppContext();
const { changeCurrentEventTracker, getCurrentEventTracker } = useCurrentEventTracker();

const [incidentAction, setIncidentAction] = useState<Option[] | undefined>();
const [actionPlanSummary, setActionPlanSummary] = useState<IncidentActionFormSummaryData>();
Expand Down Expand Up @@ -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));
Expand All @@ -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,
Expand Down

0 comments on commit 958402c

Please sign in to comment.