11import type { OnyxCollection , OnyxEntry } from 'react-native-onyx' ;
22import { reportTransactionsSelector } from '@libs/ReportUtils' ;
3+ import CONST from '@src/CONST' ;
34import ONYXKEYS from '@src/ONYXKEYS' ;
45import type { Report , Transaction , TransactionViolation } from '@src/types/onyx' ;
6+ import useNetwork from './useNetwork' ;
57import useOnyx from './useOnyx' ;
68
79const DEFAULT_TRANSACTIONS : Transaction [ ] = [ ] ;
@@ -13,20 +15,22 @@ function useReportWithTransactionsAndViolations(reportID?: string): [OnyxEntry<R
1315 selector : ( _transactions ) => reportTransactionsSelector ( _transactions , reportID ) ,
1416 canBeMissing : true ,
1517 } ) ;
18+ const { isOffline} = useNetwork ( ) ;
19+ const filteredTransactions = transactions ?. filter ( ( transaction ) => isOffline || transaction ?. pendingAction !== CONST . RED_BRICK_ROAD_PENDING_ACTION . DELETE ) ;
1620 const [ violations ] = useOnyx (
1721 ONYXKEYS . COLLECTION . TRANSACTION_VIOLATIONS ,
1822 {
1923 selector : ( allViolations ) =>
2024 Object . fromEntries (
2125 Object . entries ( allViolations ?? { } ) . filter ( ( [ key ] ) =>
22- transactions ?. some ( ( transaction ) => transaction . transactionID === key . replace ( ONYXKEYS . COLLECTION . TRANSACTION_VIOLATIONS , '' ) ) ,
26+ filteredTransactions ?. some ( ( transaction ) => transaction . transactionID === key . replace ( ONYXKEYS . COLLECTION . TRANSACTION_VIOLATIONS , '' ) ) ,
2327 ) ,
2428 ) ,
2529 canBeMissing : true ,
2630 } ,
27- [ transactions ] ,
31+ [ filteredTransactions ] ,
2832 ) ;
29- return [ report , transactions ?? DEFAULT_TRANSACTIONS , violations ?? DEFAULT_VIOLATIONS ] ;
33+ return [ report , filteredTransactions ?? DEFAULT_TRANSACTIONS , violations ?? DEFAULT_VIOLATIONS ] ;
3034}
3135
3236export default useReportWithTransactionsAndViolations ;
0 commit comments