diff --git a/src/core_modules/capture-core/components/DataEntries/EnrollmentRegistrationEntry/EnrollmentRegistrationEntry.container.js b/src/core_modules/capture-core/components/DataEntries/EnrollmentRegistrationEntry/EnrollmentRegistrationEntry.container.js index f3f7fbf3c0..94e97045ea 100644 --- a/src/core_modules/capture-core/components/DataEntries/EnrollmentRegistrationEntry/EnrollmentRegistrationEntry.container.js +++ b/src/core_modules/capture-core/components/DataEntries/EnrollmentRegistrationEntry/EnrollmentRegistrationEntry.container.js @@ -5,7 +5,7 @@ import { useSelector } from 'react-redux'; import { EnrollmentRegistrationEntryComponent } from './EnrollmentRegistrationEntry.component'; import type { OwnProps } from './EnrollmentRegistrationEntry.types'; import { useLifecycle } from './hooks'; -import { useCurrentOrgUnitInfo } from '../../../hooks/useCurrentOrgUnitInfo'; +import { useCurrentOrgUnitId } from '../../../hooks/useCurrentOrgUnitId'; import { useReduxOrgUnit } from '../../../redux/organisationUnits'; import { dataEntryHasChanges } from '../../DataEntry/common/dataEntryHasChanges'; import { useMetadataForRegistrationForm } from '../common/TEIAndEnrollment/useMetadataForRegistrationForm'; @@ -17,7 +17,7 @@ export const EnrollmentRegistrationEntry: ComponentType = ({ trackedEntityInstanceAttributes, ...passOnProps }) => { - const orgUnitId = useCurrentOrgUnitInfo().id; + const orgUnitId = useCurrentOrgUnitId(); const { orgUnit, error } = useReduxOrgUnit(orgUnitId); const { teiId, ready, skipDuplicateCheck } = useLifecycle(selectedScopeId, id, trackedEntityInstanceAttributes, orgUnit); const { diff --git a/src/core_modules/capture-core/components/DataEntries/TeiRegistrationEntry/TeiRegistrationEntry.component.js b/src/core_modules/capture-core/components/DataEntries/TeiRegistrationEntry/TeiRegistrationEntry.component.js index 5f4da76b0c..9a1674bd2e 100644 --- a/src/core_modules/capture-core/components/DataEntries/TeiRegistrationEntry/TeiRegistrationEntry.component.js +++ b/src/core_modules/capture-core/components/DataEntries/TeiRegistrationEntry/TeiRegistrationEntry.component.js @@ -8,7 +8,7 @@ import { useHistory } from 'react-router-dom'; import { useScopeInfo } from '../../../hooks/useScopeInfo'; import { scopeTypes } from '../../../metaData'; import { TrackedEntityInstanceDataEntry } from '../TrackedEntityInstance'; -import { useCurrentOrgUnitInfo } from '../../../hooks/useCurrentOrgUnitInfo'; +import { useCurrentOrgUnitId } from '../../../hooks/useCurrentOrgUnitId'; import { useReduxOrgUnit } from '../../../redux/organisationUnits'; import type { Props, PlainProps } from './TeiRegistrationEntry.types'; import { DiscardDialog } from '../../Dialogs/DiscardDialog.component'; @@ -55,7 +55,7 @@ const TeiRegistrationEntryPlain = const [showWarning, setShowWarning] = useState(false); const { scopeType } = useScopeInfo(selectedScopeId); const { formId, formFoundation } = useMetadataForRegistrationForm({ selectedScopeId }); - const { id: orgUnitId } = useCurrentOrgUnitInfo(); + const orgUnitId = useCurrentOrgUnitId(); const { orgUnit } = useReduxOrgUnit(id); // [DHIS2-15814] Change this to new hook const orgUnitName = orgUnit ? orgUnit.name : ''; @@ -82,9 +82,8 @@ const TeiRegistrationEntryPlain = { scopeType === scopeTypes.TRACKED_ENTITY_TYPE && formId && <> - {/* $FlowFixMe */} { const dispatch = useDispatch(); const { scopeType, trackedEntityName } = useScopeInfo(selectedScopeId); - const { id: selectedOrgUnitId } = useCurrentOrgUnitInfo(); + const selectedOrgUnitId = useCurrentOrgUnitId(); const { formId, formFoundation } = useMetadataForRegistrationForm({ selectedScopeId }); const formValues = useFormValuesFromSearchTerms(); const registrationFormReady = !!formId; diff --git a/src/core_modules/capture-core/components/DataEntries/TrackedEntityInstance/TrackedEntityInstanceDataEntry.component.js b/src/core_modules/capture-core/components/DataEntries/TrackedEntityInstance/TrackedEntityInstanceDataEntry.component.js index 21a4b64e15..fad0f62845 100644 --- a/src/core_modules/capture-core/components/DataEntries/TrackedEntityInstance/TrackedEntityInstanceDataEntry.component.js +++ b/src/core_modules/capture-core/components/DataEntries/TrackedEntityInstance/TrackedEntityInstanceDataEntry.component.js @@ -42,7 +42,7 @@ class PreTeiDataEntryPure extends React.PureComponent { } type PreTeiDataEntryProps = { - orgUnit: Object, + orgUnitId: string, trackedEntityTypeId: string, onUpdateField: Function, onStartAsyncUpdateField: Function, @@ -52,17 +52,17 @@ type PreTeiDataEntryProps = { export class PreTeiDataEntry extends React.Component { getValidationContext = () => { - const { orgUnit, onGetUnsavedAttributeValues, trackedEntityTypeId } = this.props; + const { orgUnitId, onGetUnsavedAttributeValues, trackedEntityTypeId } = this.props; return { trackedEntityTypeId, - orgUnitId: orgUnit.id, + orgUnitId, onGetUnsavedAttributeValues, }; } render() { const { - orgUnit, + orgUnitId, trackedEntityTypeId, onUpdateField, onStartAsyncUpdateField, diff --git a/src/core_modules/capture-core/components/PossibleDuplicatesDialog/useDuplicates.js b/src/core_modules/capture-core/components/PossibleDuplicatesDialog/useDuplicates.js index 049dfa7a50..15f7035c2c 100644 --- a/src/core_modules/capture-core/components/PossibleDuplicatesDialog/useDuplicates.js +++ b/src/core_modules/capture-core/components/PossibleDuplicatesDialog/useDuplicates.js @@ -1,7 +1,7 @@ // @flow import { useDispatch } from 'react-redux'; import { useCallback, useContext } from 'react'; -import { useCurrentOrgUnitInfo } from '../../hooks/useCurrentOrgUnitInfo'; +import { useCurrentOrgUnitId } from '../../hooks/useCurrentOrgUnitId'; import { changePage, reviewDuplicates } from './possibleDuplicatesDialog.actions'; import { ResultsPageSizeContext } from '../Pages/shared-contexts'; import { useScopeInfo } from '../../hooks/useScopeInfo'; @@ -10,7 +10,7 @@ export const useDuplicates = (dataEntryId: string, selectedScopeId: string) => { const { resultsPageSize } = useContext(ResultsPageSizeContext); const dispatch = useDispatch(); const { scopeType } = useScopeInfo(selectedScopeId); - const { id: orgUnitId } = useCurrentOrgUnitInfo(); + const orgUnitId = useCurrentOrgUnitId(); const dispatchOnReviewDuplicates = useCallback( () => { dispatch( diff --git a/src/core_modules/capture-core/hooks/useCurrentOrgUnitId.js b/src/core_modules/capture-core/hooks/useCurrentOrgUnitId.js new file mode 100644 index 0000000000..ada2e99463 --- /dev/null +++ b/src/core_modules/capture-core/hooks/useCurrentOrgUnitId.js @@ -0,0 +1,5 @@ +// @flow +import { useSelector } from 'react-redux'; + +export const useCurrentOrgUnitId = () => + useSelector(({ currentSelections: { orgUnitId } }) => orgUnitId); diff --git a/src/core_modules/capture-core/hooks/useCurrentOrgUnitInfo.js b/src/core_modules/capture-core/hooks/useCurrentOrgUnitInfo.js deleted file mode 100644 index 35eff69d72..0000000000 --- a/src/core_modules/capture-core/hooks/useCurrentOrgUnitInfo.js +++ /dev/null @@ -1,19 +0,0 @@ -// @flow -import { useSelector } from 'react-redux'; - -export const useCurrentOrgUnitInfo = (): {| id: string, name: string, code: string |} => - ({ - id: useSelector(({ currentSelections: { orgUnitId } }) => orgUnitId), - name: useSelector(( - { - organisationUnits, - currentSelections: { orgUnitId }, - }) => - organisationUnits[orgUnitId] && organisationUnits[orgUnitId].name), - code: useSelector(( - { - organisationUnits, - currentSelections: { orgUnitId }, - }) => - organisationUnits[orgUnitId] && organisationUnits[orgUnitId].code), - });