Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/libs/TransactionPreviewUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {TranslationPaths} from '@src/languages/types';
import ROUTES from '@src/ROUTES';
import type * as OnyxTypes from '@src/types/onyx';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import {abandonReviewDuplicateTransactions, setReviewDuplicatesKey} from './actions/Transaction';
import {setReviewDuplicatesKey} from './actions/Transaction';
import {isCategoryMissing} from './CategoryUtils';
import {convertToDisplayString} from './CurrencyUtils';
import DateUtils from './DateUtils';
Expand Down Expand Up @@ -79,16 +79,18 @@ const getReviewNavigationRoute = (
policyCategories: OnyxTypes.PolicyCategories | undefined,
transactionReport: OnyxEntry<OnyxTypes.Report>,
) => {
// Clear the draft before selecting a different expense to prevent merging fields from the previous expense
// Use set method to prevent merging fields from the previous expense
// (e.g., category, tag, tax) that may be not enabled/available in the new expense's policy.
abandonReviewDuplicateTransactions();
const comparisonResult = compareDuplicateTransactionFields(transaction, duplicates, transactionReport, transaction?.transactionID, policyCategories);
setReviewDuplicatesKey({
...comparisonResult.keep,
duplicates: duplicates.map((duplicate) => duplicate?.transactionID).filter(Boolean) as string[],
transactionID: transaction?.transactionID,
reportID: transaction?.reportID,
});
setReviewDuplicatesKey(
{
...comparisonResult.keep,
duplicates: duplicates.map((duplicate) => duplicate?.transactionID).filter(Boolean) as string[],
transactionID: transaction?.transactionID,
reportID: transaction?.reportID,
},
true,
);

if (comparisonResult.change.merchant) {
return ROUTES.TRANSACTION_DUPLICATE_REVIEW_MERCHANT_PAGE.getRoute(threadReportID, backTo);
Expand Down
12 changes: 8 additions & 4 deletions src/libs/actions/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
import {getPolicyTagsData} from './Policy/Tag';

let allTransactionDrafts: OnyxCollection<Transaction> = {};
Onyx.connect({

Check warning on line 60 in src/libs/actions/Transaction.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION_DRAFT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -66,7 +66,7 @@
});

let allReports: OnyxCollection<Report> = {};
Onyx.connect({

Check warning on line 69 in src/libs/actions/Transaction.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -78,7 +78,7 @@
});

const allTransactionViolation: OnyxCollection<TransactionViolation[]> = {};
Onyx.connect({

Check warning on line 81 in src/libs/actions/Transaction.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS,
callback: (transactionViolation, key) => {
if (!key || !transactionViolation) {
Expand All @@ -90,7 +90,7 @@
});

let allTransactionViolations: TransactionViolations = [];
Onyx.connect({

Check warning on line 93 in src/libs/actions/Transaction.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS,
callback: (val) => (allTransactionViolations = val ?? []),
});
Expand Down Expand Up @@ -629,10 +629,14 @@
});
}

function setReviewDuplicatesKey(values: Partial<ReviewDuplicates>) {
Onyx.merge(`${ONYXKEYS.REVIEW_DUPLICATES}`, {
...values,
});
function setReviewDuplicatesKey(values: Partial<ReviewDuplicates>, shouldUseSetMethod = false) {
if (shouldUseSetMethod) {
Onyx.set(`${ONYXKEYS.REVIEW_DUPLICATES}`, values);
} else {
Onyx.merge(`${ONYXKEYS.REVIEW_DUPLICATES}`, {
...values,
});
}
}

function abandonReviewDuplicateTransactions() {
Expand Down
Loading