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
2 changes: 1 addition & 1 deletion src/components/AddUnreportedExpenseFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function AddUnreportedExpenseFooter({selectedIds, report, reportToConfirm, repor
policy,
reportNextStep,
policyCategories,
allTransactionsCollection: allTransactions,
allTransactions,
});
}
});
Expand Down
44 changes: 21 additions & 23 deletions src/libs/actions/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,8 @@
import {getPolicyTagsData} from './Policy/Tag';
import {getCurrentUserAccountID} from './Report';

const allTransactions: OnyxCollection<Transaction> = {};
Onyx.connect({
key: ONYXKEYS.COLLECTION.TRANSACTION,
callback: (transaction, key) => {
if (!key || !transaction) {
return;
}
const transactionID = CollectionUtils.extractCollectionItemID(key);
allTransactions[transactionID] = transaction;
},
});

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

Check warning on line 56 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 @@ -74,7 +62,7 @@
});

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

Check warning on line 65 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 @@ -86,7 +74,7 @@
});

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

Check warning on line 77 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 @@ -98,7 +86,7 @@
});

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

Check warning on line 89 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 @@ -385,19 +373,29 @@
});
}

type DismissDuplicateTransactionViolationProps = {
transactionIDs: string[];
dismissedPersonalDetails: PersonalDetails;
expenseReport: OnyxEntry<Report>;
policy: OnyxEntry<Policy>;
isASAPSubmitBetaEnabled: boolean;
allTransactions: OnyxCollection<Transaction>;
};

/**
* Dismisses the duplicate transaction violation for the provided transactionIDs
* and updates the transaction to include the dismissed violation in the comment.
*/
function dismissDuplicateTransactionViolation(
transactionIDs: string[],
dismissedPersonalDetails: PersonalDetails,
expenseReport: OnyxEntry<Report>,
policy: OnyxEntry<Policy>,
isASAPSubmitBetaEnabled: boolean,
) {
function dismissDuplicateTransactionViolation({
transactionIDs,
dismissedPersonalDetails,
expenseReport,
policy,
isASAPSubmitBetaEnabled,
allTransactions,
}: DismissDuplicateTransactionViolationProps) {
const currentTransactionViolations = transactionIDs.map((id) => ({transactionID: id, violations: allTransactionViolation?.[id] ?? []}));
const currentTransactions = transactionIDs.map((id) => allTransactions?.[id]);
const currentTransactions = transactionIDs.map((id) => allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${id}`]);
const transactionsReportActions = currentTransactions.map((transaction) => getIOUActionForReportID(transaction?.reportID, transaction?.transactionID));
const optimisticDismissedViolationReportActions = transactionsReportActions.map(() => {
return buildOptimisticDismissedViolationReportAction({reason: 'manual', violationName: CONST.VIOLATIONS.DUPLICATED_TRANSACTION});
Expand Down Expand Up @@ -700,7 +698,7 @@
policy?: OnyxEntry<Policy>;
reportNextStep?: OnyxEntry<ReportNextStepDeprecated>;
policyCategories?: OnyxEntry<PolicyCategories>;
allTransactionsCollection: OnyxCollection<Transaction>;
allTransactions: OnyxCollection<Transaction>;
};

function changeTransactionsReport({
Expand All @@ -712,11 +710,11 @@
policy,
reportNextStep,
policyCategories,
allTransactionsCollection,
allTransactions,
}: ChangeTransactionsReportProps) {
const reportID = newReport?.reportID ?? CONST.REPORT.UNREPORTED_REPORT_ID;

const transactions = transactionIDs.map((id) => allTransactionsCollection?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${id}`]).filter((t): t is NonNullable<typeof t> => t !== undefined);
const transactions = transactionIDs.map((id) => allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${id}`]).filter((t): t is NonNullable<typeof t> => t !== undefined);
const transactionIDToReportActionAndThreadData: Record<string, TransactionThreadInfo> = {};
const updatedReportTotals: Record<string, number> = {};
const updatedReportNonReimbursableTotals: Record<string, number> = {};
Expand Down
2 changes: 1 addition & 1 deletion src/pages/NewReportWorkspaceSelectionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ function NewReportWorkspaceSelectionPage({route}: NewReportWorkspaceSelectionPag
policy: policies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`],
reportNextStep,
policyCategories: undefined,
allTransactionsCollection: allTransactions,
allTransactions,
});

// eslint-disable-next-line rulesdir/no-default-id-values
Expand Down
6 changes: 3 additions & 3 deletions src/pages/Search/SearchTransactionsChangeReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function SearchTransactionsChangeReport() {
policy: policyForMovingExpenses,
reportNextStep,
policyCategories: allPolicyCategories?.[`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyForMovingExpensesID}`],
allTransactionsCollection: allTransactions,
allTransactions,
});
clearSelectedTransactions();
});
Expand Down Expand Up @@ -128,7 +128,7 @@ function SearchTransactionsChangeReport() {
policy: allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${item.policyID}`],
reportNextStep,
policyCategories: allPolicyCategories?.[`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${item.policyID}`],
allTransactionsCollection: allTransactions,
allTransactions,
});
// eslint-disable-next-line @typescript-eslint/no-deprecated
InteractionManager.runAfterInteractions(() => {
Expand All @@ -147,7 +147,7 @@ function SearchTransactionsChangeReport() {
isASAPSubmitBetaEnabled,
accountID: session?.accountID ?? CONST.DEFAULT_NUMBER_ID,
email: session?.email ?? '',
allTransactionsCollection: allTransactions,
allTransactions,
});
clearSelectedTransactions();
Navigation.goBack();
Expand Down
20 changes: 11 additions & 9 deletions src/pages/TransactionDuplicate/Review.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,9 @@ function TransactionDuplicateReview() {
[transactionIDs],
);

const [transactions] = useOnyx(
ONYXKEYS.COLLECTION.TRANSACTION,
{
selector: transactionsSelector,
canBeMissing: true,
},
[transactionIDs],
);
const [allTransactions] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, {canBeMissing: true});
const transactions = useMemo(() => transactionsSelector(allTransactions ?? {}), [allTransactions, transactionsSelector]);

const originalTransactionIDsListRef = useRef<string[] | null>(null);
const [transactionIDsList = getEmptyArray<string>()] = useOnyx(ONYXKEYS.TRANSACTION_THREAD_NAVIGATION_TRANSACTION_IDS, {
canBeMissing: true,
Expand Down Expand Up @@ -97,7 +92,14 @@ function TransactionDuplicateReview() {
);

const keepAll = () => {
dismissDuplicateTransactionViolation(transactionIDs, currentPersonalDetails, expenseReport, policy, isASAPSubmitBetaEnabled);
dismissDuplicateTransactionViolation({
transactionIDs,
dismissedPersonalDetails: currentPersonalDetails,
expenseReport,
policy,
isASAPSubmitBetaEnabled,
allTransactions,
});
Navigation.goBack();
};

Expand Down
4 changes: 2 additions & 2 deletions src/pages/iou/request/step/IOURequestEditReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function IOURequestEditReport({route}: IOURequestEditReportProps) {
policy: allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${item.policyID}`],
reportNextStep,
policyCategories: allPolicyCategories?.[`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${item.policyID}`],
allTransactionsCollection: allTransactions,
allTransactions,
});
turnOffMobileSelectionMode();
clearSelectedTransactions(true);
Expand All @@ -91,7 +91,7 @@ function IOURequestEditReport({route}: IOURequestEditReportProps) {
isASAPSubmitBetaEnabled,
accountID: session?.accountID ?? CONST.DEFAULT_NUMBER_ID,
email: session?.email ?? '',
allTransactionsCollection: allTransactions,
allTransactions,
});
if (shouldTurnOffSelectionMode) {
turnOffMobileSelectionMode();
Expand Down
4 changes: 2 additions & 2 deletions src/pages/iou/request/step/IOURequestStepReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function IOURequestStepReport({route, transaction}: IOURequestStepReportProps) {
policy: allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${item.policyID}`],
reportNextStep: undefined,
policyCategories: allPolicyCategories?.[`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${item.policyID}`],
allTransactionsCollection: allTransactions,
allTransactions,
});
removeTransaction(transaction.transactionID);
}
Expand Down Expand Up @@ -175,7 +175,7 @@ function IOURequestStepReport({route, transaction}: IOURequestStepReportProps) {
isASAPSubmitBetaEnabled,
accountID: session?.accountID ?? CONST.DEFAULT_NUMBER_ID,
email: session?.email ?? '',
allTransactionsCollection: allTransactions,
allTransactions,
});
removeTransaction(transaction.transactionID);
});
Expand Down
2 changes: 1 addition & 1 deletion tests/actions/IOUTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8928,7 +8928,7 @@ describe('actions/IOU', () => {
accountID: CARLOS_ACCOUNT_ID,
email: CARLOS_EMAIL,
newReport: result.current.report,
allTransactionsCollection: allTransactions,
allTransactions,
});

let updatedTransaction: OnyxEntry<Transaction>;
Expand Down
Loading
Loading