diff --git a/src/core_modules/capture-core/components/WidgetEnrollmentEventNew/DataEntry/DataEntry.component.js b/src/core_modules/capture-core/components/WidgetEnrollmentEventNew/DataEntry/DataEntry.component.js index f07359bc2b..38689f9c84 100644 --- a/src/core_modules/capture-core/components/WidgetEnrollmentEventNew/DataEntry/DataEntry.component.js +++ b/src/core_modules/capture-core/components/WidgetEnrollmentEventNew/DataEntry/DataEntry.component.js @@ -192,7 +192,7 @@ const buildOrgUnitSettingsFn = () => { label: i18n.t('Organisation unit'), required: true, }), - getPropName: () => 'orgUnit', + getPropName: () => 'orgUnitId', getValidatorContainers: () => getOrgUnitValidatorContainers(), getMeta: () => ({ placement: placements.TOP, diff --git a/src/core_modules/capture-core/components/WidgetEnrollmentEventNew/DataEntry/helpers/getOpenDataEntryActions.js b/src/core_modules/capture-core/components/WidgetEnrollmentEventNew/DataEntry/helpers/getOpenDataEntryActions.js index 4552b41cae..330aecbabf 100644 --- a/src/core_modules/capture-core/components/WidgetEnrollmentEventNew/DataEntry/helpers/getOpenDataEntryActions.js +++ b/src/core_modules/capture-core/components/WidgetEnrollmentEventNew/DataEntry/helpers/getOpenDataEntryActions.js @@ -2,7 +2,7 @@ import { convertGeometryOut } from 'capture-core/components/DataEntries/converters'; import { loadNewDataEntry } from '../../../DataEntry/actions/dataEntryLoadNew.actions'; -import { getEventDateValidatorContainers } from '../fieldValidators/eventDate.validatorContainersGetter'; +import { getEventDateValidatorContainers, getOrgUnitValidatorContainers } from '../fieldValidators'; import { getNoteValidatorContainers } from '../fieldValidators/note.validatorContainersGetter'; import type { ProgramCategory } from '../../../WidgetEventSchedule/CategoryOptions/CategoryOptions.types'; import { getCategoryOptionsValidatorContainers } from '../fieldValidators/categoryOptions.validatorContainersGetter'; @@ -15,6 +15,11 @@ const dataEntryPropsToInclude: DataEntryPropsToInclude = [ type: 'DATE', validatorContainers: getEventDateValidatorContainers(), }, + { + id: 'orgUnitId', + type: 'ORGANISATION_UNIT', + validatorContainers: getOrgUnitValidatorContainers(), + }, { id: 'scheduledAt', type: 'DATE', diff --git a/src/core_modules/capture-core/components/WidgetEnrollmentEventNew/OrgUnitFetcher/OrgUnitFetcher.component.js b/src/core_modules/capture-core/components/WidgetEnrollmentEventNew/OrgUnitFetcher/OrgUnitFetcher.component.js index b27b40a59e..f92ecbfa41 100644 --- a/src/core_modules/capture-core/components/WidgetEnrollmentEventNew/OrgUnitFetcher/OrgUnitFetcher.component.js +++ b/src/core_modules/capture-core/components/WidgetEnrollmentEventNew/OrgUnitFetcher/OrgUnitFetcher.component.js @@ -23,7 +23,7 @@ export const OrgUnitFetcher = ({ return ( ); } diff --git a/src/core_modules/capture-core/components/WidgetEnrollmentEventNew/Validated/Validated.container.js b/src/core_modules/capture-core/components/WidgetEnrollmentEventNew/Validated/Validated.container.js index 9575049bc1..61c961a257 100644 --- a/src/core_modules/capture-core/components/WidgetEnrollmentEventNew/Validated/Validated.container.js +++ b/src/core_modules/capture-core/components/WidgetEnrollmentEventNew/Validated/Validated.container.js @@ -31,7 +31,7 @@ export const Validated = ({ onSaveExternal, onSaveSuccessActionType, onSaveErrorActionType, - orgUnitCore, + orgUnit, teiId, enrollmentId, rulesExecutionDependencies, @@ -42,10 +42,6 @@ export const Validated = ({ const dataEntryId = 'enrollmentEvent'; const itemId = 'newEvent'; const relatedStageRef = useRef(null); - const dataEntryKey = `${dataEntryId}-${itemId}`; - const dataEntryValues = useSelector(({ dataEntriesFieldsValue }) => dataEntriesFieldsValue[dataEntryKey]); - const orgUnitSelected = dataEntryValues?.orgUnit; - const orgUnit = orgUnitSelected || orgUnitCore; const eventSaveInProgress = useSelector( ({ enrollmentDomain }) => !!enrollmentDomain.eventSaveInProgress?.requestEventId, ); @@ -53,12 +49,11 @@ export const Validated = ({ dataEntryId, itemId, programId: program.id, + orgUnitId: orgUnit.id, + orgUnitName: orgUnit.name, teiId, enrollmentId, formFoundation, - dataEntryKey, - dataEntryValues, - orgUnit, }); const rulesExecutionDependenciesClientFormatted = diff --git a/src/core_modules/capture-core/components/WidgetEnrollmentEventNew/Validated/useBuildNewEventPayload.js b/src/core_modules/capture-core/components/WidgetEnrollmentEventNew/Validated/useBuildNewEventPayload.js index afeac4dddf..e4269a87e1 100644 --- a/src/core_modules/capture-core/components/WidgetEnrollmentEventNew/Validated/useBuildNewEventPayload.js +++ b/src/core_modules/capture-core/components/WidgetEnrollmentEventNew/Validated/useBuildNewEventPayload.js @@ -10,13 +10,14 @@ import { getConvertedRelatedStageEvent } from './getConvertedRelatedStageEvent'; import type { LinkedRequestEvent, RelatedStageRefPayload, RequestEvent } from './validated.types'; type Props = { + dataEntryId: string, + itemId: string, + orgUnitId: string, programId: string, formFoundation: RenderFoundation, enrollmentId: string, + orgUnitName: string, teiId: string, - dataEntryKey: string, - dataEntryValues: Object, - orgUnit: Object, }; export const createServerData = ({ @@ -48,16 +49,19 @@ export const createServerData = ({ }; export const useBuildNewEventPayload = ({ + dataEntryId, + itemId, + orgUnitId, programId, teiId, enrollmentId, + orgUnitName, formFoundation, - dataEntryKey, - dataEntryValues, - orgUnit, }: Props) => { const { serverVersion: { minor } } = useConfig(); + const dataEntryKey = `${dataEntryId}-${itemId}`; const formValues = useSelector(({ formsValues }) => formsValues[dataEntryKey]); + const dataEntryValues = useSelector(({ dataEntriesFieldsValue }) => dataEntriesFieldsValue[dataEntryKey]); const dataEntryValuesMeta = useSelector(({ dataEntriesFieldsMeta }) => dataEntriesFieldsMeta[dataEntryKey]); const notes = useSelector(({ dataEntriesNotes }) => dataEntriesNotes[dataEntryKey]); const { fromClientDate } = useTimeZoneConversion(); @@ -135,10 +139,10 @@ export const useBuildNewEventPayload = ({ eventId: requestEventId, mainDataClientValues: { ...dataEntryClientValues, notes: notesValues }, programId, - orgUnitId: orgUnit.id, + orgUnitId, enrollmentId, teiId, - orgUnitName: orgUnit.name, + orgUnitName, completed: saveType === addEventSaveTypes.COMPLETE, fromClientDate, serverMinorVersion: minor, diff --git a/src/core_modules/capture-core/components/WidgetEnrollmentEventNew/Validated/validated.types.js b/src/core_modules/capture-core/components/WidgetEnrollmentEventNew/Validated/validated.types.js index 93820c1f8f..e0af3da0ff 100644 --- a/src/core_modules/capture-core/components/WidgetEnrollmentEventNew/Validated/validated.types.js +++ b/src/core_modules/capture-core/components/WidgetEnrollmentEventNew/Validated/validated.types.js @@ -40,7 +40,7 @@ export type RelatedStageRefPayload = {| export type ContainerProps = {| ...CommonValidatedProps, - orgUnitCore: OrgUnit, + orgUnit: OrgUnit, |}; export type Props = {|