Skip to content

Commit f39ebea

Browse files
DylanDylannclaude
andcommitted
refactor: pass explicit currentUserAccountID/Email to createDraftWorkspaceAndNavigateToConfirmationScreen
Thread currentUserAccountID and currentUserEmail from components through createDraftTransactionAndNavigateToParticipantSelector and createDraftWorkspaceAndNavigateToConfirmationScreen instead of using deprecated Onyx session variables in ReportUtils.ts. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 1744268 commit f39ebea

7 files changed

Lines changed: 67 additions & 10 deletions

File tree

src/libs/ReportUtils.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11326,14 +11326,16 @@ function canLeaveChat(report: OnyxEntry<Report>, policy: OnyxEntry<Policy>, isRe
1132611326
);
1132711327
}
1132811328

11329-
function createDraftWorkspaceAndNavigateToConfirmationScreen(introSelected: OnyxEntry<IntroSelected>, transactionID: string, actionName: IOUAction, workspaceName: string): void {
11329+
function createDraftWorkspaceAndNavigateToConfirmationScreen(
11330+
introSelected: OnyxEntry<IntroSelected>,
11331+
transactionID: string,
11332+
actionName: IOUAction,
11333+
workspaceName: string,
11334+
currentUserAccountID: number,
11335+
currentUserEmail: string,
11336+
): void {
1133011337
const isCategorizing = actionName === CONST.IOU.ACTION.CATEGORIZE;
11331-
const {expenseChatReportID, policyID, policyName} = createDraftWorkspace(
11332-
introSelected,
11333-
workspaceName,
11334-
deprecatedCurrentUserAccountID ?? CONST.DEFAULT_NUMBER_ID,
11335-
deprecatedCurrentUserEmail ?? '',
11336-
);
11338+
const {expenseChatReportID, policyID, policyName} = createDraftWorkspace(introSelected, workspaceName, currentUserAccountID, currentUserEmail);
1133711339
setMoneyRequestParticipants(transactionID, [
1133811340
{
1133911341
selected: true,
@@ -11365,6 +11367,8 @@ type CreateDraftTransactionParams = {
1136511367
isRestrictedToPreferredPolicy?: boolean;
1136611368
preferredPolicyID?: string;
1136711369
transaction: OnyxEntry<Transaction>;
11370+
currentUserAccountID: number;
11371+
currentUserEmail: string;
1136811372
};
1136911373

1137011374
function createDraftTransactionAndNavigateToParticipantSelector({
@@ -11380,6 +11384,8 @@ function createDraftTransactionAndNavigateToParticipantSelector({
1138011384
isRestrictedToPreferredPolicy = false,
1138111385
preferredPolicyID,
1138211386
transaction,
11387+
currentUserAccountID,
11388+
currentUserEmail,
1138311389
}: CreateDraftTransactionParams): void {
1138411390
const transactionID = transaction?.transactionID;
1138511391
if (!transactionID || !reportID) {
@@ -11524,7 +11530,7 @@ function createDraftTransactionAndNavigateToParticipantSelector({
1152411530
return;
1152511531
}
1152611532

11527-
return createDraftWorkspaceAndNavigateToConfirmationScreen(introSelected, transactionID, actionName, '');
11533+
return createDraftWorkspaceAndNavigateToConfirmationScreen(introSelected, transactionID, actionName, '', currentUserAccountID, currentUserEmail);
1152811534
}
1152911535

1153011536
/**

src/pages/ReportDetailsPage.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,8 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail
469469
isRestrictedToPreferredPolicy,
470470
preferredPolicyID,
471471
transaction: iouTransaction,
472+
currentUserAccountID: currentUserPersonalDetails.accountID,
473+
currentUserEmail: currentUserPersonalDetails.email ?? '',
472474
});
473475
},
474476
});
@@ -491,6 +493,8 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail
491493
amountOwed,
492494
ownerBillingGracePeriodEnd,
493495
transaction: iouTransaction,
496+
currentUserAccountID: currentUserPersonalDetails.accountID,
497+
currentUserEmail: currentUserPersonalDetails.email ?? '',
494498
});
495499
},
496500
});
@@ -512,6 +516,8 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail
512516
amountOwed,
513517
ownerBillingGracePeriodEnd,
514518
transaction: iouTransaction,
519+
currentUserAccountID: currentUserPersonalDetails.accountID,
520+
currentUserEmail: currentUserPersonalDetails.email ?? '',
515521
});
516522
},
517523
});

src/pages/inbox/report/PureReportActionItem.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,8 @@ function PureReportActionItem({
976976
isRestrictedToPreferredPolicy,
977977
preferredPolicyID,
978978
transaction: trackExpenseTransaction,
979+
currentUserAccountID: personalDetail.accountID,
980+
currentUserEmail: personalDetail.email ?? '',
979981
});
980982
},
981983
},
@@ -998,6 +1000,8 @@ function PureReportActionItem({
9981000
amountOwed,
9991001
ownerBillingGracePeriodEnd,
10001002
transaction: trackExpenseTransaction,
1003+
currentUserAccountID: personalDetail.accountID,
1004+
currentUserEmail: personalDetail.email ?? '',
10011005
});
10021006
},
10031007
},
@@ -1016,6 +1020,8 @@ function PureReportActionItem({
10161020
amountOwed,
10171021
ownerBillingGracePeriodEnd,
10181022
transaction: trackExpenseTransaction,
1023+
currentUserAccountID: personalDetail.accountID,
1024+
currentUserEmail: personalDetail.email ?? '',
10191025
});
10201026
},
10211027
},

src/pages/iou/request/step/IOURequestStepAccountant.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function IOURequestStepAccountant({
2626
},
2727
}: IOURequestStepAccountantProps) {
2828
const {translate} = useLocalize();
29-
const {login, email = ''} = useCurrentUserPersonalDetails();
29+
const {accountID, login, email = ''} = useCurrentUserPersonalDetails();
3030
const selector = useCallback(
3131
(policies: OnyxCollection<Policy>) => {
3232
return activeAdminPoliciesSelector(policies, login ?? '');
@@ -49,7 +49,14 @@ function IOURequestStepAccountant({
4949
// Sharing with an accountant involves inviting them to the workspace and that requires admin access.
5050
const hasActiveAdminWorkspaces = (adminPolicies?.length ?? 0) > 0;
5151
if (!hasActiveAdminWorkspaces) {
52-
createDraftWorkspaceAndNavigateToConfirmationScreen(introSelected, transactionID, action, newGenerateDefaultWorkspaceName(email, lastWorkspaceNumber, translate));
52+
createDraftWorkspaceAndNavigateToConfirmationScreen(
53+
introSelected,
54+
transactionID,
55+
action,
56+
newGenerateDefaultWorkspaceName(email, lastWorkspaceNumber, translate),
57+
accountID,
58+
email,
59+
);
5360
return;
5461
}
5562

tests/actions/IOUTest.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,8 @@ describe('actions/IOU', () => {
540540
userBillingGracePeriodEnds: undefined,
541541
amountOwed: 0,
542542
transaction: transactionToCategorize,
543+
currentUserAccountID: RORY_ACCOUNT_ID,
544+
currentUserEmail: RORY_EMAIL,
543545
});
544546
await waitForBatchedUpdates();
545547

@@ -588,6 +590,8 @@ describe('actions/IOU', () => {
588590
userBillingGracePeriodEnds: undefined,
589591
amountOwed: 0,
590592
transaction: originalTransaction,
593+
currentUserAccountID: RORY_ACCOUNT_ID,
594+
currentUserEmail: RORY_EMAIL,
591595
});
592596
await waitForBatchedUpdates();
593597

@@ -625,6 +629,8 @@ describe('actions/IOU', () => {
625629
userBillingGracePeriodEnds: undefined,
626630
amountOwed: 0,
627631
transaction: undefined,
632+
currentUserAccountID: RORY_ACCOUNT_ID,
633+
currentUserEmail: RORY_EMAIL,
628634
});
629635
await waitForBatchedUpdates();
630636

@@ -657,6 +663,8 @@ describe('actions/IOU', () => {
657663
transaction,
658664
userBillingGracePeriodEnds: undefined,
659665
amountOwed: 0,
666+
currentUserAccountID: RORY_ACCOUNT_ID,
667+
currentUserEmail: RORY_EMAIL,
660668
});
661669
await waitForBatchedUpdates();
662670

tests/actions/IOUTest/TrackExpenseTest.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ describe('actions/IOU/TrackExpense', () => {
268268
userBillingGracePeriodEnds: undefined,
269269
amountOwed: 0,
270270
transaction,
271+
currentUserAccountID: RORY_ACCOUNT_ID,
272+
currentUserEmail: RORY_EMAIL,
271273
});
272274
await waitForBatchedUpdates();
273275

@@ -841,6 +843,8 @@ describe('actions/IOU/TrackExpense', () => {
841843
userBillingGracePeriodEnds: undefined,
842844
amountOwed: 0,
843845
transaction: createdTransaction,
846+
currentUserAccountID: RORY_ACCOUNT_ID,
847+
currentUserEmail: RORY_EMAIL,
844848
});
845849
await waitForBatchedUpdates();
846850

tests/unit/ReportUtilsTest.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13966,6 +13966,8 @@ describe('ReportUtils', () => {
1396613966
userBillingGracePeriodEnds: undefined,
1396713967
amountOwed: 0,
1396813968
transaction: undefined,
13969+
currentUserAccountID,
13970+
currentUserEmail,
1396913971
});
1397013972

1397113973
expect(Navigation.navigate).not.toHaveBeenCalled();
@@ -14005,6 +14007,8 @@ describe('ReportUtils', () => {
1400514007
amountOwed: 1,
1400614008
ownerBillingGracePeriodEnd: pastGracePeriod,
1400714009
transaction,
14010+
currentUserAccountID,
14011+
currentUserEmail,
1400814012
});
1400914013

1401014014
// Then it should navigate to the restricted action page
@@ -14040,6 +14044,8 @@ describe('ReportUtils', () => {
1404014044
userBillingGracePeriodEnds,
1404114045
amountOwed: 0,
1404214046
transaction,
14047+
currentUserAccountID,
14048+
currentUserEmail,
1404314049
});
1404414050

1404514051
// Then it should navigate to the restricted action page
@@ -14078,6 +14084,8 @@ describe('ReportUtils', () => {
1407814084
userBillingGracePeriodEnds: undefined,
1407914085
amountOwed: 0,
1408014086
transaction,
14087+
currentUserAccountID,
14088+
currentUserEmail,
1408114089
});
1408214090

1408314091
// Then it should navigate to the category step
@@ -14118,6 +14126,8 @@ describe('ReportUtils', () => {
1411814126
userBillingGracePeriodEnds: undefined,
1411914127
amountOwed: 0,
1412014128
transaction,
14129+
currentUserAccountID,
14130+
currentUserEmail,
1412114131
});
1412214132

1412314133
// Then it should automatically pick the available policy and navigate to the category step
@@ -14145,6 +14155,8 @@ describe('ReportUtils', () => {
1414514155
userBillingGracePeriodEnds: undefined,
1414614156
amountOwed: 0,
1414714157
transaction,
14158+
currentUserAccountID,
14159+
currentUserEmail,
1414814160
});
1414914161

1415014162
// Then it should navigate to the upgrade page because no policies were found to categorize with
@@ -14193,6 +14205,8 @@ describe('ReportUtils', () => {
1419314205
userBillingGracePeriodEnds: undefined,
1419414206
amountOwed: 0,
1419514207
transaction,
14208+
currentUserAccountID,
14209+
currentUserEmail,
1419614210
});
1419714211

1419814212
// Then it should navigate to the upgrade page because it's ambiguous which policy to use
@@ -14237,6 +14251,8 @@ describe('ReportUtils', () => {
1423714251
userBillingGracePeriodEnds: undefined,
1423814252
amountOwed: 0,
1423914253
transaction,
14254+
currentUserAccountID,
14255+
currentUserEmail,
1424014256
});
1424114257

1424214258
// Then it should log a warning and not navigate
@@ -14281,6 +14297,8 @@ describe('ReportUtils', () => {
1428114297
amountOwed: 0,
1428214298
ownerBillingGracePeriodEnd: pastGracePeriod,
1428314299
transaction,
14300+
currentUserAccountID,
14301+
currentUserEmail,
1428414302
});
1428514303

1428614304
// Then it should NOT navigate to restricted action page, but to category step
@@ -14317,6 +14335,8 @@ describe('ReportUtils', () => {
1431714335
amountOwed: 50,
1431814336
ownerBillingGracePeriodEnd: pastGracePeriod,
1431914337
transaction,
14338+
currentUserAccountID,
14339+
currentUserEmail,
1432014340
});
1432114341

1432214342
// Then it should navigate to restricted action page

0 commit comments

Comments
 (0)