Repository navigation
[No QA] [Payment due @huult] Stop routing group workspace members to the reports upgrade screen - #101465
Conversation
Guard the upgrade path on policy hydration, let a valid active workspace rescue the user before the upgrade early return, and pass the current user login so the employeeList role fallback is reachable. Co-authored-by: MitchExpensify <MitchExpensify@users.noreply.github.com>
Codecov Report✅ Changes either increased or maintained existing code coverage, great job!
|
|
🤖 Web test steps verification results: The reports empty state and the FAB create-report flow both show the correct non-paywall UI for a Collect-plan group workspace member. The hard-reload/cold-start race (VERIFY 3) could not be exercised, because a page reload during a driven web session risks dropping client auth into a magic-code wall this run cannot clear. This PR still has no documented testing steps — the
Same result shape as the Android run: the reachable flows are clean on both platforms, and the cold-start hydration race is unverified on both — blocked by app relaunch on Android and by page reload on Web. Since that race is the case the hydration guard exists to fix, it's worth covering with a unit test on the hook rather than through UI automation. Also note the |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 57288aedff
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| // The active workspace can still be a valid destination even when the qualification pass came back | ||
| // empty, so check it before giving up. This has to run ahead of the upgrade path below, otherwise a | ||
| // perfectly valid active workspace can never rescue the user. | ||
| if (isPolicyValidForMovingExpenses(activePolicy, login, isPerDiemRequest, isTimeRequest)) { |
There was a problem hiding this comment.
Validate roles from employeeList before upgrading
When a group policy stores the current member's role only in employeeList—the exact partially loaded shape handled by the EmptySearchView change—both the qualification pass and this new active-policy fallback call isPolicyValidForMovingExpenses, whose isPolicyMemberByRole check accepts only policy.role. The active workspace therefore still cannot rescue these members, and callers such as SearchActionsBarCreateButton route them to the reports upgrade screen even though its separate policy selector recognizes their workspace. Use the login-aware getPolicyRole fallback when validating policies.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Good catch — fixed in 0268312.
isPolicyMemberByRole now resolves the role through getPolicyRole(policy, login) instead of reading policy.role directly, so a workspace that only carries the member's role in employeeList is accepted here the same way getGroupPoliciesWhereReportCanBeCreated already accepts it via shouldShowPolicy. That removes the disagreement you described between this hook and SearchActionsBarCreateButton's own selector.
See src/hooks/usePolicyForMovingExpenses.ts:29.
Added a regression test for it — tests/unit/hooks/usePolicyForMovingExpenses.test.tsx — and confirmed it fails against the old policy.role-only check and passes with the fix.
| return {policyForMovingExpensesID: activePolicyID, policyForMovingExpenses: activePolicy, shouldSelectPolicy: false, shouldNavigateToUpgradePath: false}; | ||
| } | ||
|
|
||
| return {policyForMovingExpensesID: undefined, policyForMovingExpenses: undefined, shouldSelectPolicy: false, shouldNavigateToUpgradePath: arePoliciesLoaded}; |
There was a problem hiding this comment.
Block actions while the policy collection is loading
During the initial Onyx read, this returns the same false value used for a confirmed eligible policy, but the hook's consumers do not receive arePoliciesLoaded and therefore cannot distinguish the two states. For example, if a user clicks Create report in SearchTransactionsChangeReport during this window, its fall-through calls createNewReport and changeTransactionsReport with an undefined policy instead of waiting; this can optimistically create an unscoped report and move the selected transactions before policy hydration completes. Expose a loading state or otherwise make acting callers no-op until the collection is loaded.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
You're right, and SearchTransactionsChangeReport is the one call site where the fall-through actually mutates. Fixed in 0268312.
The hook now returns arePoliciesLoaded, and createReport no-ops while the collection is loading rather than calling createNewReport/changeTransactionsReport with an undefined policy — the same guard useCreateReport uses.
- src/hooks/usePolicyForMovingExpenses.ts:104 — the new field, with a doc comment on when callers must gate on it
- src/pages/Search/SearchTransactionsChangeReport.tsx:205 — the no-op
I re-read the other shouldNavigateToUpgradePath consumers and left them alone deliberately: SearchActionsBarCreateButton, QuickCreationActionsBar, MoneyRequestView, and DynamicSplitExpenseEditPage all fall through to a workspace selector or report picker when no policy resolves, which is a state they already handle and which creates nothing. Only this one writes.
|
Tag me when it's ready |
|
@huult is this good to go? |
|
@MelvinBot what's the latest here? Can you make sure all comments are addressed and the PR is ready for review again? |
…ydrationGuard Co-authored-by: MitchExpensify <MitchExpensify@users.noreply.github.com>
…tating call site - isPolicyMemberByRole now resolves the role via getPolicyRole, so a workspace that only carries the member's role in employeeList is accepted here the same way getGroupPoliciesWhereReportCanBeCreated already accepts it. - Expose arePoliciesLoaded and no-op SearchTransactionsChangeReport's createReport while the policy collection loads, so it can never create a report with an undefined policy during the hydration window. - Add unit tests for the hydration guard, the employeeList role fallback, and the managed card transaction path. Co-authored-by: MitchExpensify <MitchExpensify@users.noreply.github.com>
|
@thesahindia Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
|
Both review comments are addressed and CI is green. One thing still blocks "ready for review", and it needs a person — see the bottom. What I just pushed (
CI: everything passes — typecheck, ESLint, Oxfmt, React Compiler, spellcheck, all 8 Jest shards, Bun tests, perf, builds. The only reds are Still blocking: the One caveat: I could not drive the app in a browser this run, so nothing here is newly verified in a live session. The claims above come from the code, the merged |
@MitchExpensify Is this PR ready for review? |
@thesahindia Do you have time to review this PR? If not, please let me know so I can ask another C+. |
…ydrationGuard Co-authored-by: huult <huult@users.noreply.github.com>
On it. @huult, could you add the test steps? |
|
@MelvinBot, add these steps to the tests section
|
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppScreen.Recording.2026-10-14.at.7.30.35.AM.movAndroid: mWeb ChromeScreen.Recording.2026-10-14.at.6.47.45.AM.moviOS: HybridAppScreen.Recording.2026-10-14.at.7.21.16.AM.moviOS: mWeb SafariScreen.Recording.2026-10-14.at.7.06.28.AM.movMacOS: Chrome / SafariScreen.Recording.2026-10-14.at.6.30.36.AM.mov |
|
Added all 9 steps to the Tests section of the PR description, in place of the TODO placeholder. I kept the "Verify that no errors appear in the JS console" checkbox below them and left the rest of the description unchanged. |
|
@MelvinBot Please add [No QA] to the PR title. |
|
🚧 francoisl has triggered a test Expensify/App build. You can view the workflow run here. |
This comment has been minimized.
This comment has been minimized.
|
🚧 francoisl has triggered a test Expensify/App build. You can view the workflow run here. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
🚀 Deployed to staging by https://github.com/francoisl in version: 9.5.10-0 🚀
|
|
No help site update is needed. This bug fix stops sending group workspace members to the Collect plan upgrade screen, so the app now does what members already expect, and no article describes that upgrade screen. |
|
🚀 Deployed to staging by https://github.com/francoisl in version: 9.5.12-0 🚀
|
|
No help site update is needed. This bug fix stops sending group workspace members to the Collect plan upgrade screen, so the app now does what members already expect, and no article describes that upgrade screen. My earlier review still applies, because the PR's changes have not changed since then. |
|
🚀 Deployed to production by https://github.com/cristipaval in version: 9.5.12-1 🚀
Bundle Size Analysis (Sentry): |
|
🤖 Payment issue created: #104214 |








Explanation of Change
Members of a group workspace were sometimes shown the "Reports are available on the Collect plan, starting at $5 per member per month" upgrade screen, even though their workspace already supports reports. This is not a plan gate —
reportshas norequiredPlanand is not inSUBMIT_FEATURE_IDS. The screen is the App's "you have no eligible group workspace" prompt, andUpgradeIntrois rendered without apolicyID, so it always shows the hardcoded Collect wording no matter what plan the user is actually on.usePolicyForMovingExpensesgates that prompt, and it treated "I could not resolve a policy" as "this user has no workspace" in three ways that are wrong for a real member:No hydration guard. The policy collection read at the top of the hook discarded its load status, so the moment the collection read back empty — including during Onyx cold start — the hook returned
shouldNavigateToUpgradePath: true.useCreateReportalready guards the identical situation about 40 lines away, with a comment describing this exact bug. This change reads the load status off the sameuseOnyxcall (so the value and the status always come from the same source, including when the search-snapshot redirect is in play) and no longer claims "no workspace" before we know.The active-workspace fallback was unreachable. The
activePolicyfallback sat below the unconditional early return, so a fully loaded, valid active workspace could never rescue the user. It now runs before the upgrade path. It is validated withisPolicyValidForMovingExpensesrather than the looser check the old fallback used, so an active workspace is only used when it is genuinely a valid destination — this cannot select something the old code would have rejected.EmptySearchViewdropped the login.getGroupPoliciesWhereReportCanBeCreatedwas called withoutcurrentUserLogin.getPolicyRolereturns early when there is no login, which makes itsemployeeList[login].rolefallback dead code, so any policy that carries the member's role only inemployeeListwas filtered out and the user looked workspace-less. This was the only one of seven call sites that omitted the login; the FAB, Search router, workspace selector, and navigation guard all pass it.One more ordering fix came out of this: the
isUnreportedManagedCardTransactionbranch never depends on a locally resolved policy — it deliberately returns an emptypolicyIDso the backend auto-selects — but it sat below the early return, so that flow also hit the upgrade screen whenever no policy resolved. It is now answered first.Update — review feedback applied. Two follow-ups from the automated review are now in:
The role check is login-aware.
isPolicyMemberByRoleresolved the role frompolicy.roleonly, which the backend populates just for the user's default/active workspace. It now goes throughgetPolicyRole(policy, login), so a workspace whose role arrives only inemployeeListis accepted here the same waygetGroupPoliciesWhereReportCanBeCreatedalready accepts it. Without this, the active-workspace fallback in item 2 could not rescue exactly the members it was added for.The hook exposes
arePoliciesLoaded. During the hydration windowshouldNavigateToUpgradePath: falsemeans "I don't know yet", not "this user has an eligible policy". Every consumer that only navigates already handles an unresolved policy — they fall through to a workspace selector or report picker, which creates nothing. ButSearchTransactionsChangeReportmutates: it would have created a report with an undefined policy and moved the selected transactions into it. That one call site now no-ops while the collection loads, matchinguseCreateReport.Also worth noting:
isLoadingOnyxValueonly reflects the local cache read, not network hydration. The guard closes the cold-start window; the active-workspace fallback in item 2 is what covers the longer "response has not landed yet" window.Fixed Issues
$ https://github.com/Expensify/Expensify/issues/681029
PROPOSAL: https://github.com/Expensify/Expensify/issues/681029#issuecomment-5702368350
AI Tests
All required local AI tests for these files now pass against
main:npm run typecheck— passed. The earlier CI failure was stale-branch drift intests/unit/ModifiedExpenseMessageTest.ts, a file this PR does not touch; mergingmainfixed it.npm run lint-changed— passednpm run react-compiler-compliance-check checkon the two changed source files — passednpm run spell-changed— passed, 0 issues across 5 filesnpm run fmt(oxfmt) — cleannpm test tests/unit/hooks/usePolicyForMovingExpenses.test.tsx tests/ui/components/SearchActionsBarCreateButtonTest.tsx— 15 passedNew unit tests in
tests/unit/hooks/usePolicyForMovingExpenses.test.tsxcover the cold-start hydration guard, theemployeeListrole fallback, and the managed-card-transaction path. TheemployeeListcase was checked against the pre-fixpolicy.role-only code and fails there, so it is a real regression test rather than a passing tautology.Not verified in a browser: the cold-start race itself. Driving a real page reload or app relaunch was outside what the automated runs on this PR could do, so that window still wants a manual pass on top of the unit test.
Tests
Sign in to staging with a test account that belongs to one Collect or Control workspace.
Open the workspace's Members page to load its member list.
Open Search → Reports and let it finish loading.
In Chrome DevTools → Network, select Offline.
In the console, run:
Without reloading, select Create → Create report in the Search header.
Verify the result:
Before reloading or going online, restore the original data:
In DevTools → Network, select No throttling.
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.
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectionAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari