diff --git a/src/hooks/useCurrentReportID.tsx b/src/hooks/useCurrentReportID.tsx index 9b6f25f834cd1..3af6f3b42c56a 100644 --- a/src/hooks/useCurrentReportID.tsx +++ b/src/hooks/useCurrentReportID.tsx @@ -1,10 +1,14 @@ import type {NavigationState} from '@react-navigation/native'; import React, {createContext, useCallback, useContext, useMemo, useState} from 'react'; +import {useOnyx} from 'react-native-onyx'; import Navigation from '@libs/Navigation/Navigation'; +import {getReportIDFromLink} from '@libs/ReportUtils'; +import ONYXKEYS from '@src/ONYXKEYS'; type CurrentReportIDContextValue = { updateCurrentReportID: (state: NavigationState) => void; currentReportID: string | undefined; + currentReportIDFromPath: string | undefined; }; type CurrentReportIDContextProviderProps = { @@ -16,6 +20,8 @@ const CurrentReportIDContext = createContext function CurrentReportIDContextProvider(props: CurrentReportIDContextProviderProps) { const [currentReportID, setCurrentReportID] = useState(''); + const [lastVisitedPath] = useOnyx(ONYXKEYS.LAST_VISITED_PATH); + const lastAccessReportFromPath = getReportIDFromLink(lastVisitedPath ?? null); /** * This function is used to update the currentReportID @@ -46,8 +52,9 @@ function CurrentReportIDContextProvider(props: CurrentReportIDContextProviderPro (): CurrentReportIDContextValue => ({ updateCurrentReportID, currentReportID, + currentReportIDFromPath: lastAccessReportFromPath || undefined, }), - [updateCurrentReportID, currentReportID], + [updateCurrentReportID, currentReportID, lastAccessReportFromPath], ); return {props.children}; diff --git a/src/hooks/useReportIDs.tsx b/src/hooks/useReportIDs.tsx index 87e417b1f8bee..7a6ccea331ab2 100644 --- a/src/hooks/useReportIDs.tsx +++ b/src/hooks/useReportIDs.tsx @@ -64,7 +64,7 @@ function ReportIDsContextProvider({ const {shouldUseNarrowLayout} = useResponsiveLayout(); const {accountID} = useCurrentUserPersonalDetails(); const currentReportIDValue = useCurrentReportID(); - const derivedCurrentReportID = currentReportIDForTests ?? currentReportIDValue?.currentReportID; + const derivedCurrentReportID = currentReportIDForTests ?? currentReportIDValue?.currentReportIDFromPath ?? currentReportIDValue?.currentReportID; const {activeWorkspaceID} = useActiveWorkspace(); const policyMemberAccountIDs = useMemo(() => getPolicyEmployeeListByIdWithoutCurrentUser(policies, activeWorkspaceID, accountID), [policies, activeWorkspaceID, accountID]);