@@ -26,7 +26,6 @@ import {
26
26
} from '@userActions/IOU' ;
27
27
import CONST from '@src/CONST' ;
28
28
import ONYXKEYS from '@src/ONYXKEYS' ;
29
- import type { Route } from '@src/ROUTES' ;
30
29
import ROUTES from '@src/ROUTES' ;
31
30
import type SCREENS from '@src/SCREENS' ;
32
31
import type { Participant } from '@src/types/onyx/IOU' ;
@@ -42,7 +41,7 @@ type IOURequestStepParticipantsProps = WithWritableReportOrNotFoundProps<typeof
42
41
43
42
function IOURequestStepParticipants ( {
44
43
route : {
45
- params : { iouType, reportID, transactionID, action} ,
44
+ params : { iouType, reportID, transactionID, action, backTo } ,
46
45
} ,
47
46
transaction,
48
47
} : IOURequestStepParticipantsProps ) {
@@ -109,6 +108,19 @@ function IOURequestStepParticipants({
109
108
resetDraftTransactionsCustomUnit ( transactionID ) ;
110
109
} , [ isFocused , isMovingTransactionFromTrackExpense , transactionID ] ) ;
111
110
111
+ const waitForKeyboardDismiss = useCallback (
112
+ ( callback : ( ) => void ) => {
113
+ if ( isAndroidNative || isMobileSafari ) {
114
+ KeyboardUtils . dismiss ( ) . then ( ( ) => {
115
+ callback ( ) ;
116
+ } ) ;
117
+ } else {
118
+ callback ( ) ;
119
+ }
120
+ } ,
121
+ [ isAndroidNative , isMobileSafari ] ,
122
+ ) ;
123
+
112
124
const trackExpense = useCallback ( ( ) => {
113
125
// If coming from the combined submit/track flow and the user proceeds to just track the expense,
114
126
// we will use the track IOU type in the confirmation flow.
@@ -120,8 +132,16 @@ function IOURequestStepParticipants({
120
132
setCustomUnitRateID ( transactionID , rateID ) ;
121
133
setMoneyRequestParticipantsFromReport ( transactionID , selfDMReport ) ;
122
134
const iouConfirmationPageRoute = ROUTES . MONEY_REQUEST_STEP_CONFIRMATION . getRoute ( action , CONST . IOU . TYPE . TRACK , transactionID , selfDMReportID ) ;
123
- Navigation . navigate ( iouConfirmationPageRoute ) ;
124
- } , [ action , selfDMReport , selfDMReportID , transactionID ] ) ;
135
+ waitForKeyboardDismiss ( ( ) => {
136
+ // If the backTo parameter is set, we should navigate back to the confirmation screen that is already on the stack.
137
+ if ( backTo ) {
138
+ // We don't want to compare params because we just changed the participants.
139
+ Navigation . goBack ( iouConfirmationPageRoute , { compareParams : false } ) ;
140
+ } else {
141
+ Navigation . navigate ( iouConfirmationPageRoute ) ;
142
+ }
143
+ } ) ;
144
+ } , [ action , backTo , selfDMReport , selfDMReportID , transactionID , waitForKeyboardDismiss ] ) ;
125
145
126
146
const addParticipant = useCallback (
127
147
( val : Participant [ ] ) => {
@@ -159,19 +179,6 @@ function IOURequestStepParticipants({
159
179
[ iouType , reportID , trackExpense , transactionID , isMovingTransactionFromTrackExpense ] ,
160
180
) ;
161
181
162
- const handleNavigation = useCallback (
163
- ( route : Route ) => {
164
- if ( isAndroidNative || isMobileSafari ) {
165
- KeyboardUtils . dismiss ( ) . then ( ( ) => {
166
- Navigation . navigate ( route ) ;
167
- } ) ;
168
- } else {
169
- Navigation . navigate ( route ) ;
170
- }
171
- } ,
172
- [ isAndroidNative , isMobileSafari ] ,
173
- ) ;
174
-
175
182
const goToNextStep = useCallback ( ( ) => {
176
183
const isCategorizing = action === CONST . IOU . ACTION . CATEGORIZE ;
177
184
const isShareAction = action === CONST . IOU . ACTION . SHARE ;
@@ -202,12 +209,24 @@ function IOURequestStepParticipants({
202
209
? ROUTES . MONEY_REQUEST_STEP_CATEGORY . getRoute ( action , iouType , transactionID , selectedReportID . current || reportID , iouConfirmationPageRoute )
203
210
: iouConfirmationPageRoute ;
204
211
205
- handleNavigation ( route ) ;
206
- } , [ action , participants , iouType , transaction , transactionID , reportID , handleNavigation ] ) ;
212
+ waitForKeyboardDismiss ( ( ) => {
213
+ // If the backTo parameter is set, we should navigate back to the confirmation screen that is already on the stack.
214
+ if ( backTo ) {
215
+ // We don't want to compare params because we just changed the participants.
216
+ Navigation . goBack ( route , { compareParams : false } ) ;
217
+ } else {
218
+ Navigation . navigate ( route ) ;
219
+ }
220
+ } ) ;
221
+ } , [ action , participants , iouType , transaction , transactionID , reportID , waitForKeyboardDismiss , backTo ] ) ;
207
222
208
223
const navigateBack = useCallback ( ( ) => {
224
+ if ( backTo ) {
225
+ Navigation . goBack ( backTo ) ;
226
+ return ;
227
+ }
209
228
navigateToStartMoneyRequestStep ( iouRequestType , iouType , transactionID , reportID , action ) ;
210
- } , [ iouRequestType , iouType , transactionID , reportID , action ] ) ;
229
+ } , [ backTo , iouRequestType , iouType , transactionID , reportID , action ] ) ;
211
230
212
231
useEffect ( ( ) => {
213
232
const isCategorizing = action === CONST . IOU . ACTION . CATEGORIZE ;
0 commit comments