From 587a4415e3246df8259cdf6a4f70db73646aecc9 Mon Sep 17 00:00:00 2001 From: henrikmv Date: Thu, 5 Dec 2024 14:08:26 +0100 Subject: [PATCH] feat: auto select orgUnit --- .../DataEntry/helpers/getOpenDataEntryActions.js | 8 ++++++-- .../WidgetEnrollmentEventNew/Validated/useLifecycle.js | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) 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 c5481bf76c..2dc83e03da 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 @@ -42,7 +42,11 @@ const dataEntryPropsToInclude: DataEntryPropsToInclude = [ ]; export const getOpenDataEntryActions = - (dataEntryId: string, itemId: string, programCategory?: ProgramCategory) => { + (dataEntryId: string, itemId: string, programCategory?: ProgramCategory, orgUnit: Object) => { + const { id, name, path } = orgUnit; + const defaultDataEntryValues = { + orgUnit: { id, name, path }, + }; if (programCategory && programCategory.categories) { dataEntryPropsToInclude.push(...programCategory.categories.map(category => ({ id: `attributeCategoryOptions-${category.id}`, @@ -50,6 +54,6 @@ export const getOpenDataEntryActions = validatorContainers: getCategoryOptionsValidatorContainers({ categories: programCategory.categories }, category.id), }))); } - return loadNewDataEntry(dataEntryId, itemId, dataEntryPropsToInclude); + return loadNewDataEntry(dataEntryId, itemId, dataEntryPropsToInclude, defaultDataEntryValues); }; diff --git a/src/core_modules/capture-core/components/WidgetEnrollmentEventNew/Validated/useLifecycle.js b/src/core_modules/capture-core/components/WidgetEnrollmentEventNew/Validated/useLifecycle.js index bf41bf3e53..cd7106d38a 100644 --- a/src/core_modules/capture-core/components/WidgetEnrollmentEventNew/Validated/useLifecycle.js +++ b/src/core_modules/capture-core/components/WidgetEnrollmentEventNew/Validated/useLifecycle.js @@ -39,12 +39,12 @@ export const useLifecycle = ({ useEffect(() => { if (!isLoading) { dispatch(batchActions([ - ...getOpenDataEntryActions(dataEntryId, itemId, programCategory), + ...getOpenDataEntryActions(dataEntryId, itemId, programCategory, orgUnit), ])); dataEntryReadyRef.current = true; delayRulesExecutionRef.current = true; } - }, [dispatch, dataEntryId, itemId, program, formFoundation, isLoading, programCategory]); + }, [dispatch, dataEntryId, itemId, program, formFoundation, isLoading, programCategory, orgUnit]); const eventsRef = useRef(); const attributesRef = useRef();