Skip to content

Commit

Permalink
Merge pull request #27 from EyeSeeTea/fix/demo-fixes
Browse files Browse the repository at this point in the history
Misc Fixes
  • Loading branch information
bhavananarayanan authored Nov 7, 2024
2 parents 7a42023 + e3262b0 commit eb0bca3
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ export function saveDiseaseOutbreak(
teamMemberRepository: TeamMemberRepository;
roleRepository: RoleRepository;
},
diseaseOutbreakEventBaseAttrs: DiseaseOutbreakEventBaseAttrs
diseaseOutbreakEvent: DiseaseOutbreakEventBaseAttrs
): FutureData<Id> {
return repositories.diseaseOutbreakEventRepository
.save(diseaseOutbreakEventBaseAttrs)
.flatMap(() => {
return saveIncidentManagerTeamMemberRole(repositories, diseaseOutbreakEventBaseAttrs);
.save(diseaseOutbreakEvent)
.flatMap((diseaseOutbreakId: Id) => {
const diseaseOutbreakEventWithId = { ...diseaseOutbreakEvent, id: diseaseOutbreakId };
return saveIncidentManagerTeamMemberRole(repositories, diseaseOutbreakEventWithId);
});
}

Expand Down
3 changes: 2 additions & 1 deletion src/webapp/pages/form-page/mapFormStateToEntityData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,9 @@ function mapFormStateToRiskAssessmentQuestionnaire(
formData.options,
index.toString()
);

return {
id: customSection.id.replace("additionalQuestions", ""),
id: customSection.id.replace("additionalQuestions", "").replace(`_${index}`, ""),
question: allFields.find(field => field.id.includes(`custom-question${index}`))
?.value as string,
likelihood: likelihoodOption,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand Down
16 changes: 2 additions & 14 deletions src/webapp/pages/form-page/useForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -62,15 +61,12 @@ export function useForm(formType: FormType, id?: Id): State {
const [globalMessage, setGlobalMessage] = useState<Maybe<GlobalMessage>>();
const [formState, setFormState] = useState<FormLoadState>({ kind: "loading" });
const [configurableForm, setConfigurableForm] = useState<ConfigurableForm>();
const [currentEventTrackerState, setCurrentEventTrackerState] =
useState<Maybe<DiseaseOutbreakEvent>>();

const [formLabels, setFormLabels] = useState<FormLables>();
const [isLoading, setIsLoading] = useState(false);
const currentEventTracker = getCurrentEventTracker();

useEffect(() => {
if (currentEventTrackerState?.id === currentEventTracker?.id) return;

compositionRoot.getWithOptions.execute(formType, currentEventTracker, id).run(
formData => {
setConfigurableForm(formData);
Expand All @@ -79,7 +75,6 @@ export function useForm(formType: FormType, id?: Id): State {
kind: "loaded",
data: mapEntityToFormState(formData, !!id),
});
setCurrentEventTrackerState(currentEventTracker);
},
error => {
setFormState({
Expand All @@ -90,16 +85,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;
Expand Down
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 eb0bca3

Please sign in to comment.