forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMoneyRequestReportPreviewContent.tsx
More file actions
1103 lines (1037 loc) · 56.4 KB
/
Copy pathMoneyRequestReportPreviewContent.tsx
File metadata and controls
1103 lines (1037 loc) · 56.4 KB
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
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import {useIsFocused} from '@react-navigation/native';
import {hasSeenTourSelector} from '@selectors/Onboarding';
import {FlashList} from '@shopify/flash-list';
import type {FlashListRef, ListRenderItemInfo} from '@shopify/flash-list';
import React, {useCallback, useDeferredValue, useEffect, useMemo, useRef, useState} from 'react';
import {View} from 'react-native';
import type {ViewToken} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import Animated, {useAnimatedStyle, useSharedValue, withDelay, withSpring, withTiming} from 'react-native-reanimated';
import ActivityIndicator from '@components/ActivityIndicator';
import AnimatedSubmitButton from '@components/AnimatedSubmitButton';
import Button from '@components/Button';
import {getButtonRole} from '@components/Button/utils';
import ButtonWithDropdownMenu from '@components/ButtonWithDropdownMenu';
import {useDelegateNoAccessActions, useDelegateNoAccessState} from '@components/DelegateNoAccessModalProvider';
import Icon from '@components/Icon';
import {ModalActions} from '@components/Modal/Global/ModalContext';
import MoneyReportHeaderStatusBarSkeleton from '@components/MoneyReportHeaderStatusBarSkeleton';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
import {PressableWithFeedback} from '@components/Pressable';
import PressableWithoutFeedback from '@components/Pressable/PressableWithoutFeedback';
import ProcessMoneyReportHoldMenu from '@components/ProcessMoneyReportHoldMenu';
import type {ActionHandledType} from '@components/ProcessMoneyReportHoldMenu';
import ExportWithDropdownMenu from '@components/ReportActionItem/ExportWithDropdownMenu';
import AnimatedSettlementButton from '@components/SettlementButton/AnimatedSettlementButton';
import type {PaymentActionParams} from '@components/SettlementButton/types';
import {showContextMenuForReport} from '@components/ShowContextMenuContext';
import StatusBadge from '@components/StatusBadge';
import Text from '@components/Text';
import useConfirmModal from '@hooks/useConfirmModal';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useOnyx from '@hooks/useOnyx';
import useParticipantsInvoiceReport from '@hooks/useParticipantsInvoiceReport';
import usePaymentAnimations from '@hooks/usePaymentAnimations';
import usePermissions from '@hooks/usePermissions';
import usePolicy from '@hooks/usePolicy';
import useReportIsArchived from '@hooks/useReportIsArchived';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import ControlSelection from '@libs/ControlSelection';
import {convertToDisplayString} from '@libs/CurrencyUtils';
import {canUseTouchScreen} from '@libs/DeviceCapabilities';
import {getTotalAmountForIOUReportPreviewButton} from '@libs/MoneyRequestReportUtils';
import Navigation from '@libs/Navigation/Navigation';
import {getConnectedIntegration, hasDynamicExternalWorkflow} from '@libs/PolicyUtils';
import {hasPendingDEWSubmit} from '@libs/ReportActionsUtils';
import {getInvoicePayerName} from '@libs/ReportNameUtils';
import getReportPreviewAction from '@libs/ReportPreviewActionUtils';
import {
areAllRequestsBeingSmartScanned as areAllRequestsBeingSmartScannedReportUtils,
canSubmitAndIsAwaitingForCurrentUser,
getAddExpenseDropdownOptions,
getDisplayNameForParticipant,
getMoneyRequestSpendBreakdown,
getNonHeldAndFullAmount,
getPolicyName,
getReportName,
getReportStatusColorStyle,
getReportStatusTranslation,
getTransactionsWithReceipts,
hasHeldExpenses as hasHeldExpensesReportUtils,
hasNonReimbursableTransactions as hasNonReimbursableTransactionsReportUtils,
hasOnlyHeldExpenses as hasOnlyHeldExpensesReportUtils,
hasOnlyTransactionsWithPendingRoutes as hasOnlyTransactionsWithPendingRoutesReportUtils,
hasUpdatedTotal,
hasViolations as hasViolationsReportUtils,
isInvoiceReport as isInvoiceReportUtils,
isInvoiceRoom as isInvoiceRoomReportUtils,
isPolicyExpenseChat as isPolicyExpenseChatReportUtils,
isReportApproved,
isSettled,
isTripRoom as isTripRoomReportUtils,
} from '@libs/ReportUtils';
import shouldAdjustScroll from '@libs/shouldAdjustScroll';
import {startSpan} from '@libs/telemetry/activeSpans';
import type {SkeletonSpanReasonAttributes} from '@libs/telemetry/useSkeletonSpan';
import {hasPendingUI, isManagedCardTransaction, isPending} from '@libs/TransactionUtils';
import colors from '@styles/theme/colors';
import variables from '@styles/variables';
import {approveMoneyRequest, canIOUBePaid as canIOUBePaidIOUActions, payInvoice, payMoneyRequest, submitReport} from '@userActions/IOU';
import {openOldDotLink} from '@userActions/Link';
import CONST from '@src/CONST';
import type {TranslationPaths} from '@src/languages/types';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import {validTransactionDraftIDsSelector} from '@src/selectors/TransactionDraft';
import type {ReportAttributesDerivedValue, Transaction} from '@src/types/onyx';
import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage';
import AccessMoneyRequestReportPreviewPlaceHolder from './AccessMoneyRequestReportPreviewPlaceHolder';
import EmptyMoneyRequestReportPreview from './EmptyMoneyRequestReportPreview';
import type {MoneyRequestReportPreviewContentProps} from './types';
const MAX_PREVIEWS_NUMBER = 10;
const ITEM_LAYOUT_TYPE = {
PREVIEW: 'preview',
SHOW_MORE: 'showMore',
};
const reportAttributesSelector = (c: OnyxEntry<ReportAttributesDerivedValue>) => c?.reports;
function MoneyRequestReportPreviewContent({
iouReportID,
newTransactionIDs,
chatReportID,
action,
containerStyles,
contextMenuAnchor,
isHovered = false,
isWhisper = false,
checkIfContextMenuActive = () => {},
onPaymentOptionsShow,
onPaymentOptionsHide,
chatReport,
invoiceReceiverPolicy,
iouReport,
transactions,
policy,
invoiceReceiverPersonalDetail,
lastTransactionViolations,
renderTransactionItem,
onCarouselLayout,
onWrapperLayout,
currentWidth,
reportPreviewStyles,
shouldDisplayContextMenu = true,
shouldShowBorder = false,
onPress,
forwardedFSClass,
}: MoneyRequestReportPreviewContentProps) {
const [userBillingGraceEndPeriods] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_USER_BILLING_GRACE_PERIOD_END);
const [chatReportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${chatReportID}`);
const [iouReportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${iouReportID}`);
const [ownerBillingGraceEndPeriod] = useOnyx(ONYXKEYS.NVP_PRIVATE_OWNER_BILLING_GRACE_PERIOD_END);
const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID);
const [iouReportNextStep] = useOnyx(`${ONYXKEYS.COLLECTION.NEXT_STEP}${iouReportID}`);
const [amountOwed] = useOnyx(ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED);
const activePolicy = usePolicy(activePolicyID);
const [lastDistanceExpenseType] = useOnyx(ONYXKEYS.NVP_LAST_DISTANCE_EXPENSE_TYPE);
const shouldShowLoading = !chatReportMetadata?.hasOnceLoadedReportActions && transactions.length === 0 && !chatReportMetadata?.isOptimisticReport;
// `hasOnceLoadedReportActions` becomes true before transactions populate fully,
// so we defer the loading state update to ensure transactions are loaded
const shouldShowLoadingDeferred = useDeferredValue(shouldShowLoading);
const lastTransaction = transactions?.at(0);
const shouldShowSkeleton = shouldShowLoading && transactions.length === 0;
const shouldShowAccessPlaceHolder = !iouReport && !shouldShowLoading;
const shouldShowEmptyPlaceholder = transactions.length === 0 && !shouldShowLoading;
const showStatusAndSkeleton = !shouldShowEmptyPlaceholder;
const skeletonReasonAttributes: SkeletonSpanReasonAttributes = {
context: 'MoneyRequestReportPreviewContent',
hasOnceLoadedReportActions: chatReportMetadata?.hasOnceLoadedReportActions,
isTransactionsEmpty: transactions.length === 0,
isOptimisticReport: chatReportMetadata?.isOptimisticReport,
};
const carouselReasonAttributes: SkeletonSpanReasonAttributes = {
context: 'MoneyRequestReportPreviewContent.Carousel',
hasCurrentWidth: !!currentWidth,
shouldShowLoading,
shouldShowLoadingDeferred,
};
const theme = useTheme();
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const {translate, formatPhoneNumber} = useLocalize();
const {isOffline} = useNetwork();
// eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth
const {shouldUseNarrowLayout, isSmallScreenWidth} = useResponsiveLayout();
const currentUserDetails = useCurrentUserPersonalDetails();
const currentUserAccountID = currentUserDetails.accountID;
const currentUserEmail = currentUserDetails.email ?? '';
const expensifyIcons = useMemoizedLazyExpensifyIcons(['ArrowRight', 'BackArrow', 'Location', 'ReceiptPlus']);
const {areAllRequestsBeingSmartScanned, hasNonReimbursableTransactions} = useMemo(
() => ({
areAllRequestsBeingSmartScanned: areAllRequestsBeingSmartScannedReportUtils(iouReportID, action),
hasOnlyTransactionsWithPendingRoutes: hasOnlyTransactionsWithPendingRoutesReportUtils(iouReportID),
hasNonReimbursableTransactions: hasNonReimbursableTransactionsReportUtils(iouReportID),
}),
// When transactions get updated these values may have changed, so that is a case where we also want to recompute them
// eslint-disable-next-line react-hooks/exhaustive-deps
[transactions, iouReportID, action],
);
const {isPaidAnimationRunning, isApprovedAnimationRunning, isSubmittingAnimationRunning, stopAnimation, startAnimation, startApprovedAnimation, startSubmittingAnimation} =
usePaymentAnimations();
const {showConfirmModal} = useConfirmModal();
const [isHoldMenuVisible, setIsHoldMenuVisible] = useState(false);
const [requestType, setRequestType] = useState<ActionHandledType>();
const [paymentType, setPaymentType] = useState<PaymentMethodType>();
const isIouReportArchived = useReportIsArchived(iouReportID);
const isChatReportArchived = useReportIsArchived(chatReport?.reportID);
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED);
const {isBetaEnabled} = usePermissions();
const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS);
const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST);
const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT);
const [betas] = useOnyx(ONYXKEYS.BETAS);
const [isSelfTourViewed] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: hasSeenTourSelector});
const isDEWBetaEnabled = isBetaEnabled(CONST.BETAS.NEW_DOT_DEW);
const hasViolations = hasViolationsReportUtils(iouReport?.reportID, transactionViolations, currentUserAccountID, currentUserEmail);
const [draftTransactionIDs] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_DRAFT, {selector: validTransactionDraftIDsSelector});
const getCanIOUBePaid = useCallback(
(shouldShowOnlyPayElsewhere = false) =>
canIOUBePaidIOUActions(iouReport, chatReport, policy, bankAccountList, transactions, shouldShowOnlyPayElsewhere, undefined, invoiceReceiverPolicy),
[iouReport, chatReport, policy, bankAccountList, transactions, invoiceReceiverPolicy],
);
const canIOUBePaid = useMemo(() => getCanIOUBePaid(), [getCanIOUBePaid]);
const onlyShowPayElsewhere = useMemo(() => !canIOUBePaid && getCanIOUBePaid(true), [canIOUBePaid, getCanIOUBePaid]);
const shouldShowPayButton = isPaidAnimationRunning || canIOUBePaid || onlyShowPayElsewhere;
const {nonHeldAmount, fullAmount, hasValidNonHeldAmount} = getNonHeldAndFullAmount(iouReport, shouldShowPayButton);
const canIOUBePaidAndApproved = useMemo(() => getCanIOUBePaid(false), [getCanIOUBePaid]);
const connectedIntegration = getConnectedIntegration(policy);
const hasOnlyHeldExpenses = hasOnlyHeldExpensesReportUtils(iouReport?.reportID);
const managerID = iouReport?.managerID ?? action.childManagerAccountID ?? CONST.DEFAULT_NUMBER_ID;
const {totalDisplaySpend} = getMoneyRequestSpendBreakdown(iouReport);
const iouSettled = isSettled(iouReportID) || action?.childStatusNum === CONST.REPORT.STATUS_NUM.REIMBURSED;
const previewMessageOpacity = useSharedValue(1);
const previewMessageStyle = useAnimatedStyle(() => ({
opacity: previewMessageOpacity.get(),
}));
const checkMarkScale = useSharedValue(iouSettled ? 1 : 0);
const isApproved = isReportApproved({
report: iouReport,
parentReportAction: action,
});
const thumbsUpScale = useSharedValue(isApproved ? 1 : 0);
const isPolicyExpenseChat = isPolicyExpenseChatReportUtils(chatReport);
const isInvoiceRoom = isInvoiceRoomReportUtils(chatReport);
const isTripRoom = isTripRoomReportUtils(chatReport);
const canAllowSettlement = hasUpdatedTotal(iouReport, policy);
const numberOfRequests = transactions?.length ?? 0;
const transactionsWithReceipts = getTransactionsWithReceipts(iouReportID);
const numberOfPendingRequests = transactionsWithReceipts.filter((transaction) => isPending(transaction) && isManagedCardTransaction(transaction)).length;
const shouldShowRTERViolationMessage = numberOfRequests === 1 && hasPendingUI(lastTransaction, lastTransactionViolations);
const shouldShowOnlyPayElsewhere = useMemo(() => !canIOUBePaid && getCanIOUBePaid(true), [canIOUBePaid, getCanIOUBePaid]);
const [reportAttributes] = useOnyx(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES, {
selector: reportAttributesSelector,
});
const hasReceipts = transactionsWithReceipts.length > 0;
const isScanning = hasReceipts && areAllRequestsBeingSmartScanned;
const existingB2BInvoiceReport = useParticipantsInvoiceReport(activePolicyID, CONST.REPORT.INVOICE_RECEIVER_TYPE.BUSINESS, chatReport?.policyID);
const {isDelegateAccessRestricted} = useDelegateNoAccessState();
const {showDelegateNoAccessModal} = useDelegateNoAccessActions();
const [reportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReportID}`);
// The submit button should be success green color only if the user is submitter and the policy does not have Scheduled Submit turned on
// Or if the report has been reopened or retracted
const isWaitingForSubmissionFromCurrentUser = useMemo(
() => canSubmitAndIsAwaitingForCurrentUser(iouReport, chatReport, policy, transactions, transactionViolations, currentUserEmail, currentUserAccountID, reportActions),
[iouReport, chatReport, policy, transactions, transactionViolations, currentUserEmail, currentUserAccountID, reportActions],
);
const confirmPayment = useCallback(
({paymentType: type, payAsBusiness, methodID, paymentMethod}: PaymentActionParams) => {
if (!type) {
return;
}
setPaymentType(type);
setRequestType(CONST.IOU.REPORT_ACTION_TYPE.PAY);
if (isDelegateAccessRestricted) {
showDelegateNoAccessModal();
} else if (hasHeldExpensesReportUtils(iouReport?.reportID)) {
setIsHoldMenuVisible(true);
} else if (chatReport && iouReport) {
startAnimation();
if (isInvoiceReportUtils(iouReport)) {
payInvoice({
paymentMethodType: type,
chatReport,
invoiceReport: iouReport,
invoiceReportCurrentNextStepDeprecated: iouReportNextStep,
introSelected,
currentUserAccountIDParam: currentUserAccountID,
currentUserEmailParam: currentUserEmail,
payAsBusiness,
existingB2BInvoiceReport,
methodID,
paymentMethod,
activePolicy,
betas,
isSelfTourViewed,
});
} else {
payMoneyRequest({
paymentType: type,
chatReport,
iouReport,
introSelected,
iouReportCurrentNextStepDeprecated: iouReportNextStep,
currentUserAccountID,
activePolicy,
policy,
betas,
isSelfTourViewed,
userBillingGraceEndPeriods,
amountOwed,
});
}
}
},
[
isDelegateAccessRestricted,
iouReport,
chatReport,
showDelegateNoAccessModal,
startAnimation,
iouReportNextStep,
introSelected,
currentUserAccountID,
currentUserEmail,
existingB2BInvoiceReport,
activePolicy,
policy,
betas,
isSelfTourViewed,
userBillingGraceEndPeriods,
amountOwed,
],
);
const showDEWModal = useCallback(() => {
showConfirmModal({
title: translate('customApprovalWorkflow.title'),
prompt: translate('customApprovalWorkflow.description'),
confirmText: translate('customApprovalWorkflow.goToExpensifyClassic'),
shouldShowCancelButton: false,
}).then((result) => {
if (result.action !== ModalActions.CONFIRM) {
return;
}
openOldDotLink(CONST.OLDDOT_URLS.INBOX);
});
}, [showConfirmModal, translate]);
const confirmApproval = () => {
if (hasDynamicExternalWorkflow(policy) && !isDEWBetaEnabled) {
showDEWModal();
return;
}
setRequestType(CONST.IOU.REPORT_ACTION_TYPE.APPROVE);
if (isDelegateAccessRestricted) {
showDelegateNoAccessModal();
} else if (hasHeldExpensesReportUtils(iouReport?.reportID)) {
setIsHoldMenuVisible(true);
} else {
startApprovedAnimation();
approveMoneyRequest({
expenseReport: iouReport,
policy: activePolicy,
currentUserAccountIDParam: currentUserAccountID,
currentUserEmailParam: currentUserEmail,
hasViolations,
isASAPSubmitBetaEnabled,
expenseReportCurrentNextStepDeprecated: iouReportNextStep,
betas,
userBillingGraceEndPeriods,
amountOwed,
full: true,
});
}
};
const previewMessage = useMemo(() => {
if (isScanning) {
return totalDisplaySpend ? `${translate('common.receipt')} ${CONST.DOT_SEPARATOR} ${translate('common.scanning')}` : `${translate('common.receipt')}`;
}
if (numberOfPendingRequests === 1 && numberOfRequests === 1) {
return `${translate('common.receipt')} ${CONST.DOT_SEPARATOR} ${translate('iou.pending')}`;
}
if (shouldShowRTERViolationMessage) {
return `${translate('common.receipt')} ${CONST.DOT_SEPARATOR} ${translate('iou.pendingMatch')}`;
}
let payerOrApproverName;
if (isPolicyExpenseChat || isTripRoom) {
payerOrApproverName = getPolicyName({report: chatReport, policy});
} else if (isInvoiceRoom) {
payerOrApproverName = getInvoicePayerName(chatReport, invoiceReceiverPolicy, invoiceReceiverPersonalDetail);
} else {
payerOrApproverName = getDisplayNameForParticipant({
accountID: managerID,
shouldUseShortForm: true,
formatPhoneNumber,
});
}
if (isApproved) {
return translate('iou.managerApproved', payerOrApproverName);
}
let paymentVerb: TranslationPaths = 'iou.payerOwes';
if (iouSettled || iouReport?.isWaitingOnBankAccount) {
paymentVerb = 'iou.payerPaid';
} else if (hasNonReimbursableTransactions) {
paymentVerb = 'iou.payerSpent';
payerOrApproverName = getDisplayNameForParticipant({
accountID: chatReport?.ownerAccountID,
shouldUseShortForm: true,
formatPhoneNumber,
});
}
return translate(paymentVerb, payerOrApproverName);
}, [
isScanning,
numberOfPendingRequests,
numberOfRequests,
shouldShowRTERViolationMessage,
isPolicyExpenseChat,
isTripRoom,
isInvoiceRoom,
isApproved,
iouSettled,
iouReport?.isWaitingOnBankAccount,
hasNonReimbursableTransactions,
translate,
totalDisplaySpend,
chatReport,
policy,
invoiceReceiverPolicy,
invoiceReceiverPersonalDetail,
managerID,
formatPhoneNumber,
]);
/*
Show subtitle if at least one of the expenses is not being smart scanned, and either:
- There is more than one expense – in this case, the "X expenses, Y scanning" subtitle is shown;
- There is only one expense, it has a receipt and is not being smart scanned – in this case, the expense merchant or description is shown;
* There is an edge case when there is only one distance expense with a pending route and amount = 0.
In this case, we don't want to show the merchant or description because it says: "Pending route...", which is already displayed in the amount field.
*/
const expenseCount = useMemo(
() =>
translate('iou.expenseCount', {
count: numberOfRequests,
}),
[translate, numberOfRequests],
);
const reportStatus = useMemo(
() =>
getReportStatusTranslation({
stateNum: iouReport?.stateNum ?? action?.childStateNum,
statusNum: iouReport?.statusNum ?? action?.childStatusNum,
translate,
}),
[action?.childStateNum, action?.childStatusNum, iouReport?.stateNum, iouReport?.statusNum, translate],
);
const shouldShowReportStatus = !!reportStatus && !!expenseCount;
const reportStatusColorStyle = useMemo(
() => getReportStatusColorStyle(theme, iouReport?.stateNum ?? action?.childStateNum, iouReport?.statusNum ?? action?.childStatusNum),
[action?.childStateNum, action?.childStatusNum, iouReport?.stateNum, iouReport?.statusNum, theme],
);
const totalAmountStyle = shouldUseNarrowLayout ? [styles.flexColumnReverse, styles.alignItemsStretch] : [styles.flexRow, styles.alignItemsCenter];
useEffect(() => {
if (!isPaidAnimationRunning || isApprovedAnimationRunning || isSubmittingAnimationRunning) {
return;
}
previewMessageOpacity.set(
withTiming(0.75, {duration: CONST.ANIMATION_PAID_DURATION / 2}, () => {
previewMessageOpacity.set(withTiming(1, {duration: CONST.ANIMATION_PAID_DURATION / 2}));
}),
);
// We only want to animate the text when the text changes
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [previewMessage, previewMessageOpacity]);
useEffect(() => {
if (!iouSettled) {
return;
}
checkMarkScale.set(isPaidAnimationRunning ? withDelay(CONST.ANIMATION_PAID_CHECKMARK_DELAY, withSpring(1, {duration: CONST.ANIMATION_PAID_DURATION})) : 1);
}, [isPaidAnimationRunning, iouSettled, checkMarkScale]);
useEffect(() => {
if (!isApproved) {
return;
}
thumbsUpScale.set(isApprovedAnimationRunning ? withDelay(CONST.ANIMATION_THUMBS_UP_DELAY, withSpring(1, {duration: CONST.ANIMATION_THUMBS_UP_DURATION})) : 1);
}, [isApproved, isApprovedAnimationRunning, thumbsUpScale]);
const carouselTransactions = useMemo(() => (shouldShowAccessPlaceHolder ? [] : transactions.slice(0, 11)), [shouldShowAccessPlaceHolder, transactions]);
const prevCarouselTransactionLength = useRef(0);
useEffect(() => {
return () => {
prevCarouselTransactionLength.current = carouselTransactions.length;
};
}, [carouselTransactions.length]);
const [currentIndex, setCurrentIndex] = useState(0);
const [currentVisibleItems, setCurrentVisibleItems] = useState([0]);
const [footerWidth, setFooterWidth] = useState(0);
// optimisticIndex - value for index we are scrolling to with an arrow button or undefined after scroll is completed
// value ensures that disabled state is applied instantly and not overridden by onViewableItemsChanged when scrolling
// undefined makes arrow buttons react on currentIndex changes when scrolling manually
const [optimisticIndex, setOptimisticIndex] = useState<number | undefined>(undefined);
const carouselRef = useRef<FlashListRef<Transaction> | null>(null);
const prevTransactionCountForScroll = useRef(carouselTransactions.length);
const [carouselKey, setCarouselKey] = useState(0);
// Reset carousel when transitioning from empty to non-empty data.
// scrollToOffset doesn't clear RecyclerListView's internal layout cache on iOS mobile web,
// so we force a full re-mount via key to prevent new items from rendering off-screen.
useEffect(() => {
if (carouselTransactions.length > 0 && prevTransactionCountForScroll.current === 0) {
setCurrentIndex(0);
setOptimisticIndex(undefined);
setCarouselKey((prev) => prev + 1);
}
prevTransactionCountForScroll.current = carouselTransactions.length;
}, [carouselTransactions.length]);
const visibleItemsOnEndCount = useMemo(() => {
const lastItemWidth = transactions.length > MAX_PREVIEWS_NUMBER ? footerWidth : reportPreviewStyles.transactionPreviewCarouselStyle.width;
const lastItemWithGap = lastItemWidth + styles.gap2.gap;
const itemWithGap = reportPreviewStyles.transactionPreviewCarouselStyle.width + styles.gap2.gap;
return Math.floor((currentWidth - 2 * styles.pl2.paddingLeft - lastItemWithGap) / itemWithGap) + 1;
}, [transactions.length, footerWidth, reportPreviewStyles.transactionPreviewCarouselStyle.width, styles.gap2.gap, styles.pl2.paddingLeft, currentWidth]);
const viewabilityConfig = useMemo(() => {
return {itemVisiblePercentThreshold: 100};
}, []);
const carouselTransactionsRef = useRef(carouselTransactions);
useEffect(() => {
carouselTransactionsRef.current = carouselTransactions;
}, [carouselTransactions]);
const isFocused = useIsFocused();
const isFocusedRef = useRef(isFocused);
useEffect(() => {
isFocusedRef.current = isFocused;
}, [isFocused]);
useEffect(() => {
const index = carouselTransactions.findIndex((transaction) => newTransactionIDs?.has(transaction.transactionID));
if (index < 0) {
return;
}
const newTransaction = carouselTransactions.at(index);
setTimeout(() => {
if (!isFocusedRef.current) {
return;
}
// If the new transaction is not available at the index it was on before the delay, avoid the scrolling
// because we are scrolling to either a wrong or unavailable transaction (which can cause crash).
if (newTransaction?.transactionID !== carouselTransactionsRef.current.at(index)?.transactionID) {
return;
}
carouselRef.current?.scrollToIndex({
index,
viewOffset: -2 * styles.gap2.gap,
animated: true,
});
}, CONST.ANIMATED_TRANSITION);
// We only want to scroll to a new transaction when the set of new transaction IDs changes.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [newTransactionIDs]);
const onViewableItemsChanged = useRef(({viewableItems}: {viewableItems: ViewToken[]; changed: ViewToken[]}) => {
const newIndex = viewableItems.at(0)?.index;
if (typeof newIndex === 'number') {
setCurrentIndex(newIndex);
}
const viewableItemsIndexes = viewableItems.map((item) => item.index).filter((item): item is number => item !== null);
setCurrentVisibleItems(viewableItemsIndexes);
}).current;
const snapOffsets = carouselTransactions.map((_, index) => index * (reportPreviewStyles.transactionPreviewCarouselStyle.width + styles.transactionsCarouselGap.width));
const handleChange = (index: number) => {
if (index > carouselTransactions.length - visibleItemsOnEndCount) {
const lastScrollableIndex = carouselTransactions.length - visibleItemsOnEndCount;
setOptimisticIndex(lastScrollableIndex);
carouselRef.current?.scrollToOffset({
offset: snapOffsets.at(lastScrollableIndex) ?? 0,
animated: true,
});
return;
}
if (index < 0) {
setOptimisticIndex(0);
carouselRef.current?.scrollToTop({animated: true});
return;
}
if (index === carouselTransactions.length - visibleItemsOnEndCount) {
setOptimisticIndex(index);
carouselRef.current?.scrollToEnd({animated: true});
return;
}
setOptimisticIndex(index);
carouselRef.current?.scrollToOffset({
offset: snapOffsets.at(index) ?? 0,
animated: true,
});
};
const renderItem = (itemInfo: ListRenderItemInfo<Transaction>) => {
if (itemInfo.index > MAX_PREVIEWS_NUMBER - 1) {
return (
<View
style={[styles.p5, styles.justifyContentCenter]}
onLayout={(e) => setFooterWidth(e.nativeEvent.layout.width)}
>
<Text style={{color: colors.blue600}}>
+{transactions.length - MAX_PREVIEWS_NUMBER} {translate('common.more').toLowerCase()}
</Text>
</View>
);
}
return renderTransactionItem(itemInfo);
};
// The button should expand up to transaction width
const buttonMaxWidth =
!shouldUseNarrowLayout && reportPreviewStyles.transactionPreviewCarouselStyle.width >= CONST.REPORT.TRANSACTION_PREVIEW.CAROUSEL.MIN_WIDE_WIDTH
? {maxWidth: reportPreviewStyles.transactionPreviewCarouselStyle.width}
: {};
useEffect(() => {
if (
optimisticIndex === undefined ||
optimisticIndex !== currentIndex ||
// currentIndex is still the same as target (f.ex. 0), but not yet scrolled to the far left
(currentVisibleItems.at(0) !== optimisticIndex && optimisticIndex !== undefined) ||
// currentIndex reached, but not scrolled to the end
(optimisticIndex === carouselTransactions.length - visibleItemsOnEndCount && currentVisibleItems.length !== visibleItemsOnEndCount)
) {
return;
}
setOptimisticIndex(undefined);
}, [carouselTransactions.length, currentIndex, currentVisibleItems, currentVisibleItems.length, optimisticIndex, visibleItemsOnEndCount]);
const openReportFromPreview = useCallback(() => {
if (!iouReportID) {
return;
}
startSpan(`${CONST.TELEMETRY.SPAN_OPEN_REPORT}_${iouReportID}`, {
name: 'MoneyRequestReportPreviewContent',
op: CONST.TELEMETRY.SPAN_OPEN_REPORT,
});
// Small screens navigate to full report view since super wide RHP
// is not available on narrow layouts and would break the navigation logic.
if (isSmallScreenWidth) {
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(iouReportID, undefined, undefined, Navigation.getActiveRoute()));
} else {
Navigation.navigate(
ROUTES.EXPENSE_REPORT_RHP.getRoute({
reportID: iouReportID,
backTo: Navigation.getActiveRoute(),
}),
);
}
}, [iouReportID, isSmallScreenWidth]);
const isDEWPolicy = hasDynamicExternalWorkflow(policy);
const isDEWSubmitPending = hasPendingDEWSubmit(iouReportMetadata, isDEWPolicy);
const reportPreviewAction = useMemo(() => {
return getReportPreviewAction({
isReportArchived: isIouReportArchived || isChatReportArchived,
currentUserAccountID: currentUserDetails.accountID,
currentUserLogin: currentUserDetails.login ?? '',
report: iouReport,
policy,
transactions,
bankAccountList,
invoiceReceiverPolicy,
isPaidAnimationRunning,
isApprovedAnimationRunning,
isSubmittingAnimationRunning,
isDEWSubmitPending,
violationsData: transactionViolations,
reportMetadata: iouReportMetadata,
});
}, [
bankAccountList,
isIouReportArchived,
isChatReportArchived,
currentUserDetails.accountID,
currentUserDetails.login,
iouReport,
policy,
transactions,
invoiceReceiverPolicy,
isPaidAnimationRunning,
isApprovedAnimationRunning,
isSubmittingAnimationRunning,
transactionViolations,
isDEWSubmitPending,
iouReportMetadata,
]);
const addExpenseDropdownOptions = useMemo(
() =>
getAddExpenseDropdownOptions({
translate,
icons: expensifyIcons,
iouReportID: iouReport?.reportID,
policy,
userBillingGraceEndPeriodCollection: userBillingGraceEndPeriods,
draftTransactionIDs,
amountOwed,
ownerBillingGraceEndPeriod,
iouRequestBackToReport: chatReportID,
unreportedExpenseBackToReport: iouReport?.parentReportID,
lastDistanceExpenseType,
}),
[
translate,
expensifyIcons,
iouReport?.reportID,
iouReport?.parentReportID,
policy,
userBillingGraceEndPeriods,
amountOwed,
chatReportID,
lastDistanceExpenseType,
ownerBillingGraceEndPeriod,
draftTransactionIDs,
],
);
const isReportDeleted = action?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE;
const formattedAmount = getTotalAmountForIOUReportPreviewButton(iouReport, policy, reportPreviewAction);
const reportPreviewActions = {
[CONST.REPORT.REPORT_PREVIEW_ACTIONS.SUBMIT]: (
<AnimatedSubmitButton
success={isWaitingForSubmissionFromCurrentUser}
text={translate('common.submit')}
onPress={() => {
if (hasDynamicExternalWorkflow(policy) && !isDEWBetaEnabled) {
showDEWModal();
return;
}
startSubmittingAnimation();
submitReport(
iouReport,
policy,
currentUserAccountID,
currentUserEmail,
hasViolations,
isASAPSubmitBetaEnabled,
iouReportNextStep,
userBillingGraceEndPeriods,
amountOwed,
);
}}
isSubmittingAnimationRunning={isSubmittingAnimationRunning}
onAnimationFinish={stopAnimation}
sentryLabel={CONST.SENTRY_LABEL.REPORT_PREVIEW.SUBMIT_BUTTON}
/>
),
[CONST.REPORT.REPORT_PREVIEW_ACTIONS.APPROVE]: (
<Button
text={translate('iou.approve')}
success
onPress={() => confirmApproval()}
sentryLabel={CONST.SENTRY_LABEL.REPORT_PREVIEW.APPROVE_BUTTON}
/>
),
[CONST.REPORT.REPORT_PREVIEW_ACTIONS.PAY]: (
<AnimatedSettlementButton
onlyShowPayElsewhere={shouldShowOnlyPayElsewhere}
isPaidAnimationRunning={isPaidAnimationRunning}
isApprovedAnimationRunning={isApprovedAnimationRunning}
canIOUBePaid={canIOUBePaidAndApproved || isPaidAnimationRunning}
onAnimationFinish={stopAnimation}
chatReportID={chatReportID}
policyID={policy?.id}
iouReport={iouReport}
currency={iouReport?.currency}
wrapperStyle={buttonMaxWidth}
onPress={confirmPayment}
onPaymentOptionsShow={onPaymentOptionsShow}
onPaymentOptionsHide={onPaymentOptionsHide}
formattedAmount={formattedAmount}
confirmApproval={confirmApproval}
enablePaymentsRoute={ROUTES.ENABLE_PAYMENTS}
shouldHidePaymentOptions={!shouldShowPayButton}
kycWallAnchorAlignment={{
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.LEFT,
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.BOTTOM,
}}
paymentMethodDropdownAnchorAlignment={{
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.RIGHT,
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.BOTTOM,
}}
isDisabled={isOffline && !canAllowSettlement}
isLoading={!isOffline && !canAllowSettlement}
sentryLabel={CONST.SENTRY_LABEL.REPORT_PREVIEW.PAY_BUTTON}
/>
),
[CONST.REPORT.REPORT_PREVIEW_ACTIONS.EXPORT_TO_ACCOUNTING]: connectedIntegration ? (
<ExportWithDropdownMenu
report={iouReport}
reportActions={reportActions}
connectionName={connectedIntegration}
wrapperStyle={styles.flexReset}
dropdownAnchorAlignment={{
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.RIGHT,
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.BOTTOM,
}}
sentryLabel={CONST.SENTRY_LABEL.REPORT_PREVIEW.EXPORT_BUTTON}
/>
) : null,
[CONST.REPORT.REPORT_PREVIEW_ACTIONS.VIEW]: (
<Button
text={translate('common.view')}
onPress={() => {
openReportFromPreview();
}}
sentryLabel={CONST.SENTRY_LABEL.REPORT_PREVIEW.VIEW_BUTTON}
/>
),
[CONST.REPORT.REPORT_PREVIEW_ACTIONS.ADD_EXPENSE]: (
<ButtonWithDropdownMenu
onPress={() => {}}
shouldAlwaysShowDropdownMenu
customText={translate('iou.addExpense')}
options={addExpenseDropdownOptions}
isSplitButton={false}
anchorAlignment={{
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.RIGHT,
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.BOTTOM,
}}
sentryLabel={CONST.SENTRY_LABEL.REPORT_PREVIEW.ADD_EXPENSE_BUTTON}
/>
),
};
const adjustScroll = useCallback(() => {
// Workaround for a known React Native bug on Android (https://github.com/facebook/react-native/issues/27504):
// When the FlatList is scrolled to the end and the last item is deleted, a blank space is left behind.
// To fix this, we detect when onEndReached is triggered due to an item deletion,
// and programmatically scroll to the end to fill the space.
if (carouselTransactions.length >= prevCarouselTransactionLength.current || !shouldAdjustScroll) {
return;
}
prevCarouselTransactionLength.current = carouselTransactions.length;
carouselRef.current?.scrollToEnd();
}, [carouselTransactions.length]);
const renderSeparator = () => <View style={styles.transactionsCarouselGap} />;
const getItemType = (_item: Transaction, index: number) => {
return index === MAX_PREVIEWS_NUMBER ? ITEM_LAYOUT_TYPE.SHOW_MORE : ITEM_LAYOUT_TYPE.PREVIEW;
};
return (
<View
onLayout={onWrapperLayout}
testID="MoneyRequestReportPreviewContent-wrapper"
fsClass={forwardedFSClass}
>
<OfflineWithFeedback
pendingAction={iouReport?.pendingFields?.preview}
shouldDisableOpacity={!!(action.pendingAction ?? action.isOptimisticAction)}
needsOffscreenAlphaCompositing
style={styles.mt1}
>
<View
style={[styles.chatItemMessage, isReportDeleted && [styles.cursorDisabled, styles.pointerEventsAuto], containerStyles]}
onLayout={onCarouselLayout}
testID="carouselWidthSetter"
>
<PressableWithoutFeedback
onPress={onPress}
onPressIn={() => canUseTouchScreen() && ControlSelection.block()}
onPressOut={() => ControlSelection.unblock()}
onLongPress={(event) => {
if (!shouldDisplayContextMenu) {
return;
}
showContextMenuForReport(event, contextMenuAnchor, chatReportID, action, checkIfContextMenuActive);
}}
shouldUseHapticsOnLongPress
style={[
styles.flexRow,
styles.justifyContentBetween,
StyleUtils.getBackgroundColorStyle(theme.cardBG),
shouldShowBorder ? styles.borderedContentCardLarge : styles.reportContainerBorderRadius,
isReportDeleted && styles.pointerEventsNone,
]}
role={getButtonRole(true)}
isNested
accessibilityLabel={translate('iou.viewDetails')}
sentryLabel={CONST.SENTRY_LABEL.REPORT_PREVIEW.CARD}
>
<View
style={[
StyleUtils.getBackgroundColorStyle(theme.cardBG),
styles.reportContainerBorderRadius,
styles.w100,
(isHovered || isScanning || isWhisper) && styles.reportPreviewBoxHoverBorder,
]}
>
<View style={[reportPreviewStyles.wrapperStyle]}>
<View style={[reportPreviewStyles.contentContainerStyle, styles.gap4]}>
<View style={[styles.expenseAndReportPreviewTextContainer, styles.overflowHidden]}>
<View style={[styles.flexRow, styles.justifyContentBetween, styles.flexShrink1, styles.gap1]}>
<View style={[styles.flexColumn, styles.gap1, styles.flexShrink1]}>
<View style={[styles.flexRow, styles.mw100, styles.flexShrink1]}>
<Animated.View style={[styles.flexRow, styles.alignItemsCenter, previewMessageStyle, styles.flexShrink1]}>
<Text
style={[styles.headerText]}
testID="MoneyRequestReportPreview-reportName"
>
{/* This will be fixed as follow up https://github.com/Expensify/App/pull/75357 */}
{/* eslint-disable-next-line @typescript-eslint/no-deprecated */}
{getReportName({report: iouReport, reportAttributes}) || action.childReportName}
</Text>
</Animated.View>
</View>
{showStatusAndSkeleton && shouldShowSkeleton ? (
<MoneyReportHeaderStatusBarSkeleton reasonAttributes={skeletonReasonAttributes} />
) : (
(!shouldShowEmptyPlaceholder || shouldShowAccessPlaceHolder) &&
(shouldShowReportStatus || !shouldShowAccessPlaceHolder) && (
<View style={[styles.flexRow, styles.justifyContentStart, styles.alignItemsCenter]}>
{shouldShowReportStatus && (
<StatusBadge
text={reportStatus}
backgroundColor={reportStatusColorStyle?.backgroundColor}
textColor={reportStatusColorStyle?.textColor}
badgeStyles={styles.mr1}
/>
)}
{!shouldShowAccessPlaceHolder && <Text style={[styles.textLabelSupporting, styles.lh16]}>{expenseCount}</Text>}
</View>
)
)}
</View>
{!shouldUseNarrowLayout && !shouldShowAccessPlaceHolder && transactions.length > 2 && reportPreviewStyles.expenseCountVisible && (
<View style={[styles.flexRow, styles.alignItemsCenter]}>
<PressableWithFeedback
accessibilityRole="button"
accessible
accessibilityLabel={translate('common.previous')}
style={[styles.reportPreviewArrowButton, {backgroundColor: theme.buttonDefaultBG}]}
onPress={() => handleChange(currentIndex - 1)}
disabled={optimisticIndex !== undefined ? optimisticIndex === 0 : currentIndex === 0 && currentVisibleItems.at(0) === 0}
disabledStyle={[styles.cursorDefault, styles.buttonOpacityDisabled]}
sentryLabel={CONST.SENTRY_LABEL.REPORT_PREVIEW.CAROUSEL_PREVIOUS}
>
<Icon
src={expensifyIcons.BackArrow}
small
fill={theme.icon}
isButtonIcon
/>
</PressableWithFeedback>
<PressableWithFeedback
accessibilityRole="button"
accessible
accessibilityLabel={translate('common.next')}
style={[styles.reportPreviewArrowButton, {backgroundColor: theme.buttonDefaultBG}]}
onPress={() => handleChange(currentIndex + 1)}
disabled={
optimisticIndex
? optimisticIndex + visibleItemsOnEndCount >= carouselTransactions.length
: currentVisibleItems.at(-1) === carouselTransactions.length - 1
}
disabledStyle={[styles.cursorDefault, styles.buttonOpacityDisabled]}
sentryLabel={CONST.SENTRY_LABEL.REPORT_PREVIEW.CAROUSEL_NEXT}
>
<Icon
src={expensifyIcons.ArrowRight}
small
fill={theme.icon}
isButtonIcon