Skip to content

Commit

Permalink
fix: review change
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikmv committed Sep 12, 2024
1 parent dbe4461 commit 2b6b0a7
Showing 1 changed file with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,18 @@ export const useOrgUnitAutoSelect = (setRelatedStageDataValues: any) => {
const queryFn = {
resource: 'organisationUnits',
params: {
fields: 'id,path,displayName',
withinUserSearchHierarchy: true,
page: 2,
fields: ['id, displayName~rename(name), path'],
withinUserHierarchy: true,
pageSize: 2,
},
};
const { data, isLoading } = useApiMetadataQuery(queryKey, queryFn);

useEffect(() => {
if (!isLoading && data) {
const orgUnits = data.organisationUnits;
if (!orgUnits || orgUnits.length !== 1) return;
const [orgUnit] = orgUnits;
const { displayName, ...rest } = orgUnit;
if (!isLoading && data?.organisationUnits?.length === 1) {
setRelatedStageDataValues(prev => ({
...prev,
orgUnit: { ...rest, name: displayName },
orgUnit: data.organisationUnits[0],
}));
}
}, [data, isLoading, setRelatedStageDataValues]);
Expand Down

0 comments on commit 2b6b0a7

Please sign in to comment.