1
- import React from 'react' ;
2
- import { View } from 'react-native' ;
1
+ import React , { useCallback } from 'react' ;
2
+ import { InteractionManager , View } from 'react-native' ;
3
3
import type { OnyxEntry } from 'react-native-onyx' ;
4
4
import { useOnyx } from 'react-native-onyx' ;
5
5
import HeaderGap from '@components/HeaderGap' ;
6
6
import MoneyReportHeader from '@components/MoneyReportHeader' ;
7
+ import OfflineWithFeedback from '@components/OfflineWithFeedback' ;
7
8
import ReportActionsSkeletonView from '@components/ReportActionsSkeletonView' ;
8
9
import ReportHeaderSkeletonView from '@components/ReportHeaderSkeletonView' ;
10
+ import useActiveWorkspace from '@hooks/useActiveWorkspace' ;
9
11
import useNetwork from '@hooks/useNetwork' ;
10
12
import usePaginatedReportActions from '@hooks/usePaginatedReportActions' ;
11
13
import useThemeStyles from '@hooks/useThemeStyles' ;
14
+ import { removeFailedReport } from '@libs/actions/Report' ;
12
15
import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID' ;
16
+ import Log from '@libs/Log' ;
17
+ import navigationRef from '@libs/Navigation/navigationRef' ;
13
18
import { isMoneyRequestAction } from '@libs/ReportActionsUtils' ;
14
19
import { canEditReportAction , getReportOfflinePendingActionAndErrors } from '@libs/ReportUtils' ;
20
+ import { buildCannedSearchQuery } from '@libs/SearchQueryUtils' ;
15
21
import Navigation from '@navigation/Navigation' ;
16
22
import ReportFooter from '@pages/home/report/ReportFooter' ;
23
+ import NAVIGATORS from '@src/NAVIGATORS' ;
17
24
import ONYXKEYS from '@src/ONYXKEYS' ;
18
25
import type { Route } from '@src/ROUTES' ;
26
+ import ROUTES from '@src/ROUTES' ;
19
27
import type { ThemeStyles } from '@src/styles' ;
20
28
import type * as OnyxTypes from '@src/types/onyx' ;
21
29
import MoneyRequestReportActionsList from './MoneyRequestReportActionsList' ;
@@ -37,6 +45,24 @@ type MoneyRequestReportViewProps = {
37
45
backToRoute : Route | undefined ;
38
46
} ;
39
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
+
40
66
function InitialLoadingSkeleton ( { styles} : { styles : ThemeStyles } ) {
41
67
return (
42
68
< View style = { [ styles . flex1 ] } >
@@ -58,11 +84,12 @@ function getParentReportAction(parentReportActions: OnyxEntry<OnyxTypes.ReportAc
58
84
function MoneyRequestReportView ( { report, policy, reportMetadata, shouldDisplayReportFooter, backToRoute} : MoneyRequestReportViewProps ) {
59
85
const styles = useThemeStyles ( ) ;
60
86
const { isOffline} = useNetwork ( ) ;
87
+ const { activeWorkspaceID} = useActiveWorkspace ( ) ;
61
88
62
89
const reportID = report ?. reportID ;
63
90
const [ isLoadingApp ] = useOnyx ( ONYXKEYS . IS_LOADING_APP ) ;
64
91
const [ isComposerFullSize ] = useOnyx ( `${ ONYXKEYS . COLLECTION . REPORT_IS_COMPOSER_FULL_SIZE } ${ reportID } ` , { initialValue : false } ) ;
65
- const { reportPendingAction} = getReportOfflinePendingActionAndErrors ( report ) ;
92
+ const { reportPendingAction, reportErrors } = getReportOfflinePendingActionAndErrors ( report ) ;
66
93
67
94
const { reportActions, hasNewerActions, hasOlderActions} = usePaginatedReportActions ( reportID ) ;
68
95
@@ -74,6 +101,11 @@ function MoneyRequestReportView({report, policy, reportMetadata, shouldDisplayRe
74
101
const lastReportAction = [ ...reportActions , parentReportAction ] . find ( ( action ) => canEditReportAction ( action ) && ! isMoneyRequestAction ( action ) ) ;
75
102
const isLoadingInitialReportActions = reportMetadata ?. isLoadingInitialReportActions ;
76
103
104
+ const dismissReportCreationError = useCallback ( ( ) => {
105
+ goBackFromSearchMoneyRequest ( activeWorkspaceID ) ;
106
+ InteractionManager . runAfterInteractions ( ( ) => removeFailedReport ( reportID ) ) ;
107
+ } , [ activeWorkspaceID , reportID ] ) ;
108
+
77
109
if ( isLoadingInitialReportActions && reportActions . length === 0 && ! isOffline ) {
78
110
return < InitialLoadingSkeleton styles = { styles } /> ;
79
111
}
@@ -88,41 +120,55 @@ function MoneyRequestReportView({report, policy, reportMetadata, shouldDisplayRe
88
120
89
121
return (
90
122
< View style = { styles . flex1 } >
91
- < HeaderGap />
92
- { ! isLoadingApp ? (
93
- < MoneyReportHeader
94
- report = { report }
95
- policy = { policy }
96
- reportActions = { [ ] }
97
- transactionThreadReportID = { undefined }
98
- shouldDisplayBackButton
99
- onBackButtonPress = { ( ) => {
100
- Navigation . goBack ( backToRoute ) ;
101
- } }
102
- />
103
- ) : (
104
- < ReportHeaderSkeletonView />
105
- ) }
106
- { ! isLoadingApp ? (
107
- < MoneyRequestReportActionsList
108
- report = { report }
109
- reportActions = { reportActions }
110
- hasOlderActions = { hasOlderActions }
111
- hasNewerActions = { hasNewerActions }
112
- />
113
- ) : (
114
- < ReportActionsSkeletonView />
115
- ) }
116
- { shouldDisplayReportFooter ? (
117
- < ReportFooter
118
- report = { report }
119
- reportMetadata = { reportMetadata }
120
- policy = { policy }
121
- pendingAction = { reportPendingAction }
122
- isComposerFullSize = { ! ! isComposerFullSize }
123
- lastReportAction = { lastReportAction }
124
- />
125
- ) : null }
123
+ < OfflineWithFeedback
124
+ pendingAction = { reportPendingAction }
125
+ errors = { reportErrors }
126
+ onClose = { dismissReportCreationError }
127
+ needsOffscreenAlphaCompositing
128
+ style = { styles . flex1 }
129
+ contentContainerStyle = { styles . flex1 }
130
+ errorRowStyles = { [ styles . ph5 , styles . mv2 ] }
131
+ >
132
+ < HeaderGap />
133
+ { ! isLoadingApp ? (
134
+ < MoneyReportHeader
135
+ report = { report }
136
+ policy = { policy }
137
+ reportActions = { [ ] }
138
+ transactionThreadReportID = { undefined }
139
+ shouldDisplayBackButton
140
+ onBackButtonPress = { ( ) => {
141
+ if ( ! backToRoute ) {
142
+ goBackFromSearchMoneyRequest ( activeWorkspaceID ) ;
143
+ return ;
144
+ }
145
+ Navigation . goBack ( backToRoute ) ;
146
+ } }
147
+ />
148
+ ) : (
149
+ < ReportHeaderSkeletonView />
150
+ ) }
151
+ { ! isLoadingApp ? (
152
+ < MoneyRequestReportActionsList
153
+ report = { report }
154
+ reportActions = { reportActions }
155
+ hasOlderActions = { hasOlderActions }
156
+ hasNewerActions = { hasNewerActions }
157
+ />
158
+ ) : (
159
+ < ReportActionsSkeletonView />
160
+ ) }
161
+ { shouldDisplayReportFooter ? (
162
+ < ReportFooter
163
+ report = { report }
164
+ reportMetadata = { reportMetadata }
165
+ policy = { policy }
166
+ pendingAction = { reportPendingAction }
167
+ isComposerFullSize = { ! ! isComposerFullSize }
168
+ lastReportAction = { lastReportAction }
169
+ />
170
+ ) : null }
171
+ </ OfflineWithFeedback >
126
172
</ View >
127
173
) ;
128
174
}
0 commit comments