Skip to content

Commit

Permalink
feat: persist eventTrackerType data on form reload
Browse files Browse the repository at this point in the history
  • Loading branch information
deeonwuli committed Nov 8, 2024
1 parent d1a6f6f commit a0a0f55
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/webapp/pages/form-page/useForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
import { useExistingEventTrackerTypes } from "../../contexts/existing-event-tracker-types-context";
import { useCheckWritePermission } from "../../hooks/useHasCurrentUserCaptureAccess";
import { useSnackbar } from "@eyeseetea/d2-ui-components";
import { usePerformanceOverview } from "../dashboard/usePerformanceOverview";

export type GlobalMessage = {
text: string;
Expand Down Expand Up @@ -67,9 +68,18 @@ export function useForm(formType: FormType, id?: Id): State {
const [isLoading, setIsLoading] = useState(false);
const currentEventTracker = getCurrentEventTracker();
const { existingEventTrackerTypes } = useExistingEventTrackerTypes();
const { dataPerformanceOverview } = usePerformanceOverview();
useCheckWritePermission(formType);
const snackbar = useSnackbar();

const allDataPerformanceEvents = dataPerformanceOverview?.map(
event => event.hazardType || event.suspectedDisease
);
const existingEventTrackers =
existingEventTrackerTypes.length === 0
? allDataPerformanceEvents
: existingEventTrackerTypes;

useEffect(() => {
compositionRoot.getConfigurableForm
.execute(formType, currentEventTracker, configurations, id)
Expand All @@ -79,7 +89,7 @@ export function useForm(formType: FormType, id?: Id): State {
setFormLabels(formData.labels);
setFormState({
kind: "loaded",
data: mapEntityToFormState(formData, !!id, existingEventTrackerTypes),
data: mapEntityToFormState(formData, !!id, existingEventTrackers),
});
},
error => {
Expand All @@ -99,7 +109,7 @@ export function useForm(formType: FormType, id?: Id): State {
id,
currentEventTracker,
configurations,
existingEventTrackerTypes,
existingEventTrackers,
snackbar,
goTo,
]);
Expand Down

0 comments on commit a0a0f55

Please sign in to comment.