@@ -25,6 +25,7 @@ import {
2525 getPolicyFromSearchSnapshot ,
2626 getReportFromSearchSnapshot ,
2727 getReportType ,
28+ getChatReportWithFallback ,
2829 getSearchApproveOnyxData ,
2930 getSearchPayOnyxData ,
3031 getTotalFormattedAmount ,
@@ -1400,23 +1401,22 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) {
14001401 }
14011402
14021403 const isItemInvoice = isInvoiceReport ( iouReport ) ;
1403- let chatReport = getChatReportForBulkPay ( iouReport , item . chatReportID , searchData , allReports ) ;
1404- let isFallbackChatReport = false ;
1405- if ( ! chatReport ) {
1406- // The chat report is only needed for optimistic chat updates, so when it isn't loaded, pay with a fallback
1407- // built from the known IDs and let the server fill in the chat data.
1408- // Invoices are the exception. They genuinely need the invoice room data such as receiver type and pay-as-business.
1409- const fallbackChatReportID = item . chatReportID ?? iouReport . chatReportID ?? iouReport . parentReportID ;
1410- if ( isItemInvoice || ! fallbackChatReportID ) {
1411- Log . info ( '[BulkPay] Skipping report: chat report not found in the search snapshot or Onyx' , false , {
1412- reportID : item . reportID ,
1413- chatReportID : fallbackChatReportID ,
1414- isItemInvoice,
1415- } ) ;
1416- continue ;
1417- }
1418- chatReport = { reportID : fallbackChatReportID , policyID : item . policyID ?? iouReport . policyID } ;
1419- isFallbackChatReport = true ;
1404+ const fallbackChatReportID = item . chatReportID ?? iouReport . chatReportID ?? iouReport . parentReportID ;
1405+ const fallbackPolicyID = iouReport . policyID ?? item . policyID ;
1406+ const { chatReport, isFallbackChatReport} = getChatReportWithFallback (
1407+ getChatReportForBulkPay ( iouReport , item . chatReportID , searchData , allReports ) ,
1408+ fallbackChatReportID ,
1409+ fallbackPolicyID ,
1410+ ) ;
1411+ // The fallback covers money requests only. Invoices genuinely need the invoice room data such as
1412+ // receiver type and pay-as-business, so skip them when the chat isn't loaded.
1413+ if ( ! chatReport || ( isItemInvoice && isFallbackChatReport ) ) {
1414+ Log . info ( '[BulkPay] Skipping report: chat report not found in the search snapshot or Onyx' , false , {
1415+ reportID : item . reportID ,
1416+ chatReportID : fallbackChatReportID ,
1417+ isItemInvoice,
1418+ } ) ;
1419+ continue ;
14201420 }
14211421
14221422 const rawPaymentMethod = paymentMethod ?? getLastPolicyPaymentMethod ( item . policyID , personalPolicyID , lastPaymentMethods , undefined , isIOUReportUtil ( item . reportID ) ) ;
0 commit comments