@@ -7,17 +7,23 @@ import MoneyReportHeader from '@components/MoneyReportHeader';
7
7
import OfflineWithFeedback from '@components/OfflineWithFeedback' ;
8
8
import ReportActionsSkeletonView from '@components/ReportActionsSkeletonView' ;
9
9
import ReportHeaderSkeletonView from '@components/ReportHeaderSkeletonView' ;
10
+ import useActiveWorkspace from '@hooks/useActiveWorkspace' ;
10
11
import useNetwork from '@hooks/useNetwork' ;
11
12
import usePaginatedReportActions from '@hooks/usePaginatedReportActions' ;
12
13
import useThemeStyles from '@hooks/useThemeStyles' ;
13
14
import { removeReport } from '@libs/actions/Report' ;
14
15
import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID' ;
16
+ import Log from '@libs/Log' ;
17
+ import navigationRef from '@libs/Navigation/navigationRef' ;
15
18
import { isMoneyRequestAction } from '@libs/ReportActionsUtils' ;
16
19
import { canEditReportAction , getReportOfflinePendingActionAndErrors } from '@libs/ReportUtils' ;
20
+ import { buildCannedSearchQuery } from '@libs/SearchQueryUtils' ;
17
21
import Navigation from '@navigation/Navigation' ;
18
22
import ReportFooter from '@pages/home/report/ReportFooter' ;
23
+ import NAVIGATORS from '@src/NAVIGATORS' ;
19
24
import ONYXKEYS from '@src/ONYXKEYS' ;
20
25
import type { Route } from '@src/ROUTES' ;
26
+ import ROUTES from '@src/ROUTES' ;
21
27
import type { ThemeStyles } from '@src/styles' ;
22
28
import type * as OnyxTypes from '@src/types/onyx' ;
23
29
import MoneyRequestReportActionsList from './MoneyRequestReportActionsList' ;
@@ -39,6 +45,24 @@ type MoneyRequestReportViewProps = {
39
45
backToRoute : Route | undefined ;
40
46
} ;
41
47
48
+ function goBackFromSearchMoneyRequest ( policyID : string | undefined ) {
49
+ const rootState = navigationRef . getRootState ( ) ;
50
+ const lastRoute = rootState . routes . at ( - 1 ) ;
51
+
52
+ if ( lastRoute ?. name !== NAVIGATORS . SEARCH_FULLSCREEN_NAVIGATOR ) {
53
+ Log . hmmm ( '[goBackFromSearchMoneyRequest()] goBackFromSearchMoneyRequest was called from a different navigator than SearchFullscreenNavigator.' ) ;
54
+ return ;
55
+ }
56
+
57
+ if ( rootState . routes . length > 1 ) {
58
+ Navigation . goBack ( ) ;
59
+ return ;
60
+ }
61
+
62
+ const query = buildCannedSearchQuery ( { policyID} ) ;
63
+ Navigation . goBack ( ROUTES . SEARCH_ROOT . getRoute ( { query} ) ) ;
64
+ }
65
+
42
66
function InitialLoadingSkeleton ( { styles} : { styles : ThemeStyles } ) {
43
67
return (
44
68
< View style = { [ styles . flex1 ] } >
@@ -60,6 +84,7 @@ function getParentReportAction(parentReportActions: OnyxEntry<OnyxTypes.ReportAc
60
84
function MoneyRequestReportView ( { report, policy, reportMetadata, shouldDisplayReportFooter, backToRoute} : MoneyRequestReportViewProps ) {
61
85
const styles = useThemeStyles ( ) ;
62
86
const { isOffline} = useNetwork ( ) ;
87
+ const { activeWorkspaceID} = useActiveWorkspace ( ) ;
63
88
64
89
const reportID = report ?. reportID ;
65
90
const [ isLoadingApp ] = useOnyx ( ONYXKEYS . IS_LOADING_APP ) ;
@@ -77,9 +102,9 @@ function MoneyRequestReportView({report, policy, reportMetadata, shouldDisplayRe
77
102
const isLoadingInitialReportActions = reportMetadata ?. isLoadingInitialReportActions ;
78
103
79
104
const dismissReportCreationError = useCallback ( ( ) => {
80
- Navigation . goBack ( backToRoute ) ;
105
+ goBackFromSearchMoneyRequest ( activeWorkspaceID ) ;
81
106
removeReport ( reportID ) ;
82
- } , [ backToRoute , reportID ] ) ;
107
+ } , [ activeWorkspaceID , reportID ] ) ;
83
108
84
109
if ( isLoadingInitialReportActions && reportActions . length === 0 && ! isOffline ) {
85
110
return < InitialLoadingSkeleton styles = { styles } /> ;
@@ -113,6 +138,10 @@ function MoneyRequestReportView({report, policy, reportMetadata, shouldDisplayRe
113
138
transactionThreadReportID = { undefined }
114
139
shouldDisplayBackButton
115
140
onBackButtonPress = { ( ) => {
141
+ if ( ! backToRoute ) {
142
+ goBackFromSearchMoneyRequest ( activeWorkspaceID ) ;
143
+ return ;
144
+ }
116
145
Navigation . goBack ( backToRoute ) ;
117
146
} }
118
147
/>
0 commit comments