Skip to content

Commit 63e39e6

Browse files
authored
Merge pull request Expensify#88772 from parasharrajat/onyx/session-7
Remove currentUser global data from iou/bulkEdit
2 parents 2300dfa + 7d67453 commit 63e39e6

3 files changed

Lines changed: 55 additions & 2 deletions

File tree

src/libs/actions/IOU/BulkEdit.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
3030
import type * as OnyxTypes from '@src/types/onyx';
3131
import type {SearchResultDataType} from '@src/types/onyx/SearchResults';
3232
import type {TransactionChanges} from '@src/types/onyx/Transaction';
33-
import {getAllTransactionViolations, getCurrentUserEmail, getUpdatedMoneyRequestReportData, getUserAccountID} from '.';
33+
import {getAllTransactionViolations, getUpdatedMoneyRequestReportData} from '.';
3434

3535
function removeUnchangedBulkEditFields(
3636
transactionChanges: TransactionChanges,
@@ -80,6 +80,8 @@ type UpdateMultipleMoneyRequestsParams = {
8080
allPolicies?: OnyxCollection<OnyxTypes.Policy>;
8181
introSelected: OnyxEntry<OnyxTypes.IntroSelected>;
8282
betas: OnyxEntry<OnyxTypes.Beta[]>;
83+
currentUserLogin: string;
84+
currentUserAccountID: number;
8385
};
8486

8587
function updateMultipleMoneyRequests({
@@ -95,6 +97,8 @@ function updateMultipleMoneyRequests({
9597
allPolicies,
9698
introSelected,
9799
betas,
100+
currentUserAccountID,
101+
currentUserLogin,
98102
}: UpdateMultipleMoneyRequestsParams) {
99103
// Track running totals per report so multiple edits in the same report compound correctly.
100104
const optimisticReportsByID: Record<string, OnyxTypes.Report> = {};
@@ -133,7 +137,7 @@ function updateMultipleMoneyRequests({
133137
// bulk-edit comments are visible immediately while still offline.
134138
let didCreateThreadInThisIteration = false;
135139
if (!transactionThreadReportID && iouReport?.reportID) {
136-
const optimisticTransactionThread = createTransactionThreadReport(introSelected, getCurrentUserEmail(), getUserAccountID(), betas, iouReport, reportAction, transaction);
140+
const optimisticTransactionThread = createTransactionThreadReport(introSelected, currentUserLogin, currentUserAccountID, betas, iouReport, reportAction, transaction);
137141
if (optimisticTransactionThread?.reportID) {
138142
transactionThreadReportID = optimisticTransactionThread.reportID;
139143
transactionThread = optimisticTransactionThread;

src/pages/Search/SearchEditMultiple/SearchEditMultiplePage.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import ScreenWrapper from '@components/ScreenWrapper';
88
import ScrollView from '@components/ScrollView';
99
import {useSearchActionsContext, useSearchStateContext} from '@components/Search/SearchContext';
1010
import Text from '@components/Text';
11+
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
1112
import useLocalize from '@hooks/useLocalize';
1213
import useOnyx from '@hooks/useOnyx';
1314
import useThemeStyles from '@hooks/useThemeStyles';
@@ -40,6 +41,7 @@ function SearchEditMultiplePage() {
4041
const styles = useThemeStyles();
4142
const {currentSearchHash, currentSearchResults} = useSearchStateContext();
4243
const {clearSelectedTransactions} = useSearchActionsContext();
44+
const {login: currentUserLogin, accountID: currentUserAccountID} = useCurrentUserPersonalDetails();
4345
const [policies] = useOnyx(ONYXKEYS.COLLECTION.POLICY);
4446
const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID);
4547
const [draftTransaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${CONST.IOU.OPTIMISTIC_BULK_EDIT_TRANSACTION_ID}`);
@@ -171,6 +173,8 @@ function SearchEditMultiplePage() {
171173
allPolicies: policies,
172174
introSelected,
173175
betas,
176+
currentUserAccountID,
177+
currentUserLogin: currentUserLogin ?? '',
174178
});
175179
// Bulk edit can start from report (ID-based selection) or search (map-based selection),
176180
// so clear both stores to keep deselection behavior consistent.

tests/actions/IOUTest/BulkEditTest.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import createRandomTransaction from '../../utils/collections/transaction';
1414
import getOnyxValue from '../../utils/getOnyxValue';
1515
import waitForBatchedUpdates from '../../utils/waitForBatchedUpdates';
1616

17+
const RORY_EMAIL = 'rory@expensifail.com';
18+
const RORY_ACCOUNT_ID = 3;
19+
1720
describe('actions/IOU/BulkEdit', () => {
1821
describe('updateMultipleMoneyRequests', () => {
1922
it('applies expense report sign to amount updates', () => {
@@ -69,6 +72,8 @@ describe('actions/IOU/BulkEdit', () => {
6972
hash: undefined,
7073
introSelected: undefined,
7174
betas: undefined,
75+
currentUserLogin: RORY_EMAIL,
76+
currentUserAccountID: RORY_ACCOUNT_ID,
7277
});
7378

7479
const params = writeSpy.mock.calls.at(0)?.[1] as {updates: string};
@@ -140,6 +145,8 @@ describe('actions/IOU/BulkEdit', () => {
140145
hash: undefined,
141146
introSelected: undefined,
142147
betas: undefined,
148+
currentUserLogin: RORY_EMAIL,
149+
currentUserAccountID: RORY_ACCOUNT_ID,
143150
});
144151

145152
expect(writeSpy).not.toHaveBeenCalled();
@@ -200,6 +207,8 @@ describe('actions/IOU/BulkEdit', () => {
200207
hash: undefined,
201208
introSelected: undefined,
202209
betas: undefined,
210+
currentUserLogin: RORY_EMAIL,
211+
currentUserAccountID: RORY_ACCOUNT_ID,
203212
});
204213

205214
const getOptimisticTotal = (callIndex: number) => {
@@ -269,6 +278,8 @@ describe('actions/IOU/BulkEdit', () => {
269278
hash: undefined,
270279
introSelected: undefined,
271280
betas: undefined,
281+
currentUserLogin: RORY_EMAIL,
282+
currentUserAccountID: RORY_ACCOUNT_ID,
272283
});
273284

274285
const params = writeSpy.mock.calls.at(0)?.[1] as {updates: string};
@@ -342,6 +353,8 @@ describe('actions/IOU/BulkEdit', () => {
342353
hash: undefined,
343354
introSelected: undefined,
344355
betas: undefined,
356+
currentUserLogin: RORY_EMAIL,
357+
currentUserAccountID: RORY_ACCOUNT_ID,
345358
});
346359

347360
const params = writeSpy.mock.calls.at(0)?.[1] as {updates: string};
@@ -406,6 +419,8 @@ describe('actions/IOU/BulkEdit', () => {
406419
hash: undefined,
407420
introSelected: undefined,
408421
betas: undefined,
422+
currentUserLogin: RORY_EMAIL,
423+
currentUserAccountID: RORY_ACCOUNT_ID,
409424
});
410425

411426
const params = writeSpy.mock.calls.at(0)?.[1] as {updates: string};
@@ -468,6 +483,8 @@ describe('actions/IOU/BulkEdit', () => {
468483
hash: undefined,
469484
introSelected: undefined,
470485
betas: undefined,
486+
currentUserLogin: RORY_EMAIL,
487+
currentUserAccountID: RORY_ACCOUNT_ID,
471488
});
472489

473490
expect(writeSpy).toHaveBeenCalled();
@@ -538,6 +555,8 @@ describe('actions/IOU/BulkEdit', () => {
538555
hash: undefined,
539556
introSelected: undefined,
540557
betas: undefined,
558+
currentUserLogin: RORY_EMAIL,
559+
currentUserAccountID: RORY_ACCOUNT_ID,
541560
});
542561
await waitForBatchedUpdates();
543562

@@ -592,6 +611,8 @@ describe('actions/IOU/BulkEdit', () => {
592611
hash: undefined,
593612
introSelected: undefined,
594613
betas: undefined,
614+
currentUserLogin: RORY_EMAIL,
615+
currentUserAccountID: RORY_ACCOUNT_ID,
595616
});
596617
await waitForBatchedUpdates();
597618

@@ -649,6 +670,8 @@ describe('actions/IOU/BulkEdit', () => {
649670
hash: undefined,
650671
introSelected: undefined,
651672
betas: undefined,
673+
currentUserLogin: RORY_EMAIL,
674+
currentUserAccountID: RORY_ACCOUNT_ID,
652675
});
653676
await waitForBatchedUpdates();
654677

@@ -713,6 +736,8 @@ describe('actions/IOU/BulkEdit', () => {
713736
hash: undefined,
714737
introSelected: undefined,
715738
betas: undefined,
739+
currentUserLogin: RORY_EMAIL,
740+
currentUserAccountID: RORY_ACCOUNT_ID,
716741
});
717742
await waitForBatchedUpdates();
718743

@@ -778,6 +803,8 @@ describe('actions/IOU/BulkEdit', () => {
778803
},
779804
introSelected: undefined,
780805
betas: undefined,
806+
currentUserLogin: RORY_EMAIL,
807+
currentUserAccountID: RORY_ACCOUNT_ID,
781808
});
782809
await waitForBatchedUpdates();
783810

@@ -854,6 +881,8 @@ describe('actions/IOU/BulkEdit', () => {
854881
},
855882
introSelected: undefined,
856883
betas: undefined,
884+
currentUserLogin: RORY_EMAIL,
885+
currentUserAccountID: RORY_ACCOUNT_ID,
857886
});
858887
await waitForBatchedUpdates();
859888

@@ -918,6 +947,8 @@ describe('actions/IOU/BulkEdit', () => {
918947
hash: undefined,
919948
introSelected: undefined,
920949
betas: undefined,
950+
currentUserLogin: RORY_EMAIL,
951+
currentUserAccountID: RORY_ACCOUNT_ID,
921952
});
922953
await waitForBatchedUpdates();
923954

@@ -995,6 +1026,8 @@ describe('actions/IOU/BulkEdit', () => {
9951026
hash: undefined,
9961027
introSelected: undefined,
9971028
betas: undefined,
1029+
currentUserLogin: RORY_EMAIL,
1030+
currentUserAccountID: RORY_ACCOUNT_ID,
9981031
});
9991032
await waitForBatchedUpdates();
10001033

@@ -1052,6 +1085,8 @@ describe('actions/IOU/BulkEdit', () => {
10521085
hash: undefined,
10531086
introSelected: undefined,
10541087
betas: undefined,
1088+
currentUserLogin: RORY_EMAIL,
1089+
currentUserAccountID: RORY_ACCOUNT_ID,
10551090
});
10561091

10571092
// category/billable changes must be silently dropped for IOUs —
@@ -1134,6 +1169,8 @@ describe('actions/IOU/BulkEdit', () => {
11341169
allPolicies,
11351170
introSelected: undefined,
11361171
betas: undefined,
1172+
currentUserLogin: RORY_EMAIL,
1173+
currentUserAccountID: RORY_ACCOUNT_ID,
11371174
});
11381175

11391176
// Then: the optimistic transaction update should use the transaction's own policy for tax resolution.
@@ -1224,6 +1261,8 @@ describe('actions/IOU/BulkEdit', () => {
12241261
allPolicies,
12251262
introSelected: undefined,
12261263
betas: undefined,
1264+
currentUserLogin: RORY_EMAIL,
1265+
currentUserAccountID: RORY_ACCOUNT_ID,
12271266
});
12281267

12291268
// Then: buildOptimisticModifiedExpenseReportAction should receive the transaction's own policy,
@@ -1292,6 +1331,8 @@ describe('actions/IOU/BulkEdit', () => {
12921331
hash: undefined,
12931332
introSelected: undefined,
12941333
betas: undefined,
1334+
currentUserLogin: RORY_EMAIL,
1335+
currentUserAccountID: RORY_ACCOUNT_ID,
12951336
});
12961337

12971338
const params = writeSpy.mock.calls.at(0)?.[1] as {updates: string};
@@ -1359,6 +1400,8 @@ describe('actions/IOU/BulkEdit', () => {
13591400
hash: undefined,
13601401
introSelected: undefined,
13611402
betas: undefined,
1403+
currentUserLogin: RORY_EMAIL,
1404+
currentUserAccountID: RORY_ACCOUNT_ID,
13621405
});
13631406

13641407
const params = writeSpy.mock.calls.at(0)?.[1] as {updates: string};
@@ -1422,6 +1465,8 @@ describe('actions/IOU/BulkEdit', () => {
14221465
hash: undefined,
14231466
introSelected: undefined,
14241467
betas: undefined,
1468+
currentUserLogin: RORY_EMAIL,
1469+
currentUserAccountID: RORY_ACCOUNT_ID,
14251470
});
14261471

14271472
const params = writeSpy.mock.calls.at(0)?.[1] as {updates: string};

0 commit comments

Comments
 (0)