Skip to content

Commit 9d6e685

Browse files
authored
Merge pull request Expensify#88291 from parasharrajat/onyx/session-5
Update bulkDuplicateExpense function to currentUser data
2 parents bf1b257 + a41a539 commit 9d6e685

4 files changed

Lines changed: 21 additions & 9 deletions

File tree

src/hooks/useBulkDuplicateAction.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type UseBulkDuplicateActionParams = {
2626
* so these subscriptions don't exist for users who aren't actively duplicating.
2727
*/
2828
function useBulkDuplicateAction({selectedTransactionsKeys, allTransactions, allReports, searchData, onAfterDuplicate}: UseBulkDuplicateActionParams) {
29-
const {accountID} = useCurrentUserPersonalDetails();
29+
const {accountID, login: currentUserLogin} = useCurrentUserPersonalDetails();
3030
const {clearSelectedTransactions} = useSearchActionsContext();
3131
const defaultExpensePolicy = useDefaultExpensePolicy();
3232
const {isBetaEnabled} = usePermissions();
@@ -78,6 +78,8 @@ function useBulkDuplicateAction({selectedTransactionsKeys, allTransactions, allR
7878
draftTransactionIDs,
7979
betas,
8080
recentWaypoints,
81+
currentUserAccountID: accountID,
82+
currentUserLogin: currentUserLogin ?? '',
8183
});
8284

8385
if (onAfterDuplicate) {

src/hooks/useBulkDuplicateReportAction.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ function useBulkDuplicateReportAction({selectedReports, allReports, searchData}:
5454
defaultExpensePolicy,
5555
activePolicyExpenseChat,
5656
ownerPersonalDetails: currentUserPersonalDetails,
57-
currentUserLogin: currentUserPersonalDetails.login ?? '',
5857
isASAPSubmitBetaEnabled,
5958
betas,
6059
personalDetails,
@@ -65,6 +64,8 @@ function useBulkDuplicateReportAction({selectedReports, allReports, searchData}:
6564
transactionViolations: allTransactionViolations,
6665
translate,
6766
recentWaypoints,
67+
currentUserLogin: currentUserPersonalDetails.login ?? '',
68+
currentUserAccountID: currentUserPersonalDetails?.accountID,
6869
});
6970

7071
clearSelectedTransactions(undefined, true);

src/libs/actions/IOU/Duplicate.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import type {Attendee, Participant} from '@src/types/onyx/IOU';
4646
import type {CurrentUserPersonalDetails} from '@src/types/onyx/PersonalDetails';
4747
import type {WaypointCollection} from '@src/types/onyx/Transaction';
4848
import type {RequestMoneyInformation} from '.';
49-
import {getAllReportActionsFromIOU, getAllReports, getAllTransactions, getAllTransactionViolations, getCurrentUserEmail, getMoneyRequestParticipantsFromReport, getUserAccountID} from '.';
49+
import {getAllReportActionsFromIOU, getAllReports, getAllTransactions, getAllTransactionViolations, getMoneyRequestParticipantsFromReport} from '.';
5050
import {getCleanUpTransactionThreadReportOnyxData} from './DeleteMoneyRequest';
5151
import type {PerDiemExpenseInformation} from './PerDiem';
5252
import {submitPerDiemExpense} from './PerDiem';
@@ -966,6 +966,8 @@ type BulkDuplicateExpensesParams = {
966966
draftTransactionIDs: string[];
967967
betas: OnyxEntry<OnyxTypes.Beta[]>;
968968
recentWaypoints: OnyxEntry<OnyxTypes.RecentWaypoint[]>;
969+
currentUserLogin: string;
970+
currentUserAccountID: number;
969971
};
970972

971973
function bulkDuplicateExpenses({
@@ -987,6 +989,8 @@ function bulkDuplicateExpenses({
987989
draftTransactionIDs,
988990
betas,
989991
recentWaypoints,
992+
currentUserAccountID,
993+
currentUserLogin,
990994
}: BulkDuplicateExpensesParams) {
991995
const transactionsToDuplicate = transactionIDs.map((id) => allTransactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${id}`]).filter((t): t is OnyxTypes.Transaction => !!t);
992996

@@ -1082,8 +1086,8 @@ function bulkDuplicateExpenses({
10821086
shouldDeferAutoSubmit,
10831087
existingIOUReport: optimisticIOUReport,
10841088
optimisticReportPreviewActionID: currentReportPreviewActionID,
1085-
currentUserAccountID: getUserAccountID(),
1086-
currentUserLogin: getCurrentUserEmail(),
1089+
currentUserAccountID,
1090+
currentUserLogin,
10871091
});
10881092

10891093
if (result?.iouReport) {
@@ -1108,7 +1112,6 @@ type BulkDuplicateReportsParams = {
11081112
defaultExpensePolicy: OnyxEntry<OnyxTypes.Policy>;
11091113
activePolicyExpenseChat: OnyxEntry<OnyxTypes.Report>;
11101114
ownerPersonalDetails: CurrentUserPersonalDetails;
1111-
currentUserLogin: string;
11121115
isASAPSubmitBetaEnabled: boolean;
11131116
betas: OnyxEntry<OnyxTypes.Beta[]>;
11141117
personalDetails: OnyxEntry<OnyxTypes.PersonalDetailsList>;
@@ -1119,6 +1122,8 @@ type BulkDuplicateReportsParams = {
11191122
transactionViolations: OnyxCollection<OnyxTypes.TransactionViolation[]>;
11201123
translate: LocalizedTranslate;
11211124
recentWaypoints: OnyxEntry<OnyxTypes.RecentWaypoint[]>;
1125+
currentUserLogin: string;
1126+
currentUserAccountID: number;
11221127
};
11231128

11241129
function bulkDuplicateReports({
@@ -1131,7 +1136,6 @@ function bulkDuplicateReports({
11311136
defaultExpensePolicy,
11321137
activePolicyExpenseChat,
11331138
ownerPersonalDetails,
1134-
currentUserLogin,
11351139
isASAPSubmitBetaEnabled,
11361140
betas,
11371141
personalDetails,
@@ -1142,6 +1146,8 @@ function bulkDuplicateReports({
11421146
transactionViolations,
11431147
translate,
11441148
recentWaypoints,
1149+
currentUserLogin,
1150+
currentUserAccountID,
11451151
}: BulkDuplicateReportsParams) {
11461152
const allTransactionsMap = getAllTransactions();
11471153
const transactionsByReportID = new Map<string, OnyxTypes.Transaction[]>();
@@ -1215,8 +1221,8 @@ function bulkDuplicateReports({
12151221
translate,
12161222
recentWaypoints,
12171223
shouldPlaySound: false,
1218-
currentUserAccountID: getUserAccountID(),
1219-
currentUserLogin: getCurrentUserEmail(),
1224+
currentUserAccountID,
1225+
currentUserLogin,
12201226
});
12211227
}
12221228

tests/actions/IOUTest/DuplicateTest.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2486,6 +2486,8 @@ describe('actions/Duplicate', () => {
24862486
draftTransactionIDs: [],
24872487
betas: [CONST.BETAS.ALL],
24882488
recentWaypoints: [],
2489+
currentUserAccountID: RORY_ACCOUNT_ID,
2490+
currentUserLogin: RORY_EMAIL,
24892491
});
24902492

24912493
await waitForBatchedUpdates();
@@ -2588,6 +2590,7 @@ describe('actions/Duplicate', () => {
25882590
activePolicyExpenseChat,
25892591
ownerPersonalDetails: {accountID: RORY_ACCOUNT_ID, login: RORY_EMAIL, displayName: 'Rory'},
25902592
currentUserLogin: RORY_EMAIL,
2593+
currentUserAccountID: RORY_ACCOUNT_ID,
25912594
isASAPSubmitBetaEnabled: false,
25922595
betas: [CONST.BETAS.ALL],
25932596
personalDetails: {[RORY_ACCOUNT_ID]: {accountID: RORY_ACCOUNT_ID, login: RORY_EMAIL, displayName: 'Rory'}},

0 commit comments

Comments
 (0)