Skip to content

Commit 7e60271

Browse files
committed
Refactor mergeDuplicates to pass currentUserData
1 parent 03023c1 commit 7e60271

3 files changed

Lines changed: 16 additions & 7 deletions

File tree

src/libs/actions/IOU/Duplicate.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,14 @@ function getIOUActionForTransactions(transactionIDList: Array<string | undefined
7474
);
7575
}
7676

77+
type MergeDuplicatesFuncParams = MergeDuplicatesParams & {currentUserLogin: string; currentUserAccountID: number};
78+
7779
/** Merge several transactions into one by updating the fields of the one we want to keep and deleting the rest */
78-
function mergeDuplicates({transactionThreadReportID: optimisticTransactionThreadReportID, ...params}: MergeDuplicatesParams) {
80+
function mergeDuplicates({transactionThreadReportID: optimisticTransactionThreadReportID, currentUserLogin, currentUserAccountID, ...params}: MergeDuplicatesFuncParams) {
7981
const allParams: MergeDuplicatesParams = {...params};
8082
const allTransactions = getAllTransactions();
8183
const allTransactionViolations = getAllTransactionViolations();
8284
const allReports = getAllReports();
83-
const currentUserEmail = getCurrentUserEmail();
84-
const currentUserAccountID = getUserAccountID();
85-
8685
const originalSelectedTransaction = allTransactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${params.transactionID}`];
8786

8887
const optimisticTransactionData: OnyxUpdate<typeof ONYXKEYS.COLLECTION.TRANSACTION> = {
@@ -281,7 +280,7 @@ function mergeDuplicates({transactionThreadReportID: optimisticTransactionThread
281280

282281
if (optimisticTransactionThreadReportID) {
283282
const iouAction = getIOUActionForReportID(params.reportID, params.transactionID);
284-
const optimisticCreatedAction = buildOptimisticCreatedReportAction(currentUserEmail);
283+
const optimisticCreatedAction = buildOptimisticCreatedReportAction(currentUserLogin);
285284
const optimisticTransactionThreadReport = buildTransactionThread(iouAction, expenseReport, undefined, optimisticTransactionThreadReportID);
286285

287286
allParams.transactionThreadReportID = optimisticTransactionThreadReportID;

src/pages/TransactionDuplicate/Confirmation.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ function Confirmation() {
8080
if (!reportAction?.childReportID) {
8181
transactionsMergeParams.transactionThreadReportID = transactionThreadReportID;
8282
}
83-
mergeDuplicates(transactionsMergeParams);
83+
mergeDuplicates({...transactionsMergeParams, currentUserAccountID: currentUserPersonalDetails.accountID, currentUserLogin: currentUserPersonalDetails?.login ?? ''});
8484
if (isSuperWideRHPDisplayed) {
8585
Navigation.dismissToSuperWideRHP();
8686
return;
8787
}
8888
Navigation.dismissModal();
89-
}, [reportAction?.childReportID, transactionsMergeParams, isSuperWideRHPDisplayed]);
89+
}, [reportAction?.childReportID, transactionsMergeParams, currentUserPersonalDetails.accountID, currentUserPersonalDetails?.login, isSuperWideRHPDisplayed]);
9090

9191
const handleResolveDuplicates = useCallback(() => {
9292
resolveDuplicates(transactionsMergeParams);

tests/actions/IOUTest/DuplicateTest.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ describe('actions/Duplicate', () => {
200200
tag: 'UpdatedProject',
201201
receiptID: 123,
202202
reportID,
203+
currentUserLogin: RORY_EMAIL,
204+
currentUserAccountID: RORY_ACCOUNT_ID,
203205
};
204206

205207
// When: Call mergeDuplicates
@@ -281,6 +283,8 @@ describe('actions/Duplicate', () => {
281283
tag: 'UpdatedProject',
282284
receiptID: 123,
283285
reportID,
286+
currentUserLogin: RORY_EMAIL,
287+
currentUserAccountID: RORY_ACCOUNT_ID,
284288
};
285289

286290
// When: Call mergeDuplicates with empty duplicate list
@@ -332,6 +336,8 @@ describe('actions/Duplicate', () => {
332336
tag: 'UpdatedProject',
333337
receiptID: 123,
334338
reportID,
339+
currentUserLogin: RORY_EMAIL,
340+
currentUserAccountID: RORY_ACCOUNT_ID,
335341
};
336342

337343
// When: Call mergeDuplicates without expense report
@@ -526,6 +532,8 @@ describe('actions/Duplicate', () => {
526532
tag: 'UpdatedProject',
527533
receiptID: 123,
528534
reportID,
535+
currentUserLogin: RORY_EMAIL,
536+
currentUserAccountID: RORY_ACCOUNT_ID,
529537
};
530538

531539
// When: Call mergeDuplicates
@@ -626,6 +634,8 @@ describe('actions/Duplicate', () => {
626634
tag: 'UpdatedProject',
627635
receiptID: 123,
628636
reportID,
637+
currentUserLogin: RORY_EMAIL,
638+
currentUserAccountID: RORY_ACCOUNT_ID,
629639
};
630640

631641
// When: Call mergeDuplicates with transactionThreadReportID

0 commit comments

Comments
 (0)