From 39cc34a3f7484d3c0fccae0d876c89867a459022 Mon Sep 17 00:00:00 2001 From: Tony Valle Date: Tue, 17 Oct 2023 15:29:01 +0200 Subject: [PATCH] refactor: simplify `OrgUnitFetcher` in WidgetEnrollmentEventNew --- .../OrgUnitFetcher/OrgUnitFetcher.component.js | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) 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 dbdedb0a56..b2ccb9d18e 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 @@ -1,24 +1,17 @@ // @flow import * as React from 'react'; import i18n from '@dhis2/d2-i18n'; -import { useOrgUnitGroups } from 'capture-core/hooks/useOrgUnitGroups'; -import { useOrganisationUnit } from '../../../dataQueries'; +import { useReduxOrgUnit } from '../../../redux/organisationUnits'; import { Validated } from '../Validated/Validated.container'; import type { OrgUnitFetcherProps } from './orgUnitFetcher.types'; -// Produces a rules engine compatible OrgUnit object. - -// The technical reason for introducing this component is that useOrganisationUnit and useOrgUnitGroups -// use async methods; the job of this component is to wait for these to complete. - export const OrgUnitFetcher = ({ orgUnitId, ...passOnProps }: OrgUnitFetcherProps) => { - const { error, orgUnit } = useOrganisationUnit(orgUnitId, 'displayName,code'); - const { orgUnitGroups, error: groupError } = useOrgUnitGroups(orgUnitId); + const { error, orgUnit } = useReduxOrgUnit(orgUnitId); - if (error || groupError) { + if (error) { return (
{i18n.t('organisation unit could not be retrieved. Please try again later.')} @@ -26,9 +19,7 @@ export const OrgUnitFetcher = ({ ); } - if (orgUnit && orgUnitGroups) { - orgUnit.groups = orgUnitGroups; - + if (orgUnit) { return (