Skip to content

Create a real workspace when submitting a tracked expense to an employer with no workspace - #105138

Draft
MelvinBot wants to merge 1 commit into
mainfrom
claude-createRealWorkspaceOnSubmitToEmployer
Draft

MelvinBot wants to merge 1 commit into
mainfrom
claude-createRealWorkspaceOnSubmitToEmployer

Conversation

@MelvinBot

Copy link
Copy Markdown
Contributor

Explanation of Change

When a user with no workspace chose Submit to my employer, the App only created a local draft workspace (POLICY_DRAFTS). The server created the real workspace later, inside AddTrackedExpenseToPolicy, when the expense was submitted. Workspace pages opened from the confirmation flow only read real policies, so tapping + on the category picker opened the add-category screen, and its AccessOrNotFoundWrapper found no policy and showed Not here.

As agreed on the issue, this PR creates a real Submit workspace with createWorkspace as soon as the user taps Submit to my employer:

  • StartExpenseFlows.ts: the no-workspace branch now calls createWorkspace with the same options useAutoCreateSubmitWorkspace uses (type: SUBMIT, engagementChoice: EMPLOYER, makeMeAdmin, no onboarding tasks, no guide welcome message). It points the draft transaction at the new expense chat and opens confirmation with the same backTo behavior as before. A module-level guard keeps a fast double tap from creating two workspaces.
  • The three callers (ChatActionableButtons, ReportDetailsMenuTrackExpenseItems, MoneyRequestHeaderSecondaryActions) pass the extra values createWorkspace needs (conciergeChat, isSelfTourViewed, hasActiveAdminPolicies, delegateAccountID, hasOwnedPaidPolicy).
  • Submit now takes the same route as "user already has one workspace" (requestMoney, then AddTrackedExpenseToPolicy), so the draft-only submit path is removed:
    • isSubmittingExpenseToDraftWorkspace (in useExpenseSubmission, useTrackExpenseSubmission and resolveSubmissionPath)
    • the SUBMIT case in trackExpense and submitTrackedExpenseToPolicy. moveTrackedExpenseToPolicy is folded back into categorizeTrackedExpense, its only remaining caller.
    • the policyType option in TrackExpense.ts, isDistanceRequest in TrackedExpenseParams, and policyName/type in AddTrackedExpenseToPolicyParams
    • the type option and Submit branches in createDraftWorkspace
  • Categorize, Share with accountant and Travel still use draft workspaces, so POLICY_DRAFTS and the shared draft code are unchanged, apart from comments that no longer mention Submit.

AI tests run locally:

  • npm run typecheck, npm run lint-changed, npm run spell-changed and react-compiler-compliance-check check on the changed components all passed. Formatting was applied with npm run fmt.
  • Jest passed: 16 related suites, 580 tests, including CreateDraftTransactionTest, resolveSubmissionPathTest, TrackExpenseTest, RequestMoneyTest, PolicyTest, ChatActionableButtonsTest, MoneyRequestHeaderSecondaryActionsTest, useExpenseSubmission.test and SubmitTrackedExpenseGoBackTests.
  • New tests cover two cases: a real Submit workspace is created in POLICY (not POLICY_DRAFTS), and a double tap creates only one workspace.
  • Not run: the full Jest suite, npm run lint on the whole repo, and the Storybook smoke test.

Fixed Issues

$ #101766
PROPOSAL: #101766 (comment)

Tests

// TODO: The human co-author must fill out the tests you ran before marking this PR as "ready for review"
// Please describe what tests you performed that validates your changed worked.

  • Verify that no errors appear in the JS console

Offline tests

QA Steps

// TODO: The human co-author must fill out the QA tests you ran before marking this PR as "ready for review".
// Please describe what QA needs to do to validate your changes and what areas do they need to test for regressions.

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I verified any copy / text that was added to the app is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If the PR adds or modifies the UI:
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    • I verified all new/changed elements have meaningful accessible names and roles.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

…n employer with no workspace

Submit to my employer used to create a local draft workspace, which made every
workspace page reached from the confirmation flow (e.g. adding a category) show
Not here, because those pages only read real policies. Create the workspace with
createWorkspace up front instead, and remove the draft-only submit path that
created the workspace inside AddTrackedExpenseToPolicy.

Co-authored-by: Shubham Agrawal <shubham1206agra@users.noreply.github.com>
@melvin-bot melvin-bot Bot added Melvin-Test-Android Melvin-Test-Web Triggers Melvin to run the testing steps of the PR on web labels Oct 27, 2026
@MelvinBot
MelvinBot requested a review from a team October 27, 2026 14:39
@MelvinBot

Copy link
Copy Markdown
Contributor Author

I created this PR from an upstream branch because I don't have push access to your fork.

To take ownership of this branch and push updates, run:

git remote add upstream https://github.com/Expensify/App.git
git fetch upstream claude-createRealWorkspaceOnSubmitToEmployer
git checkout -b claude-createRealWorkspaceOnSubmitToEmployer upstream/claude-createRealWorkspaceOnSubmitToEmployer
git push -u origin claude-createRealWorkspaceOnSubmitToEmployer

Then you can close this PR and open a new one from your fork.

@MelvinBot

MelvinBot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 Web test steps verification results: ✅ pass

Choosing "Submit to my employer" with no workspace creates exactly one real Submit workspace, and the Category "+" icon opens the Add category page instead of a Not here page. The PR's Tests section is still a TODO, so I used the reproduction steps from the linked issue.
Workspaces list showing exactly one workspace

Step Status
V1: After onboarding with "Something else", the account has no workspaceWorkspaces tab showed "No workspaces yet" with a "New workspace" button right after onboarding.
Workspaces list showing 'No workspaces yet'
✅
V2: A tracked expense to yourself is created and "Submit to my employer" is availableCreated a manual $10.00 expense to "Melvin Tester (you)". TrackExpense returned 200. The expense showed "Submit to a friend" and "Submit to my employer" buttons.
✅
V3: Selecting "Submit to my employer" opens the confirmation page with no errorsThe "Confirm details" page opened with destination "Melvin Tester's Workspace, Submits to Melvin Tester" and Amount, Merchant, Description, Category and Date fields. No error banners.
Confirm details page after choosing Submit to my employer
✅
V4: Clicking "+" on the Category picker does not show a Not here pageThe category list showed an "Add category" (+) button. Clicking it opened the "Add category" page with a Name field and Save button, not a Not here page.
Add category page opened via the + icon
✅
V5: Submitting succeeds, lands in a workspace expense chat, and only one workspace is createdAfter filling the required Merchant field, "Create expense" put the expense in "Expense Report 2026-10-27" in "Melvin Tester's Workspace", which has a Submit action. The Workspaces list showed exactly one workspace (Submit type). The network log showed exactly one CreateWorkspace call (status 200).
Workspace expense report chat with Submit button
Workspaces list showing exactly one workspace
✅

view run · view recording

@codecov

codecov Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.

Files with missing lines Coverage Δ
.../components/MoneyRequestHeaderSecondaryActions.tsx 59.36% <100.00%> (+0.28%) ⬆️
src/hooks/usePolicyForTransaction.ts 100.00% <ø> (ø)
src/libs/actions/IOU/TrackExpense.ts 86.66% <100.00%> (+1.87%) ⬆️
src/libs/actions/Policy/Policy.ts 72.61% <100.00%> (-0.29%) ⬇️
...DetailsPage/ReportDetailsMenuTrackExpenseItems.tsx 91.08% <100.00%> (+0.66%) ⬆️
src/pages/inbox/ReportFetchHandler.tsx 93.68% <ø> (ø)
...ox/report/actionContents/ChatActionableButtons.tsx 89.20% <100.00%> (+0.57%) ⬆️
.../request/step/IOURequestStepConfirmation/index.tsx 90.93% <ø> (ø)
...nfirmation/submission/useTrackExpenseSubmission.ts 94.50% <100.00%> (+1.72%) ⬆️
...irmation/submission/utils/resolveSubmissionPath.ts 100.00% <100.00%> (ø)
... and 2 more
... and 7 files with indirect coverage changes

@MelvinBot

Copy link
Copy Markdown
Contributor Author

The failing check is unrelated to this PR, so I didn't push a code change.

Analysis: validate-perf-tests failed on [ReportActionsList] should re-render when an unrelated transaction is written with a render-count difference of 0.6 (allowed: 0). This PR doesn't touch ReportActionsList or the ReportActionsListRowWrites.perf-test.tsx suite. The branch perf tests themselves passed.

Evidence: The same suite fails today on unrelated PRs with similar fractional differences, and some of those branches pass on a rerun:

Branch Failing measurement Difference
georgia-search-refetch-on-custom-field-edit unrelated transaction is written 0.8
claude-categoryPickerNamelessCategoryCrash unrelated transaction is written 0.6
ishpaul/684546-talk-to-human-ticket unrelated report is written 0.7 (passed on rerun)
@mikolajpochec/wise-create-initial-intake-form report name changes 0.7

Next step: Rerun the whole "Reassure Performance Tests" workflow (not only the failed job, so measurements regenerate). Check independent approval is a review-gate check and needs no code change.


view run

@MelvinBot

MelvinBot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 Android test steps verification results: ❌ fail

On a no-workspace account, the self-DM expense was created and "Submit to my employer" was offered, but selecting it from the expense's header "More" menu froze the app, so I couldn't reach the category picker or submit the expense. The PR's Tests section is still a TODO, so I used the reproduction steps from the linked issue.
Action sheet with 'Submit to my employer' stuck on screen, unresponsive to further taps

Step Status
V1: After onboarding with "Something else", the account has no workspaceWorkspaces tab showed "No workspaces yet".
Workspaces list showing no workspaces yet
✅
V2: A tracked expense to yourself is created and "Submit to my employer" is availableCreated a $10.00 manual expense to "Melvin Tester (you)". The expense's "More" menu listed "Submit to my employer" with Send to someone, Split, Merge, Duplicate expense and Move to report.
Tracked expense report chat showing $10.00 expense from Melvin Tester (you)
✅
V3: Selecting "Submit to my employer" opens the confirmation page with no errorsTapping "Submit to my employer" in the header "More" menu changed nothing. The action sheet never closed, and no confirmation page, error or toast appeared. For about 2 minutes, the app ignored every input: repeat taps, other menu items, coordinate taps, swipe-to-dismiss and the hardware back key. The app did not crash: MainActivity stayed in the foreground, and Metro logged no errors. I couldn't relaunch the app to retry through the inline chat button, which the passing Web run used.
Action sheet with 'Submit to my employer' stuck on screen, unresponsive to further taps
❌
V4: Tapping "+" on the Category picker does not show a Not here pageNot reached because the app froze at V3.
❌
V5: Submitting succeeds, lands in a workspace expense chat, and only one workspace is createdNot reached because the app froze at V3.
❌

view run · view recording

@Krishna2323

Copy link
Copy Markdown
Contributor

@MelvinBot resolve conflicts

@MelvinBot

MelvinBot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 Web test steps verification results: ❌ fail

Resolved the conflicts locally, but did not commit or push because validation is blocked by Bun's postinstall script was not run and Jest module-loading errors. Storybook smoke tests passed; browser verification was blocked by a blank page before sign-in.
Blank dev NewDot page blocking verification

Step Status
Session recoveryThe page remained blank; sign-in could not be reached.
Blank dev NewDot page blocking verification
❌
Track an expense without a workspaceNot verified: session setup blocked.
❌
Submit to my employer creates one real workspaceNot verified: session setup blocked.
❌
Category + opens Add categoryNot verified: session setup blocked.
❌
Expense submission succeedsNot verified: session setup blocked.
❌

view run · no recording available

@Krishna2323

Copy link
Copy Markdown
Contributor

@MelvinBot resolve conflicts

@MelvinBot

MelvinBot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 Web test steps verification results: ❌ fail

Conflicts were resolved locally, but not committed or pushed: validation remains blocked by Bun initialization and Jest module-loading errors; Storybook smoke tests passed. Browser verification was blocked by a blank page.

Blank app page blocking verification

Step Status
Track an expense without a workspaceBlocked by the blank app page.
⚠️
Submit to my employer creates one real workspaceCould not reach confirmation.
⚠️
Category + opens Add categoryCould not access the category picker.
⚠️
Submission succeeds without duplicate workspacesCould not submit or verify workspace count.
⚠️
No JavaScript console errorsCould not verify.
⚠️

view run · no recording available

@Krishna2323

Copy link
Copy Markdown
Contributor

@MelvinBot resolve conflicts

@MelvinBot

MelvinBot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 Web test steps verification results: ❌ fail

Conflicts were resolved locally, but not committed or pushed: lint/typecheck remain blocked by Bun initialization, and Jest hits ES-module loading errors. Storybook smoke tests and 18 submission-routing tests passed; web verification was blocked by an empty page.
Empty app page blocking verification

Step Status
Create tracked expense, create one Submit workspace, open Add category, and submit without duplicate workspacesBlocked before setup: browser snapshots returned zero nodes. No product regression verdict is possible.
Empty app page blocking verification
❌
No JavaScript console errorsNot verified; console inspection was unavailable through supported web commands.
❌

view run · no recording available

@Krishna2323

Copy link
Copy Markdown
Contributor

@MelvinBot resolve conflicts

@MelvinBot

Copy link
Copy Markdown
Contributor Author

Conflicts were resolved locally, but not committed or pushed because validation was blocked:

  • Lint: missing eslint-config-expensify/oxlint/utils.
  • Typecheck and targeted Jest tests each timed out after 10 minutes.
  • Formatter execution was denied.

The PR remains unchanged. The development environment needs repair before the resolution can be validated and pushed.


view run

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Melvin-Test-Android Melvin-Test-Web Triggers Melvin to run the testing steps of the PR on web

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants