Skip to content

Commit

Permalink
refactor: rename useCurrentOrgUnitInfo -> useCurrentOrgUnitId
Browse files Browse the repository at this point in the history
  • Loading branch information
superskip committed Oct 17, 2023
1 parent 3c75ea9 commit 5bb3883
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -17,7 +17,7 @@ export const EnrollmentRegistrationEntry: ComponentType<OwnProps> = ({
trackedEntityInstanceAttributes,
...passOnProps
}) => {
const orgUnitId = useCurrentOrgUnitInfo().id;
const orgUnitId = useCurrentOrgUnitId();
const { orgUnit, error } = useReduxOrgUnit(orgUnitId);
const { teiId, ready, skipDuplicateCheck } = useLifecycle(selectedScopeId, id, trackedEntityInstanceAttributes, orgUnit);
const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 : '';

Expand All @@ -82,9 +82,8 @@ const TeiRegistrationEntryPlain =
{
scopeType === scopeTypes.TRACKED_ENTITY_TYPE && formId &&
<>
{/* $FlowFixMe */}
<TrackedEntityInstanceDataEntry
orgUnit={orgUnit}
orgUnitId={orgUnitId}
formFoundation={formFoundation}
trackedEntityTypeId={selectedScopeId}
teiRegistrationMetadata={teiRegistrationMetadata}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useDispatch, useSelector } from 'react-redux';
import React, { useEffect, useMemo } from 'react';
import type { ComponentType } from 'react';
import { useScopeInfo } from '../../../hooks/useScopeInfo';
import { useCurrentOrgUnitInfo } from '../../../hooks/useCurrentOrgUnitInfo';
import { useCurrentOrgUnitId } from '../../../hooks/useCurrentOrgUnitId';
import { Enrollment, scopeTypes } from '../../../metaData';
import { startNewTeiDataEntryInitialisation } from './TeiRegistrationEntry.actions';
import type { OwnProps } from './TeiRegistrationEntry.types';
Expand All @@ -15,7 +15,7 @@ import { useMetadataForRegistrationForm } from '../common/TEIAndEnrollment/useMe
const useInitialiseTeiRegistration = (selectedScopeId, dataEntryId) => {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class PreTeiDataEntryPure extends React.PureComponent<Object> {
}

type PreTeiDataEntryProps = {
orgUnit: Object,
orgUnitId: string,
trackedEntityTypeId: string,
onUpdateField: Function,
onStartAsyncUpdateField: Function,
Expand All @@ -52,17 +52,17 @@ type PreTeiDataEntryProps = {

export class PreTeiDataEntry extends React.Component<PreTeiDataEntryProps> {
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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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(
Expand Down
5 changes: 5 additions & 0 deletions src/core_modules/capture-core/hooks/useCurrentOrgUnitId.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// @flow
import { useSelector } from 'react-redux';

export const useCurrentOrgUnitId = () =>
useSelector(({ currentSelections: { orgUnitId } }) => orgUnitId);
19 changes: 0 additions & 19 deletions src/core_modules/capture-core/hooks/useCurrentOrgUnitInfo.js

This file was deleted.

0 comments on commit 5bb3883

Please sign in to comment.