Skip to content

Commit

Permalink
chore: fixing sticky errors on activity form
Browse files Browse the repository at this point in the history
  • Loading branch information
pbastia committed Jan 7, 2025
1 parent 8442278 commit fec5092
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface Props {
activityId: number;
sourceTypeMap: { [key: number]: string };
};
activityFormData: object;
activityFormData: any;
currentActivity: { id: number; name: string; slug: string };
taskListData: TaskListElement[];
reportVersionId: number;
Expand Down Expand Up @@ -94,6 +94,7 @@ export default function ActivityForm({
setJsonSchema(safeJsonParse(schemaData).schema);
setSelectedSourceTypeIds(selectedSourceTypes);
}

setFormState(c.formData);
};

Expand Down Expand Up @@ -122,6 +123,20 @@ export default function ActivityForm({
const submitHandler = async () => {
setErrorList([]);

const selectedSourceTypeData = Object.keys(formState.sourceTypes)
// Only filter the keys where the checkBox for that source type is checked
.filter((slug) => formState[slug])
// Only for selected source types we grab the form data
.reduce((filteredSourceTypeData, slug) => {
filteredSourceTypeData[slug] = formState.sourceTypes[slug];
return filteredSourceTypeData;
}, {} as any);

const submittedData = {
...formState,
sourceTypes: selectedSourceTypeData,
};

const response = await actionHandler(
`reporting/report-version/${reportVersionId}/facilities/${facilityId}/activity/${activityId}/report-activity`,
"POST",
Expand All @@ -131,7 +146,7 @@ export default function ActivityForm({
/* formState needs to be used instead of the data passed to the handler, since this is a controlled component;
otherwise the data passed to the handler lags behind the changes.
See FormBase implementation comments for more details. */
activity_data: formState,
activity_data: submittedData,
}),
},
);
Expand Down

0 comments on commit fec5092

Please sign in to comment.