Skip to content

Commit f6ccfc2

Browse files
authored
Merge pull request Expensify#64082 from FitseTLT/fix-money-report-preview-pending-delete-transactions-bug
fix - Expense - Expense preview is blank briefly when deleted offline and returning online
2 parents cb198d1 + 39d88f5 commit f6ccfc2

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

src/hooks/useReportWithTransactionsAndViolations.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
22
import {reportTransactionsSelector} from '@libs/ReportUtils';
3+
import CONST from '@src/CONST';
34
import ONYXKEYS from '@src/ONYXKEYS';
45
import type {Report, Transaction, TransactionViolation} from '@src/types/onyx';
6+
import useNetwork from './useNetwork';
57
import useOnyx from './useOnyx';
68

79
const 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

3236
export default useReportWithTransactionsAndViolations;

tests/utils/collections/transaction.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ export default function createRandomTransaction(index: number): Transaction {
3434
modifiedMerchant: randWord(),
3535
originalAmount: randAmount(),
3636
originalCurrency: rand(Object.values(CONST.CURRENCY)),
37-
pendingAction: rand(Object.values(CONST.RED_BRICK_ROAD_PENDING_ACTION)),
3837
reportID: index.toString(),
3938
transactionID: index.toString(),
4039
tag: randWord(),

0 commit comments

Comments
 (0)