Skip to content

Refresh billing NVPs on restricted action page mount - #83568

Merged
lakchote merged 5 commits into
mainfrom
claude-refreshBillingNVPsOnRestrictedActionPage
Mar 6, 2026
Merged

lakchote merged 5 commits into
mainfrom
claude-refreshBillingNVPsOnRestrictedActionPage

Conversation

@MelvinBot

Copy link
Copy Markdown
Contributor

Explanation of Change

When the WorkspaceRestrictedActionPage mounts, the billing NVP data (NVP_PRIVATE_AMOUNT_OWED, NVP_PRIVATE_OWNER_BILLING_GRACE_PERIOD_END, shared grace period collection) may be stale in Onyx. This causes the workspace restriction to persist even after the workspace owner has resolved their billing issue.

The stale data problem occurs because:

  1. There is no Pusher event for billing NVP changes, so clients miss server-side updates
  2. New Expensify relies on Onyx-cached NVP values, unlike Classic which fetches fresh data per page load
  3. The only way to get updated billing NVPs is via OpenApp/ReconnectApp (sign-out/sign-in) or OpenSubscriptionPage

This PR adds a fresh billing NVP fetch when the restricted action page mounts by calling openSubscriptionPage(). It also watches the billing Onyx keys so the component re-renders when fresh data arrives. If the fresh server data shows the restriction no longer applies (i.e. shouldRestrictUserBillableActions returns false), the user is automatically navigated back.

This follows the same pattern already used by SubscriptionSettingsPage which calls openSubscriptionPage() on mount.

Fixed Issues

$ https://github.com/Expensify/Expensify/issues/597281

Tests

  1. Have a workspace where billing has been resolved (amount owed cleared or grace period cleared on the server)
  2. Open New Expensify with stale cached data showing the workspace as restricted
  3. Navigate to the restricted action page for that workspace
  4. Verify the page automatically navigates back once fresh billing data is fetched from the server
  5. For workspaces that genuinely have outstanding billing, verify the restriction page still displays correctly
  • Verify that no errors appear in the JS console

Offline tests

  1. Go offline
  2. Navigate to a restricted workspace
  3. Verify the restriction page still displays (the API call will fail silently, and the cached restriction state is preserved)
  4. Go back online
  5. Navigate to the restricted workspace again
  6. Verify that if billing has been resolved, the page auto-navigates back after fetching fresh data

QA Steps

  1. Find or create a workspace with an outstanding billing restriction
  2. Verify the restricted action page still shows correctly for affected users (owner, admin, member)
  3. Resolve the billing issue (add payment card / clear amount owed)
  4. Without signing out, navigate to the restricted workspace
  5. Verify the restriction page briefly appears then auto-navigates back as fresh data arrives
  6. Verify sign-out/sign-in workaround still works as before
  • 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 followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I used JaimeGPT to get English > Spanish translation. I then posted it in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and 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)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • 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)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • 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 a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • 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

N/A - no UI changes, only data fetching behavior change

Android: mWeb Chrome

N/A - no UI changes, only data fetching behavior change

iOS: Native

N/A - no UI changes, only data fetching behavior change

iOS: mWeb Safari

N/A - no UI changes, only data fetching behavior change

MacOS: Chrome / Safari

N/A - no UI changes, only data fetching behavior change

When users land on the restricted action page, the billing NVP data in
Onyx may be stale (e.g., workspace owner paid their bill but the client
cache was never updated because there is no Pusher event for billing NVP
changes). This causes the restriction to persist incorrectly.

Call openSubscriptionPage() on mount to fetch fresh billing NVPs from
the server. Watch the billing Onyx keys so the component re-renders when
fresh data arrives. If the fresh data shows the restriction no longer
applies, automatically navigate the user back.

Co-authored-by: Rushat Gabhane <rushatgabhane@users.noreply.github.com>
@MelvinBot
MelvinBot requested a review from a team February 26, 2026 12:32
- Replace namespace import with named imports from @libs/PolicyUtils
- Use CONST.DEFAULT_NUMBER_ID instead of -1 literal

Co-authored-by: Rushat Gabhane <rushatgabhane@users.noreply.github.com>
@MelvinBot

Copy link
Copy Markdown
Contributor Author

Fixed the failing Changed files ESLint check. Two errors in WorkspaceRestrictedActionPage.tsx:

  1. Namespace import not allowed — replaced import * as PolicyUtils with named imports {isPolicyAdmin, isPolicyOwner, isPolicyUser}
  2. No default ID values — replaced session?.accountID ?? -1 with session?.accountID ?? CONST.DEFAULT_NUMBER_ID

@codecov

codecov Bot commented Feb 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
src/ONYXKEYS.ts 100.00% <ø> (ø)
src/libs/actions/Subscription.ts 0.00% <0.00%> (ø)
...Action/Workspace/WorkspaceRestrictedActionPage.tsx 0.00% <0.00%> (ø)
... and 179 files with indirect coverage changes

@rushatgabhane

Copy link
Copy Markdown
Member

@MelvinBot this seems like a bad UX?

@MelvinBot

Copy link
Copy Markdown
Contributor Author

That's a fair concern. Looking at the current implementation, the UX flow when billing has already been resolved is:

  1. User tries to perform a billable action (e.g., create an expense)
  2. The call site checks shouldRestrictUserBillableActions against stale cached data → returns true
  3. User gets redirected to the restricted action page (lock icon, "restricted" messaging)
  4. Page mounts, fires openSubscriptionPage() to fetch fresh billing NVPs
  5. Fresh data arrives → shouldRestrictUserBillableActions now returns false → Navigation.goBack()
  6. User is back where they started, but still hasn't completed their original action

The user briefly sees a "your workspace is restricted" page that then vanishes, and they have to retry whatever they were trying to do. That flash of alarming UI for a problem that's already been resolved isn't great.

A couple of alternative approaches that could improve this:

  1. Fetch fresh billing data earlier — e.g., in ReconnectApp or on workspace focus — so the cached data is already up to date before the user hits a billable action. This would prevent the restricted page from appearing at all in most cases.

  2. Show a brief loading/checking state — instead of immediately rendering the full restriction UI, the page could show a spinner or skeleton while openSubscriptionPage() resolves, and only render the restriction content if the restriction is still active after fresh data arrives. This avoids flashing scary messaging.

  3. Refresh at the check site — the 28+ call sites that check shouldRestrictUserBillableActions could trigger a fresh fetch and re-check before redirecting, though this would add latency to every billable action.

Option 2 would be the least invasive change to this PR — adding a loading state while the fresh billing data is in flight, and only showing the restriction UI once the data is confirmed current.

@rushatgabhane

Copy link
Copy Markdown
Member

@MelvinBot let's go with option 2

Instead of immediately rendering the restriction UI (which may no longer
apply due to stale cached data), show a FullScreenLoadingIndicator while
fresh billing data is fetched from the server. The restriction page is
only shown after confirming the restriction still applies, and if the
restriction has been resolved, the user is navigated back without ever
seeing the alarming restriction UI.

Co-authored-by: Rushat Gabhane <rushatgabhane@users.noreply.github.com>
@MelvinBot

Copy link
Copy Markdown
Contributor Author

Implemented option 2. The page now shows a FullScreenLoadingIndicator while waiting for fresh billing data from the server, instead of immediately rendering the restriction UI.

How it works:

  1. On mount, openSubscriptionPage() fires to fetch fresh billing NVPs
  2. While waiting for the response, a loading spinner is shown (no alarming restriction UI)
  3. When fresh data arrives via Onyx:
    • If restriction is resolved → Navigation.goBack() (user never sees the restriction page)
    • If restriction still applies → loading indicator is replaced with the appropriate restriction UI
  4. A 3-second timeout fallback ensures the loading indicator doesn't persist indefinitely if the API returns identical data or fails

@rushatgabhane

Copy link
Copy Markdown
Member

A 3-second timeout fallback ensures the loading indicator doesn't persist indefinitely if the API returns identical data or fails

@MelvinBot nahh don't add hacks please

Use optimisticData/successData/failureData on openSubscriptionPage to
track loading state via IS_LOADING_SUBSCRIPTION_DATA, instead of a
3-second setTimeout fallback.

Co-authored-by: Rushat Gabhane <rushatgabhane@users.noreply.github.com>
@MelvinBot

Copy link
Copy Markdown
Contributor Author

Fair point. Replaced the timeout with a proper Onyx loading key (IS_LOADING_SUBSCRIPTION_DATA), following the same pattern used by openPolicyAccountingPage.

How it works now:

  • openSubscriptionPage() sets IS_LOADING_SUBSCRIPTION_DATA to true optimistically, then to false on success or failure via successData/failureData
  • The restricted action page watches this Onyx key — shows a loading indicator while true, renders the restriction UI (or navigates back) once false
  • No timeouts, no refs, no local state — the loading lifecycle is fully driven by the API response through Onyx

@rushatgabhane

Copy link
Copy Markdown
Member

fantastic! mark it ready for review @MelvinBot

@MelvinBot
MelvinBot marked this pull request as ready for review February 26, 2026 13:28
@MelvinBot
MelvinBot requested a review from a team as a code owner February 26, 2026 13:28
@MelvinBot

Copy link
Copy Markdown
Contributor Author

Done — PR has been marked as ready for review.

@melvin-bot

melvin-bot Bot commented Feb 26, 2026

Copy link
Copy Markdown

@DylanDylann 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]

@melvin-bot
melvin-bot Bot requested review from a team and eVoloshchak and removed request for a team February 26, 2026 13:28
@melvin-bot

melvin-bot Bot commented Feb 26, 2026

Copy link
Copy Markdown

@eVoloshchak 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]

@rushatgabhane
rushatgabhane removed the request for review from DylanDylann February 26, 2026 13:32

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6865991772

ℹ️ 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".

return;
}
if (!shouldRestrictUserBillableActions(policyID, userBillingGracePeriodCollection)) {
Navigation.goBack();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Add fallback navigation when restriction is cleared

Calling Navigation.goBack() here can be a no-op when this screen is opened directly (e.g., deep link or browser refresh) because there is no back stack; goBack returns early when canGoBack() is false (src/libs/Navigation/Navigation.ts). In that case, even after fresh billing data shows the workspace is no longer restricted, the user stays on the restricted-action page instead of being returned to an accessible route.

Useful? React with 👍 / 👎.

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.

Thanks for flagging this. After investigating, the concern does not apply here.

The WorkspaceRestrictedActionPage lives inside the RIGHT_MODAL_NAVIGATOR (RHP). The Expensify navigation system guarantees a back stack always exists for RHP screens, even when opened via deep link or browser refresh.

The key is in src/libs/Navigation/helpers/getAdaptedStateFromPath.ts (lines 317-321):

const isRightModalNavigator = state.routes.find((route) => route.name === NAVIGATORS.RIGHT_MODAL_NAVIGATOR);

if (isRightModalNavigator) {
    return getRoutesWithIndex([{name: NAVIGATORS.REPORTS_SPLIT_NAVIGATOR}, ...state.routes]);
}

This adapter is registered as the global getStateFromPath in the linking config (src/libs/Navigation/linkingConfig/index.ts, line 9), so every URL — deep link, browser refresh, or direct entry — goes through it. When the URL resolves to an RHP route, a REPORTS_SPLIT_NAVIGATOR base route is automatically prepended to the stack.

So even when navigating directly to restricted-action/workspace/:policyID, the navigation state will always be: [REPORTS_SPLIT_NAVIGATOR, RIGHT_MODAL_NAVIGATOR], meaning canGoBack() returns true and goBack() successfully dismisses the modal.

No fallback route is needed.

@MelvinBot

Copy link
Copy Markdown
Contributor Author

The only failing check is the PR Reviewer Checklist (reviewerChecklist.js). This check fails because no reviewer has posted the reviewer checklist comment on this PR yet.

This is not a code issue — all code-related checks (ESLint, typecheck, Prettier, tests, builds, spellcheck, signed commits, etc.) are passing. The reviewer checklist check will resolve once a reviewer posts their checklist.

@MelvinBot

Copy link
Copy Markdown
Contributor Author

This PR is already marked as ready for review — it's not in draft state, so no change is needed.

@rushatgabhane
rushatgabhane requested a review from a team March 6, 2026 00:31
@melvin-bot
melvin-bot Bot requested review from shubham1206agra and removed request for a team March 6, 2026 00:31
@melvin-bot

melvin-bot Bot commented Mar 6, 2026

Copy link
Copy Markdown

@shubham1206agra 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]

@rushatgabhane
rushatgabhane requested review from a team and removed request for shubham1206agra March 6, 2026 00:31
@melvin-bot
melvin-bot Bot requested a review from huult March 6, 2026 00:31
@melvin-bot

melvin-bot Bot commented Mar 6, 2026

Copy link
Copy Markdown

@huult 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]

@melvin-bot
melvin-bot Bot removed the request for review from a team March 6, 2026 00:31
@rushatgabhane
rushatgabhane requested review from a team and youssef-lr and removed request for huult March 6, 2026 00:33
@melvin-bot
melvin-bot Bot requested review from FitseTLT and removed request for a team March 6, 2026 00:33
@melvin-bot

melvin-bot Bot commented Mar 6, 2026

Copy link
Copy Markdown

@FitseTLT 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]

@rushatgabhane

rushatgabhane commented Mar 6, 2026 •

Copy link
Copy Markdown
Member

@youssef-lr Checklist here #83568 (comment)

@lakchote lakchote left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@lakchote
lakchote merged commit d955410 into main Mar 6, 2026
34 checks passed
@lakchote
lakchote deleted the claude-refreshBillingNVPsOnRestrictedActionPage branch March 6, 2026 12:24
@github-actions

github-actions Bot commented Mar 6, 2026

Copy link
Copy Markdown
Contributor

🚧 @lakchote has triggered a test Expensify/App build. You can view the workflow run here.

@OSBotify

OSBotify commented Mar 6, 2026

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify OSBotify mentioned this pull request Mar 6, 2026
52 tasks done
@OSBotify

OSBotify commented Mar 6, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/lakchote in version: 9.3.33-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 failure ❌

@m-natarajan

Copy link
Copy Markdown

@lakchote @rushatgabhane @heyjennahay @youssef-lr Can this PR please be tested internally, Adding billing is not possible for applause testers.

@OSBotify

OSBotify commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/luacmartins in version: 9.3.33-5 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants