@@ -22,7 +22,7 @@ import CONST from '@src/CONST';
2222import ONYXKEYS from '@src/ONYXKEYS' ;
2323import { FILTER_KEYS } from '@src/types/form/SearchAdvancedFiltersForm' ;
2424import type { SearchAdvancedFiltersForm } from '@src/types/form/SearchAdvancedFiltersForm' ;
25- import type { LastPaymentMethod , LastPaymentMethodType , Policy , SearchResults } from '@src/types/onyx' ;
25+ import type { LastPaymentMethod , LastPaymentMethodType , Policy } from '@src/types/onyx' ;
2626import type { ConnectionName } from '@src/types/onyx/Policy' ;
2727import type { SearchPolicy , SearchReport , SearchTransaction } from '@src/types/onyx/SearchResults' ;
2828import type Nullable from '@src/types/utils/Nullable' ;
@@ -32,7 +32,8 @@ function handleActionButtonPress(
3232 item : TransactionListItemType | TransactionReportGroupListItemType ,
3333 goToItem : ( ) => void ,
3434 isInMobileSelectionMode : boolean ,
35- snapshotData : SearchResults [ 'data' ] | undefined ,
35+ snapshotReport : SearchReport ,
36+ snapshotPolicy : SearchPolicy ,
3637 lastPaymentMethod : OnyxEntry < LastPaymentMethod > ,
3738 currentSearchKey ?: SearchKey ,
3839) {
@@ -42,29 +43,28 @@ function handleActionButtonPress(
4243 const allReportTransactions = ( isTransactionGroupListItemType ( item ) ? item . transactions : [ item ] ) as SearchTransaction [ ] ;
4344 const hasHeldExpense = hasHeldExpenses ( '' , allReportTransactions ) ;
4445
45- if ( hasHeldExpense || isInMobileSelectionMode || ! snapshotData ) {
46+ if ( hasHeldExpense || isInMobileSelectionMode ) {
4647 goToItem ( ) ;
4748 return ;
4849 }
4950
5051 switch ( item . action ) {
5152 case CONST . SEARCH . ACTION_TYPES . PAY :
52- getPayActionCallback ( hash , item , goToItem , snapshotData , lastPaymentMethod , currentSearchKey ) ;
53+ getPayActionCallback ( hash , item , goToItem , snapshotReport , snapshotPolicy , lastPaymentMethod , currentSearchKey ) ;
5354 return ;
5455 case CONST . SEARCH . ACTION_TYPES . APPROVE :
5556 approveMoneyRequestOnSearch ( hash , [ item . reportID ] , transactionID , currentSearchKey ) ;
5657 return ;
5758 case CONST . SEARCH . ACTION_TYPES . SUBMIT : {
58- const policy = snapshotData ?. [ `${ ONYXKEYS . COLLECTION . POLICY } ${ item . policyID } ` ] ?? { } ;
59- submitMoneyRequestOnSearch ( hash , [ item ] , [ policy ] , transactionID , currentSearchKey ) ;
59+ submitMoneyRequestOnSearch ( hash , [ item ] , [ snapshotPolicy ] , transactionID , currentSearchKey ) ;
6060 return ;
6161 }
6262 case CONST . SEARCH . ACTION_TYPES . EXPORT_TO_ACCOUNTING : {
6363 if ( ! item ) {
6464 return ;
6565 }
6666
67- const policy = ( snapshotData ?. [ ` ${ ONYXKEYS . COLLECTION . POLICY } ${ item . policyID } ` ] ?? { } ) as Policy ;
67+ const policy = ( snapshotPolicy ?? { } ) as Policy ;
6868 const connectedIntegration = getValidConnectedIntegration ( policy ) ;
6969
7070 if ( ! connectedIntegration ) {
@@ -97,7 +97,8 @@ function getPayActionCallback(
9797 hash : number ,
9898 item : TransactionListItemType | TransactionReportGroupListItemType ,
9999 goToItem : ( ) => void ,
100- snapshotData : SearchResults [ 'data' ] ,
100+ snapshotReport : SearchReport ,
101+ snapshotPolicy : SearchPolicy ,
101102 lastPaymentMethod : OnyxEntry < LastPaymentMethod > ,
102103 currentSearchKey ?: SearchKey ,
103104) {
@@ -108,16 +109,15 @@ function getPayActionCallback(
108109 return ;
109110 }
110111
111- const report = snapshotData ?. [ `${ ONYXKEYS . COLLECTION . REPORT } ${ item . reportID } ` ] ?? { } ;
112- const amount = Math . abs ( ( report ?. total ?? 0 ) - ( report ?. nonReimbursableTotal ?? 0 ) ) ;
112+ const amount = Math . abs ( ( snapshotReport ?. total ?? 0 ) - ( snapshotReport ?. nonReimbursableTotal ?? 0 ) ) ;
113113 const transactionID = isTransactionListItemType ( item ) ? [ item . transactionID ] : undefined ;
114114
115115 if ( lastPolicyPaymentMethod === CONST . IOU . PAYMENT_TYPE . ELSEWHERE ) {
116116 payMoneyRequestOnSearch ( hash , [ { reportID : item . reportID , amount, paymentType : lastPolicyPaymentMethod } ] , transactionID , currentSearchKey ) ;
117117 return ;
118118 }
119119
120- const hasVBBA = ! ! snapshotData ?. [ ` ${ ONYXKEYS . COLLECTION . POLICY } ${ item . policyID } ` ] ?. achAccount ?. bankAccountID ;
120+ const hasVBBA = ! ! snapshotPolicy ?. achAccount ?. bankAccountID ;
121121 if ( hasVBBA ) {
122122 payMoneyRequestOnSearch ( hash , [ { reportID : item . reportID , amount, paymentType : lastPolicyPaymentMethod } ] , transactionID , currentSearchKey ) ;
123123 return ;
0 commit comments