-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
IOURequestStepConfirmation.tsx
662 lines (603 loc) · 32.2 KB
/
IOURequestStepConfirmation.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
import {View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import * as Expensicons from '@components/Icon/Expensicons';
import LocationPermissionModal from '@components/LocationPermissionModal';
import MoneyRequestConfirmationList from '@components/MoneyRequestConfirmationList';
import {usePersonalDetails} from '@components/OnyxProvider';
import ScreenWrapper from '@components/ScreenWrapper';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import * as DeviceCapabilities from '@libs/DeviceCapabilities';
import * as FileUtils from '@libs/fileDownload/FileUtils';
import getCurrentPosition from '@libs/getCurrentPosition';
import * as IOUUtils from '@libs/IOUUtils';
import Log from '@libs/Log';
import Navigation from '@libs/Navigation/Navigation';
import * as OptionsListUtils from '@libs/OptionsListUtils';
import * as PolicyUtils from '@libs/PolicyUtils';
import * as ReportUtils from '@libs/ReportUtils';
import playSound, {SOUNDS} from '@libs/Sound';
import * as TransactionUtils from '@libs/TransactionUtils';
import * as IOU from '@userActions/IOU';
import {openDraftWorkspaceRequest} from '@userActions/Policy/Policy';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import type {Policy, PolicyCategories, PolicyTagList} from '@src/types/onyx';
import type {Participant} from '@src/types/onyx/IOU';
import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage';
import type {Receipt} from '@src/types/onyx/Transaction';
import type {WithFullTransactionOrNotFoundProps} from './withFullTransactionOrNotFound';
import withFullTransactionOrNotFound from './withFullTransactionOrNotFound';
import type {WithWritableReportOrNotFoundProps} from './withWritableReportOrNotFound';
import withWritableReportOrNotFound from './withWritableReportOrNotFound';
type IOURequestStepConfirmationOnyxProps = {
/** The policy of the report */
policy: OnyxEntry<Policy>;
/** The draft policy of the report */
policyDraft: OnyxEntry<Policy>;
/** The category configuration of the report's policy */
policyCategories: OnyxEntry<PolicyCategories>;
/** The draft category configuration of the report's policy */
policyCategoriesDraft: OnyxEntry<PolicyCategories>;
/** The tag configuration of the report's policy */
policyTags: OnyxEntry<PolicyTagList>;
};
type IOURequestStepConfirmationProps = IOURequestStepConfirmationOnyxProps &
WithWritableReportOrNotFoundProps<typeof SCREENS.MONEY_REQUEST.STEP_CONFIRMATION> &
WithFullTransactionOrNotFoundProps<typeof SCREENS.MONEY_REQUEST.STEP_CONFIRMATION>;
function IOURequestStepConfirmation({
policy: policyReal,
policyDraft,
policyTags,
policyCategories: policyCategoriesReal,
policyCategoriesDraft,
report: reportReal,
reportDraft,
route: {
params: {iouType, reportID, transactionID, action, participantsAutoAssigned: participantsAutoAssignedFromRoute},
},
transaction,
}: IOURequestStepConfirmationProps) {
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const personalDetails = usePersonalDetails() || CONST.EMPTY_OBJECT;
const report = reportReal ?? reportDraft;
const policy = policyReal ?? policyDraft;
const policyCategories = policyCategoriesReal ?? policyCategoriesDraft;
const styles = useThemeStyles();
const {translate} = useLocalize();
const {windowWidth} = useWindowDimensions();
const {isOffline} = useNetwork();
const [startLocationPermissionFlow, setStartLocationPermissionFlow] = useState(false);
const [selectedParticipantList, setSelectedParticipantList] = useState<Participant[]>([]);
const [receiptFile, setReceiptFile] = useState<OnyxEntry<Receipt>>();
const requestType = TransactionUtils.getRequestType(transaction);
const isDistanceRequest = requestType === CONST.IOU.REQUEST_TYPE.DISTANCE;
const receiptFilename = transaction?.filename;
const receiptPath = transaction?.receipt?.source;
const receiptType = transaction?.receipt?.type;
const customUnitRateID = TransactionUtils.getRateID(transaction) ?? '';
const defaultTaxCode = TransactionUtils.getDefaultTaxCode(policy, transaction);
const transactionTaxCode = (transaction?.taxCode ? transaction?.taxCode : defaultTaxCode) ?? '';
const transactionTaxAmount = transaction?.taxAmount ?? 0;
const isSharingTrackExpense = action === CONST.IOU.ACTION.SHARE;
const isCategorizingTrackExpense = action === CONST.IOU.ACTION.CATEGORIZE;
const isSubmittingFromTrackExpense = action === CONST.IOU.ACTION.SUBMIT;
const isMovingTransactionFromTrackExpense = IOUUtils.isMovingTransactionFromTrackExpense(action);
const payeePersonalDetails = useMemo(() => {
if (personalDetails?.[transaction?.splitPayerAccountIDs?.[0] ?? -1]) {
return personalDetails?.[transaction?.splitPayerAccountIDs?.[0] ?? -1];
}
const participant = transaction?.participants?.find((val) => val.accountID === (transaction?.splitPayerAccountIDs?.[0] ?? -1));
return {
login: participant?.login ?? '',
accountID: participant?.accountID ?? -1,
avatar: Expensicons.FallbackAvatar,
displayName: participant?.login ?? '',
isOptimisticPersonalDetail: true,
};
}, [personalDetails, transaction?.participants, transaction?.splitPayerAccountIDs]);
const gpsRequired = transaction?.amount === 0 && iouType !== CONST.IOU.TYPE.SPLIT && receiptFile;
const headerTitle = useMemo(() => {
if (isCategorizingTrackExpense) {
return translate('iou.categorize');
}
if (isSubmittingFromTrackExpense) {
return translate('iou.submitExpense');
}
if (isSharingTrackExpense) {
return translate('iou.share');
}
if (iouType === CONST.IOU.TYPE.SPLIT) {
return translate('iou.splitExpense');
}
if (iouType === CONST.IOU.TYPE.TRACK) {
return translate('iou.trackExpense');
}
if (iouType === CONST.IOU.TYPE.PAY) {
return translate('iou.paySomeone', {name: ReportUtils.getPayeeName(report)});
}
if (iouType === CONST.IOU.TYPE.INVOICE) {
return translate('workspace.invoices.sendInvoice');
}
return translate('iou.submitExpense');
}, [iouType, report, translate, isSharingTrackExpense, isCategorizingTrackExpense, isSubmittingFromTrackExpense]);
const participants = useMemo(
() =>
transaction?.participants?.map((participant) => {
if (participant.isSender && iouType === CONST.IOU.TYPE.INVOICE) {
return participant;
}
return participant.accountID ? OptionsListUtils.getParticipantsOption(participant, personalDetails) : OptionsListUtils.getReportOption(participant);
}) ?? [],
[transaction?.participants, personalDetails, iouType],
);
const isPolicyExpenseChat = useMemo(() => participants?.some((participant) => participant.isPolicyExpenseChat), [participants]);
const formHasBeenSubmitted = useRef(false);
useEffect(() => {
const policyExpenseChat = participants?.find((participant) => participant.isPolicyExpenseChat);
if (policyExpenseChat?.policyID && policy?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) {
openDraftWorkspaceRequest(policyExpenseChat.policyID);
}
}, [isOffline, participants, transaction?.billable, policy, transactionID]);
const defaultBillable = !!policy?.defaultBillable;
useEffect(() => {
IOU.setMoneyRequestBillable(transactionID, defaultBillable);
}, [transactionID, defaultBillable]);
useEffect(() => {
if (!transaction?.category) {
return;
}
if (policyCategories?.[transaction.category] && !policyCategories[transaction.category].enabled) {
IOU.setMoneyRequestCategory(transactionID, '');
}
}, [policyCategories, transaction?.category, transactionID]);
const policyDistance = Object.values(policy?.customUnits ?? {}).find((customUnit) => customUnit.name === CONST.CUSTOM_UNITS.NAME_DISTANCE);
const defaultCategory = policyDistance?.defaultCategory ?? '';
useEffect(() => {
if (requestType !== CONST.IOU.REQUEST_TYPE.DISTANCE || !!transaction?.category) {
return;
}
IOU.setMoneyRequestCategory(transactionID, defaultCategory);
// Prevent resetting to default when unselect category
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
}, [transactionID, requestType, defaultCategory]);
const navigateBack = useCallback(() => {
// If the action is categorize and there's no policies other than personal one, we simply call goBack(), i.e: dismiss the whole flow together
// We don't need to subscribe to policy_ collection as we only need to check on the latest collection value
if (action === CONST.IOU.ACTION.CATEGORIZE && PolicyUtils.hasNoPolicyOtherThanPersonalType()) {
Navigation.goBack();
return;
}
// If there is not a report attached to the IOU with a reportID, then the participants were manually selected and the user needs taken
// back to the participants step
if (!transaction?.participantsAutoAssigned && participantsAutoAssignedFromRoute !== 'true') {
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
Navigation.goBack(ROUTES.MONEY_REQUEST_STEP_PARTICIPANTS.getRoute(iouType, transactionID, transaction?.reportID || reportID, undefined, action));
return;
}
IOUUtils.navigateToStartMoneyRequestStep(requestType, iouType, transactionID, reportID, action);
}, [transaction, iouType, requestType, transactionID, reportID, action, participantsAutoAssignedFromRoute]);
const navigateToAddReceipt = useCallback(() => {
Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_SCAN.getRoute(action, iouType, transactionID, reportID, Navigation.getActiveRouteWithoutParams()));
}, [iouType, transactionID, reportID, action]);
// When the component mounts, if there is a receipt, see if the image can be read from the disk. If not, redirect the user to the starting step of the flow.
// This is because until the request is saved, the receipt file is only stored in the browsers memory as a blob:// and if the browser is refreshed, then
// the image ceases to exist. The best way for the user to recover from this is to start over from the start of the request process.
// skip this in case user is moving the transaction as the receipt path will be valid in that case
useEffect(() => {
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const isLocalFile = FileUtils.isLocalFile(receiptPath);
if (!isLocalFile) {
setReceiptFile(transaction?.receipt);
return;
}
const onSuccess = (file: File) => {
const receipt: Receipt = file;
receipt.state = file && requestType === CONST.IOU.REQUEST_TYPE.MANUAL ? CONST.IOU.RECEIPT_STATE.OPEN : CONST.IOU.RECEIPT_STATE.SCANREADY;
setReceiptFile(receipt);
};
IOU.navigateToStartStepIfScanFileCannotBeRead(receiptFilename, receiptPath, onSuccess, requestType, iouType, transactionID, reportID, receiptType);
}, [receiptType, receiptPath, receiptFilename, requestType, iouType, transactionID, reportID, action, transaction?.receipt]);
const requestMoney = useCallback(
(selectedParticipants: Participant[], trimmedComment: string, receiptObj?: Receipt, gpsPoints?: IOU.GpsPoint) => {
if (!transaction) {
return;
}
IOU.requestMoney(
report,
transaction.amount,
transaction.currency,
transaction.created,
transaction.merchant,
currentUserPersonalDetails.login,
currentUserPersonalDetails.accountID,
selectedParticipants[0],
trimmedComment,
receiptObj,
transaction.category,
transaction.tag,
transactionTaxCode,
transactionTaxAmount,
transaction.billable,
policy,
policyTags,
policyCategories,
gpsPoints,
action,
transaction.actionableWhisperReportActionID,
transaction.linkedTrackedExpenseReportAction,
transaction.linkedTrackedExpenseReportID,
);
},
[report, transaction, transactionTaxCode, transactionTaxAmount, currentUserPersonalDetails.login, currentUserPersonalDetails.accountID, policy, policyTags, policyCategories, action],
);
const trackExpense = useCallback(
(selectedParticipants: Participant[], trimmedComment: string, receiptObj?: OnyxEntry<Receipt>, gpsPoints?: IOU.GpsPoint) => {
if (!report || !transaction) {
return;
}
IOU.trackExpense(
report,
transaction.amount,
transaction.currency,
transaction.created,
transaction.merchant,
currentUserPersonalDetails.login,
currentUserPersonalDetails.accountID,
selectedParticipants[0],
trimmedComment,
receiptObj,
transaction.category,
transaction.tag,
transactionTaxCode,
transactionTaxAmount,
transaction.billable,
policy,
policyTags,
policyCategories,
gpsPoints,
Object.keys(transaction?.comment?.waypoints ?? {}).length ? TransactionUtils.getValidWaypoints(transaction.comment.waypoints, true) : undefined,
action,
transaction.actionableWhisperReportActionID,
transaction.linkedTrackedExpenseReportAction,
transaction.linkedTrackedExpenseReportID,
);
},
[report, transaction, currentUserPersonalDetails.login, currentUserPersonalDetails.accountID, transactionTaxCode, transactionTaxAmount, policy, policyTags, policyCategories, action],
);
const createDistanceRequest = useCallback(
(selectedParticipants: Participant[], trimmedComment: string) => {
if (!transaction) {
return;
}
IOU.createDistanceRequest(
report,
selectedParticipants[0],
trimmedComment,
transaction.created,
transaction.category,
transaction.tag,
transactionTaxCode,
transactionTaxAmount,
transaction.amount,
transaction.currency,
transaction.merchant,
transaction.billable,
TransactionUtils.getValidWaypoints(transaction.comment.waypoints, true),
policy,
policyTags,
policyCategories,
customUnitRateID,
);
},
[policy, policyCategories, policyTags, report, transaction, transactionTaxCode, transactionTaxAmount, customUnitRateID],
);
const createTransaction = useCallback(
(selectedParticipants: Participant[], locationPermissionGranted = false) => {
let splitParticipants = selectedParticipants;
// Filter out participants with an amount equal to O
if (iouType === CONST.IOU.TYPE.SPLIT && transaction?.splitShares) {
const participantsWithAmount = Object.keys(transaction.splitShares ?? {})
.filter((accountID: string): boolean => (transaction?.splitShares?.[Number(accountID)]?.amount ?? 0) > 0)
.map((accountID) => Number(accountID));
splitParticipants = selectedParticipants.filter((participant) =>
participantsWithAmount.includes(participant.isPolicyExpenseChat ? participant?.ownerAccountID ?? -1 : participant.accountID ?? -1),
);
}
const trimmedComment = (transaction?.comment.comment ?? '').trim();
// Don't let the form be submitted multiple times while the navigator is waiting to take the user to a different page
if (formHasBeenSubmitted.current) {
return;
}
formHasBeenSubmitted.current = true;
playSound(SOUNDS.DONE);
// If we have a receipt let's start the split expense by creating only the action, the transaction, and the group DM if needed
if (iouType === CONST.IOU.TYPE.SPLIT && receiptFile) {
if (currentUserPersonalDetails.login && !!transaction) {
IOU.startSplitBill({
participants: selectedParticipants,
currentUserLogin: currentUserPersonalDetails.login,
currentUserAccountID: currentUserPersonalDetails.accountID,
comment: trimmedComment,
receipt: receiptFile,
existingSplitChatReportID: report?.reportID,
billable: transaction.billable,
category: transaction.category,
tag: transaction.tag,
currency: transaction.currency,
taxCode: transactionTaxCode,
taxAmount: transactionTaxAmount,
});
}
return;
}
// IOUs created from a group report will have a reportID param in the route.
// Since the user is already viewing the report, we don't need to navigate them to the report
if (iouType === CONST.IOU.TYPE.SPLIT && !transaction?.isFromGlobalCreate) {
if (currentUserPersonalDetails.login && !!transaction) {
IOU.splitBill({
participants: splitParticipants,
currentUserLogin: currentUserPersonalDetails.login,
currentUserAccountID: currentUserPersonalDetails.accountID,
amount: transaction.amount,
comment: trimmedComment,
currency: transaction.currency,
merchant: transaction.merchant,
created: transaction.created,
category: transaction.category,
tag: transaction.tag,
existingSplitChatReportID: report?.reportID,
billable: transaction.billable,
iouRequestType: transaction.iouRequestType,
splitShares: transaction.splitShares,
splitPayerAccountIDs: transaction.splitPayerAccountIDs ?? [],
taxCode: transactionTaxCode,
taxAmount: transactionTaxAmount,
});
}
return;
}
// If the split expense is created from the global create menu, we also navigate the user to the group report
if (iouType === CONST.IOU.TYPE.SPLIT) {
if (currentUserPersonalDetails.login && !!transaction) {
IOU.splitBillAndOpenReport({
participants: splitParticipants,
currentUserLogin: currentUserPersonalDetails.login,
currentUserAccountID: currentUserPersonalDetails.accountID,
amount: transaction.amount,
comment: trimmedComment,
currency: transaction.currency,
merchant: transaction.merchant,
created: transaction.created,
category: transaction.category,
tag: transaction.tag,
billable: !!transaction.billable,
iouRequestType: transaction.iouRequestType,
splitShares: transaction.splitShares,
splitPayerAccountIDs: transaction.splitPayerAccountIDs,
taxCode: transactionTaxCode,
taxAmount: transactionTaxAmount,
});
}
return;
}
if (iouType === CONST.IOU.TYPE.INVOICE) {
IOU.sendInvoice(currentUserPersonalDetails.accountID, transaction, report, receiptFile, policy, policyTags, policyCategories);
return;
}
if (iouType === CONST.IOU.TYPE.TRACK || isCategorizingTrackExpense || isSharingTrackExpense) {
if (receiptFile && transaction) {
// If the transaction amount is zero, then the money is being requested through the "Scan" flow and the GPS coordinates need to be included.
if (transaction.amount === 0 && !isSharingTrackExpense && !isCategorizingTrackExpense && locationPermissionGranted) {
getCurrentPosition(
(successData) => {
trackExpense(selectedParticipants, trimmedComment, receiptFile, {
lat: successData.coords.latitude,
long: successData.coords.longitude,
});
},
(errorData) => {
Log.info('[IOURequestStepConfirmation] getCurrentPosition failed', false, errorData);
// When there is an error, the money can still be requested, it just won't include the GPS coordinates
trackExpense(selectedParticipants, trimmedComment, receiptFile);
},
{
maximumAge: CONST.GPS.MAX_AGE,
timeout: CONST.GPS.TIMEOUT,
},
);
return;
}
// Otherwise, the money is being requested through the "Manual" flow with an attached image and the GPS coordinates are not needed.
trackExpense(selectedParticipants, trimmedComment, receiptFile);
return;
}
trackExpense(selectedParticipants, trimmedComment, receiptFile);
return;
}
if (receiptFile && !!transaction) {
// If the transaction amount is zero, then the money is being requested through the "Scan" flow and the GPS coordinates need to be included.
if (transaction.amount === 0 && !isSharingTrackExpense && !isCategorizingTrackExpense && locationPermissionGranted) {
getCurrentPosition(
(successData) => {
requestMoney(selectedParticipants, trimmedComment, receiptFile, {
lat: successData.coords.latitude,
long: successData.coords.longitude,
});
},
(errorData) => {
Log.info('[IOURequestStepConfirmation] getCurrentPosition failed', false, errorData);
// When there is an error, the money can still be requested, it just won't include the GPS coordinates
requestMoney(selectedParticipants, trimmedComment, receiptFile);
},
{
maximumAge: CONST.GPS.MAX_AGE,
timeout: CONST.GPS.TIMEOUT,
},
);
return;
}
// Otherwise, the money is being requested through the "Manual" flow with an attached image and the GPS coordinates are not needed.
requestMoney(selectedParticipants, trimmedComment, receiptFile);
return;
}
if (isDistanceRequest && !isMovingTransactionFromTrackExpense) {
createDistanceRequest(selectedParticipants, trimmedComment);
return;
}
requestMoney(selectedParticipants, trimmedComment);
},
[
transaction,
report,
iouType,
receiptFile,
isDistanceRequest,
requestMoney,
currentUserPersonalDetails.login,
currentUserPersonalDetails.accountID,
trackExpense,
createDistanceRequest,
isSharingTrackExpense,
isCategorizingTrackExpense,
isMovingTransactionFromTrackExpense,
policy,
policyTags,
policyCategories,
transactionTaxAmount,
transactionTaxCode,
],
);
/**
* Checks if user has a GOLD wallet then creates a paid IOU report on the fly
*/
const sendMoney = useCallback(
(paymentMethod: PaymentMethodType | undefined) => {
const currency = transaction?.currency;
const trimmedComment = transaction?.comment?.comment ? transaction.comment.comment.trim() : '';
const participant = participants?.[0];
if (!participant || !transaction?.amount || !currency) {
return;
}
if (paymentMethod === CONST.IOU.PAYMENT_TYPE.ELSEWHERE) {
IOU.sendMoneyElsewhere(report, transaction.amount, currency, trimmedComment, currentUserPersonalDetails.accountID, participant);
return;
}
if (paymentMethod === CONST.IOU.PAYMENT_TYPE.EXPENSIFY) {
IOU.sendMoneyWithWallet(report, transaction.amount, currency, trimmedComment, currentUserPersonalDetails.accountID, participant);
}
},
[transaction?.amount, transaction?.comment, transaction?.currency, participants, currentUserPersonalDetails.accountID, report],
);
const setBillable = useCallback(
(billable: boolean) => {
IOU.setMoneyRequestBillable(transactionID, billable);
},
[transactionID],
);
// This loading indicator is shown because the transaction originalCurrency is being updated later than the component mounts.
// To prevent the component from rendering with the wrong currency, we show a loading indicator until the correct currency is set.
const isLoading = !!transaction?.originalCurrency;
const onConfirm = (listOfParticipants: Participant[]) => {
setSelectedParticipantList(listOfParticipants);
if (gpsRequired) {
setStartLocationPermissionFlow(true);
return;
}
createTransaction(listOfParticipants);
};
return (
<ScreenWrapper
includeSafeAreaPaddingBottom={false}
shouldEnableMaxHeight={DeviceCapabilities.canUseTouchScreen()}
testID={IOURequestStepConfirmation.displayName}
>
{({safeAreaPaddingBottomStyle}) => (
<View style={[styles.flex1, safeAreaPaddingBottomStyle]}>
<HeaderWithBackButton
title={headerTitle}
onBackButtonPress={navigateBack}
shouldShowThreeDotsButton={
requestType === CONST.IOU.REQUEST_TYPE.MANUAL && (iouType === CONST.IOU.TYPE.SUBMIT || iouType === CONST.IOU.TYPE.TRACK) && !isMovingTransactionFromTrackExpense
}
threeDotsAnchorPosition={styles.threeDotsPopoverOffsetNoCloseButton(windowWidth)}
threeDotsMenuItems={[
{
icon: Expensicons.Receipt,
text: translate('receipt.addReceipt'),
onSelected: navigateToAddReceipt,
},
]}
/>
{isLoading && <FullScreenLoadingIndicator />}
{gpsRequired && (
<LocationPermissionModal
startPermissionFlow={startLocationPermissionFlow}
resetPermissionFlow={() => setStartLocationPermissionFlow(false)}
onGrant={() => createTransaction(selectedParticipantList, true)}
onDeny={() => createTransaction(selectedParticipantList, false)}
/>
)}
<MoneyRequestConfirmationList
transaction={transaction}
selectedParticipants={participants}
iouAmount={Math.abs(transaction?.amount ?? 0)}
iouComment={transaction?.comment.comment ?? ''}
iouCurrencyCode={transaction?.currency}
iouIsBillable={transaction?.billable}
onToggleBillable={setBillable}
iouCategory={transaction?.category}
onConfirm={onConfirm}
onSendMoney={sendMoney}
receiptPath={receiptPath}
receiptFilename={receiptFilename}
iouType={iouType}
reportID={reportID}
isPolicyExpenseChat={isPolicyExpenseChat}
policyID={report?.policyID ?? policy?.id}
bankAccountRoute={ReportUtils.getBankAccountRoute(report)}
iouMerchant={transaction?.merchant}
iouCreated={transaction?.created}
isDistanceRequest={isDistanceRequest}
shouldShowSmartScanFields={isMovingTransactionFromTrackExpense ? transaction?.amount !== 0 : requestType !== CONST.IOU.REQUEST_TYPE.SCAN}
action={action}
payeePersonalDetails={payeePersonalDetails}
shouldPlaySound={false}
/>
</View>
)}
</ScreenWrapper>
);
}
IOURequestStepConfirmation.displayName = 'IOURequestStepConfirmation';
const IOURequestStepConfirmationWithOnyx = withOnyx<IOURequestStepConfirmationProps, IOURequestStepConfirmationOnyxProps>({
policy: {
key: ({report, transaction}) => `${ONYXKEYS.COLLECTION.POLICY}${IOU.getIOURequestPolicyID(transaction, report)}`,
},
policyDraft: {
key: ({reportDraft, transaction}) => `${ONYXKEYS.COLLECTION.POLICY_DRAFTS}${IOU.getIOURequestPolicyID(transaction, reportDraft)}`,
},
policyCategories: {
key: ({report, transaction}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${IOU.getIOURequestPolicyID(transaction, report)}`,
},
policyCategoriesDraft: {
key: ({reportDraft, transaction}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES_DRAFT}${IOU.getIOURequestPolicyID(transaction, reportDraft)}`,
},
policyTags: {
key: ({report, transaction}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${IOU.getIOURequestPolicyID(transaction, report)}`,
},
})(IOURequestStepConfirmation);
/* eslint-disable rulesdir/no-negated-variables */
const IOURequestStepConfirmationWithFullTransactionOrNotFound = withFullTransactionOrNotFound(IOURequestStepConfirmationWithOnyx);
/* eslint-disable rulesdir/no-negated-variables */
const IOURequestStepConfirmationWithWritableReportOrNotFound = withWritableReportOrNotFound(IOURequestStepConfirmationWithFullTransactionOrNotFound);
export default IOURequestStepConfirmationWithWritableReportOrNotFound;