11import Onyx from 'react-native-onyx' ;
2- import type { OnyxEntry , OnyxUpdate } from 'react-native-onyx' ;
2+ import type { OnyxCollection , OnyxEntry , OnyxUpdate } from 'react-native-onyx' ;
33import type { ValueOf } from 'type-fest' ;
44import type { FormOnyxValues } from '@components/Form/types' ;
55import type { PaymentData , SearchQueryJSON } from '@components/Search/types' ;
@@ -13,6 +13,7 @@ import fileDownload from '@libs/fileDownload';
1313import enhanceParameters from '@libs/Network/enhanceParameters' ;
1414import { rand64 } from '@libs/NumberUtils' ;
1515import { getPersonalPolicy , getSubmitToAccountID , getValidConnectedIntegration } from '@libs/PolicyUtils' ;
16+ import { getIOUActionForTransactionID } from '@libs/ReportActionsUtils' ;
1617import type { OptimisticExportIntegrationAction } from '@libs/ReportUtils' ;
1718import { buildOptimisticExportIntegrationAction , hasHeldExpenses , isExpenseReport , isInvoiceReport , isIOUReport as isIOUReportUtil } from '@libs/ReportUtils' ;
1819import type { SearchKey } from '@libs/SearchUIUtils' ;
@@ -22,7 +23,7 @@ import CONST from '@src/CONST';
2223import ONYXKEYS from '@src/ONYXKEYS' ;
2324import { FILTER_KEYS } from '@src/types/form/SearchAdvancedFiltersForm' ;
2425import type { SearchAdvancedFiltersForm } from '@src/types/form/SearchAdvancedFiltersForm' ;
25- import type { LastPaymentMethod , LastPaymentMethodType , Policy } from '@src/types/onyx' ;
26+ import type { LastPaymentMethod , LastPaymentMethodType , Policy , ReportActions , Transaction } from '@src/types/onyx' ;
2627import type { PaymentInformation } from '@src/types/onyx/LastPaymentMethod' ;
2728import type { ConnectionName } from '@src/types/onyx/Policy' ;
2829import type { SearchPolicy , SearchReport , SearchTransaction } from '@src/types/onyx/SearchResults' ;
@@ -386,8 +387,24 @@ function updateSearchResultsWithTransactionThreadReportID(hash: number, transact
386387 Onyx . merge ( `${ ONYXKEYS . COLLECTION . SNAPSHOT } ${ hash } ` , onyxUpdate ) ;
387388}
388389
389- function holdMoneyRequestOnSearch ( hash : number , transactionIDList : string [ ] , comment : string ) {
390+ function holdMoneyRequestOnSearch ( hash : number , transactionIDList : string [ ] , comment : string , allTransactions : OnyxCollection < Transaction > , allReportActions : OnyxCollection < ReportActions > ) {
390391 const { optimisticData, finallyData} = getOnyxLoadingData ( hash ) ;
392+ transactionIDList . forEach ( ( transactionID ) => {
393+ const transaction = allTransactions ?. [ `${ ONYXKEYS . COLLECTION . TRANSACTION } ${ transactionID } ` ] ;
394+ const reportActions = allReportActions ?. [ `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ transaction ?. reportID } ` ] ?? { } ;
395+ const iouReportAction = getIOUActionForTransactionID ( Object . values ( reportActions ?? { } ) , transactionID ) ;
396+ if ( iouReportAction ) {
397+ optimisticData . push ( {
398+ key : `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ transaction ?. reportID } ` ,
399+ onyxMethod : Onyx . METHOD . MERGE ,
400+ value : {
401+ [ iouReportAction . reportActionID ] : {
402+ childVisibleActionCount : ( iouReportAction ?. childVisibleActionCount ?? 0 ) + 1 ,
403+ } ,
404+ } ,
405+ } ) ;
406+ }
407+ } ) ;
391408
392409 API . write ( WRITE_COMMANDS . HOLD_MONEY_REQUEST_ON_SEARCH , { hash, transactionIDList, comment} , { optimisticData, finallyData} ) ;
393410}
0 commit comments