diff --git a/src/pages/workspace/AccessOrNotFoundWrapper.tsx b/src/pages/workspace/AccessOrNotFoundWrapper.tsx index 1a6f59830506..5deae769531d 100644 --- a/src/pages/workspace/AccessOrNotFoundWrapper.tsx +++ b/src/pages/workspace/AccessOrNotFoundWrapper.tsx @@ -1,7 +1,7 @@ /* eslint-disable rulesdir/no-negated-variables */ import React, {useEffect, useState} from 'react'; import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; -import {withOnyx} from 'react-native-onyx'; +import {useOnyx} from 'react-native-onyx'; import type {FullPageNotFoundViewProps} from '@components/BlockingViews/FullPageNotFoundView'; import FullscreenLoadingIndicator from '@components/FullscreenLoadingIndicator'; import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; @@ -43,7 +43,7 @@ const ACCESS_VARIANTS = { >; type AccessVariant = keyof typeof ACCESS_VARIANTS; -type AccessOrNotFoundWrapperOnyxProps = { +type AccessOrNotFoundWrapperChildrenProps = { /** The report that holds the transaction */ report: OnyxEntry; @@ -54,9 +54,9 @@ type AccessOrNotFoundWrapperOnyxProps = { isLoadingReportData: OnyxEntry; }; -type AccessOrNotFoundWrapperProps = AccessOrNotFoundWrapperOnyxProps & { +type AccessOrNotFoundWrapperProps = { /** The children to render */ - children: ((props: AccessOrNotFoundWrapperOnyxProps) => React.ReactNode) | React.ReactNode; + children: ((props: AccessOrNotFoundWrapperChildrenProps) => React.ReactNode) | React.ReactNode; /** The id of the report that holds the transaction */ reportID?: string; @@ -102,13 +102,25 @@ function PageNotFoundFallback({policyID, shouldShowFullScreenFallback, fullPageN ); } -function AccessOrNotFoundWrapper({accessVariants = [], fullPageNotFoundViewProps, shouldBeBlocked, ...props}: AccessOrNotFoundWrapperProps) { - const {policy, policyID, report, iouType, allPolicies, featureName, isLoadingReportData} = props; +function AccessOrNotFoundWrapper({ + accessVariants = [], + fullPageNotFoundViewProps, + shouldBeBlocked, + policyID, + reportID, + iouType, + allPolicies, + featureName, + ...props +}: AccessOrNotFoundWrapperProps) { + const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`); + const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`); + const [isLoadingReportData] = useOnyx(ONYXKEYS.IS_LOADING_REPORT_DATA, {initialValue: true}); const {login = ''} = useCurrentUserPersonalDetails(); const isPolicyIDInRoute = !!policyID?.length; const isMoneyRequest = !!iouType && IOUUtils.isValidMoneyRequestType(iouType); const isFromGlobalCreate = isEmptyObject(report?.reportID); - const pendingField = featureName ? props.policy?.pendingFields?.[featureName] : undefined; + const pendingField = featureName ? policy?.pendingFields?.[featureName] : undefined; useEffect(() => { if (!isPolicyIDInRoute || !isEmptyObject(policy)) { @@ -160,19 +172,9 @@ function AccessOrNotFoundWrapper({accessVariants = [], fullPageNotFoundViewProps ); } - return callOrReturn(props.children, props); + return callOrReturn(props.children, {report, policy, isLoadingReportData}); } export type {AccessVariant}; -export default withOnyx({ - report: { - key: ({reportID}) => `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, - }, - policy: { - key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, - }, - isLoadingReportData: { - key: ONYXKEYS.IS_LOADING_REPORT_DATA, - }, -})(AccessOrNotFoundWrapper); +export default AccessOrNotFoundWrapper;