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
6 changes: 3 additions & 3 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@
};

let conciergeReportIDOnyxConnect: OnyxEntry<string>;
Onyx.connect({

Check warning on line 1058 in src/libs/ReportUtils.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.CONCIERGE_REPORT_ID,
callback: (value) => {
conciergeReportIDOnyxConnect = value;
Expand All @@ -1063,7 +1063,7 @@
});

const defaultAvatarBuildingIconTestID = 'SvgDefaultAvatarBuilding Icon';
Onyx.connect({

Check warning on line 1066 in src/libs/ReportUtils.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.SESSION,
callback: (value) => {
// When signed out, val is undefined
Expand All @@ -1081,7 +1081,7 @@
let allPersonalDetails: OnyxEntry<PersonalDetailsList>;
let allPersonalDetailLogins: string[];
let currentUserPersonalDetails: OnyxEntry<PersonalDetails>;
Onyx.connect({

Check warning on line 1084 in src/libs/ReportUtils.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.PERSONAL_DETAILS_LIST,
callback: (value) => {
if (deprecatedCurrentUserAccountID) {
Expand All @@ -1093,7 +1093,7 @@
});

let allReportsDraft: OnyxCollection<Report>;
Onyx.connect({

Check warning on line 1096 in src/libs/ReportUtils.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_DRAFT,
waitForCollectionCallback: true,
callback: (value) => (allReportsDraft = value),
Expand All @@ -1101,7 +1101,7 @@

let allPolicies: OnyxCollection<Policy>;
let policiesArray: Policy[] = [];
Onyx.connect({

Check warning on line 1104 in src/libs/ReportUtils.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.POLICY,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -1111,7 +1111,7 @@
});

let allPolicyDrafts: OnyxCollection<Policy>;
Onyx.connect({

Check warning on line 1114 in src/libs/ReportUtils.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.POLICY_DRAFTS,
waitForCollectionCallback: true,
callback: (value) => (allPolicyDrafts = value),
Expand All @@ -1119,7 +1119,7 @@

let allReports: OnyxCollection<Report>;
let reportsByPolicyID: ReportByPolicyMap;
Onyx.connect({

Check warning on line 1122 in src/libs/ReportUtils.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 Down Expand Up @@ -1155,14 +1155,14 @@
});

let betaConfiguration: OnyxEntry<BetaConfiguration> = {};
Onyx.connect({

Check warning on line 1158 in src/libs/ReportUtils.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.BETA_CONFIGURATION,
callback: (value) => (betaConfiguration = value ?? {}),
});

let deprecatedAllTransactions: OnyxCollection<Transaction> = {};
let deprecatedReportsTransactions: Record<string, Transaction[]> = {};
Onyx.connect({

Check warning on line 1165 in src/libs/ReportUtils.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,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -1188,7 +1188,7 @@
});

let allReportActions: OnyxCollection<ReportActions>;
Onyx.connect({

Check warning on line 1191 in src/libs/ReportUtils.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_ACTIONS,
waitForCollectionCallback: true,
callback: (actions) => {
Expand Down Expand Up @@ -11409,9 +11409,9 @@
);
}

function createDraftWorkspaceAndNavigateToConfirmationScreen(introSelected: OnyxEntry<IntroSelected>, transactionID: string, actionName: IOUAction): void {
function createDraftWorkspaceAndNavigateToConfirmationScreen(introSelected: OnyxEntry<IntroSelected>, transactionID: string, actionName: IOUAction, workspaceName: string): void {
const isCategorizing = actionName === CONST.IOU.ACTION.CATEGORIZE;
const {expenseChatReportID, policyID, policyName} = createDraftWorkspace(introSelected, deprecatedCurrentUserEmail);
const {expenseChatReportID, policyID, policyName} = createDraftWorkspace(introSelected, workspaceName, deprecatedCurrentUserEmail);
setMoneyRequestParticipants(transactionID, [
{
selected: true,
Expand Down Expand Up @@ -11602,7 +11602,7 @@
return;
}

return createDraftWorkspaceAndNavigateToConfirmationScreen(introSelected, transactionID, actionName);
return createDraftWorkspaceAndNavigateToConfirmationScreen(introSelected, transactionID, actionName, '');

@bernhardoj bernhardoj Apr 6, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pass an empty string here because this code is unreachable. createDraftWorkspaceAndNavigateToConfirmationScreen accepts actionName, and all usages pass either SUBMIT, CATEGORIZE, or SHARE, will return early above.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense

}

/**
Expand Down
9 changes: 1 addition & 8 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2971,23 +2971,16 @@ function createWorkspace(options: CreateWorkspaceDataOptions): CreateWorkspacePa

/**
* Creates a draft workspace for various money request flows
*
* @param [policyOwnerEmail] the email of the account to make the owner of the policy
* @param [makeMeAdmin] leave the calling account as an admin on the policy
* @param [policyName] custom policy name we will use for created workspace
* @param [policyID] custom policy id we will use for created workspace
*/
function createDraftWorkspace(
introSelected: OnyxEntry<IntroSelected>,
Comment thread
cristipaval marked this conversation as resolved.
Resolved
workspaceName: string,
policyOwnerEmail = '',
makeMeAdmin = false,
policyName = '',
policyID = generatePolicyID(),
currency = '',
file?: File,
): CreateWorkspaceParams {
const workspaceName = policyName || generateDefaultWorkspaceName(policyOwnerEmail);

const {customUnits, customUnitID, customUnitRateID, outputCurrency} = buildOptimisticDistanceRateCustomUnits(currency);

const {expenseChatData, adminsChatReportID, adminsCreatedReportActionID, expenseChatReportID, expenseCreatedReportActionID} = ReportUtils.buildOptimisticWorkspaceChats(
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Travel/WorkspaceConfirmationForTravelPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function WorkspaceConfirmationForTravelPage({route}: WorkspaceConfirmationForTra
};

const onSubmit = (params: WorkspaceConfirmationSubmitFunctionParams) => {
createDraftWorkspace(introSelected, '', false, params.name, params.policyID, params.currency, params.avatarFile as File);
createDraftWorkspace(introSelected, params.name, '', false, params.policyID, params.currency, params.avatarFile as File);
Comment thread
bernhardoj marked this conversation as resolved.
Resolved
createWorkspace({
policyName: params.name,
policyID: params.policyID,
Expand Down
11 changes: 7 additions & 4 deletions src/pages/iou/request/step/IOURequestStepAccountant.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {activeAdminPoliciesSelector} from '@selectors/Policy';
import {activeAdminPoliciesSelector, lastWorkspaceNumberSelector} from '@selectors/Policy';
import React, {useCallback} from 'react';
import type {OnyxCollection} from 'react-native-onyx';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import {setMoneyRequestAccountant} from '@libs/actions/IOU';
import {newGenerateDefaultWorkspaceName} from '@libs/actions/Policy/Policy';
import Navigation from '@libs/Navigation/Navigation';
import {createDraftWorkspaceAndNavigateToConfirmationScreen} from '@libs/ReportUtils';
import MoneyRequestAccountantSelector from '@pages/iou/request/MoneyRequestAccountantSelector';
Expand All @@ -25,14 +26,16 @@ function IOURequestStepAccountant({
},
}: IOURequestStepAccountantProps) {
const {translate} = useLocalize();
const {login} = useCurrentUserPersonalDetails();
const {login, email = ''} = useCurrentUserPersonalDetails();
const selector = useCallback(
(policies: OnyxCollection<Policy>) => {
return activeAdminPoliciesSelector(policies, login ?? '');
},
[login],
);
const lastWorkspaceNumberWithEmailSelector = useCallback((policies: OnyxCollection<Policy>) => lastWorkspaceNumberSelector(policies, email), [email]);
const [adminPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {selector});
const [lastWorkspaceNumber] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {selector: lastWorkspaceNumberWithEmailSelector});
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED);

const setAccountant = useCallback(
Expand All @@ -46,12 +49,12 @@ function IOURequestStepAccountant({
// Sharing with an accountant involves inviting them to the workspace and that requires admin access.
const hasActiveAdminWorkspaces = (adminPolicies?.length ?? 0) > 0;
if (!hasActiveAdminWorkspaces) {
createDraftWorkspaceAndNavigateToConfirmationScreen(introSelected, transactionID, action);
createDraftWorkspaceAndNavigateToConfirmationScreen(introSelected, transactionID, action, newGenerateDefaultWorkspaceName(email, lastWorkspaceNumber, translate));
return;
}

Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_PARTICIPANTS.getRoute(iouType, transactionID, reportID, Navigation.getActiveRoute(), action));
}, [adminPolicies?.length, iouType, transactionID, reportID, action, introSelected]);
}, [adminPolicies?.length, iouType, transactionID, reportID, action, introSelected, email, lastWorkspaceNumber, translate]);

const navigateBack = useCallback(() => {
Navigation.goBack(backTo);
Expand Down
8 changes: 6 additions & 2 deletions src/pages/iou/request/step/IOURequestStepParticipants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ import {
setMoneyRequestTag,
} from '@userActions/IOU';
import {setSplitShares} from '@userActions/IOU/Split';
import {createDraftWorkspace} from '@userActions/Policy/Policy';
import {createDraftWorkspace, newGenerateDefaultWorkspaceName} from '@userActions/Policy/Policy';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import {lastWorkspaceNumberSelector} from '@src/selectors/Policy';
import type {Policy} from '@src/types/onyx';
import type {Participant} from '@src/types/onyx/IOU';
import getEmptyArray from '@src/types/utils/getEmptyArray';
Expand Down Expand Up @@ -328,7 +329,9 @@ function IOURequestStepParticipants({
}
}
if ((isCategorizing || isShareAction) && numberOfParticipants.current === 0) {
const {expenseChatReportID, policyID, policyName} = createDraftWorkspace(introSelected);
const email = currentUserPersonalDetails.email ?? '';
const lastWorkspaceNumber = lastWorkspaceNumberSelector(allPolicies, email);
const {expenseChatReportID, policyID, policyName} = createDraftWorkspace(introSelected, newGenerateDefaultWorkspaceName(email, lastWorkspaceNumber, translate));
for (const transaction of draftTransactions) {
setMoneyRequestParticipants(transaction.transactionID, [
{
Expand Down Expand Up @@ -394,6 +397,7 @@ function IOURequestStepParticipants({
introSelected,
backTo,
selfDMReportID,
translate,
],
);

Expand Down
4 changes: 2 additions & 2 deletions tests/actions/PolicyTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1821,7 +1821,7 @@ describe('actions/Policy', () => {
await waitForBatchedUpdates();

const policyID = Policy.generatePolicyID();
const params = Policy.createDraftWorkspace({choice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM}, ESH_EMAIL, true, WORKSPACE_NAME, policyID, CONST.CURRENCY.USD);
const params = Policy.createDraftWorkspace({choice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM}, WORKSPACE_NAME, ESH_EMAIL, true, policyID, CONST.CURRENCY.USD);
await waitForBatchedUpdates();

const draft = await getOnyxValue(`${ONYXKEYS.COLLECTION.POLICY_DRAFTS}${policyID}`);
Expand Down Expand Up @@ -1849,7 +1849,7 @@ describe('actions/Policy', () => {
await waitForBatchedUpdates();

const policyID = Policy.generatePolicyID();
Policy.createDraftWorkspace({choice: CONST.ONBOARDING_CHOICES.TRACK_WORKSPACE}, ESH_EMAIL, false, WORKSPACE_NAME, policyID, CONST.CURRENCY.EUR);
Policy.createDraftWorkspace({choice: CONST.ONBOARDING_CHOICES.TRACK_WORKSPACE}, WORKSPACE_NAME, ESH_EMAIL, false, policyID, CONST.CURRENCY.EUR);
await waitForBatchedUpdates();

const draft = await getOnyxValue(`${ONYXKEYS.COLLECTION.POLICY_DRAFTS}${policyID}`);
Expand Down
Loading