Skip to content

Commit

Permalink
feat: auto select orgUnit
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikmv committed Dec 5, 2024
1 parent 08fa169 commit 587a441
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,18 @@ 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}`,
type: 'TEXT',
validatorContainers: getCategoryOptionsValidatorContainers({ categories: programCategory.categories }, category.id),
})));
}
return loadNewDataEntry(dataEntryId, itemId, dataEntryPropsToInclude);
return loadNewDataEntry(dataEntryId, itemId, dataEntryPropsToInclude, defaultDataEntryValues);
};

Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 587a441

Please sign in to comment.