Skip to content

Fix: Prevent dead-end when closing account with outstanding balance#82905

Merged
luacmartins merged 22 commits intoExpensify:mainfrom
imgyf:imgyf/fix-82200-outstanding-balance-dead-end
Mar 11, 2026
Merged

Fix: Prevent dead-end when closing account with outstanding balance#82905
luacmartins merged 22 commits intoExpensify:mainfrom
imgyf:imgyf/fix-82200-outstanding-balance-dead-end

Conversation

@imgyf
Copy link
Contributor

@imgyf imgyf commented Feb 19, 2026

Explanation of Change

When a user deletes their last paid workspace while having an outstanding billing balance, the Subscription menu item and page become inaccessible (because useSubscriptionPlan returns null with no owned paid policies). This leaves the user in a dead-end state where they cannot settle their balance or close their account.

This PR:

  • Keeps the Subscription page and its menu item visible when amountOwed > 0, even after all workspaces are deleted
  • Adds a pre-deletion guard on the last paid workspace when an outstanding balance exists, showing a modal that redirects users to subscription settings to settle the balance
  • Extracts the guard logic into a shared useOutstandingBalanceGuard hook used by both WorkspaceOverviewPage and WorkspacesListPage
  • Skipped CloseAccountPage changes per @Ollyws's feedback (that flow is inaccessible to the user in this scenario)

Fixed Issues

$ #82200
PROPOSAL: #82200 (comment)

Tests

  1. Log in to the app
  2. Create a workspace
  3. Open browser console and run Onyx.set('nvp_private_amountOwed', 100) to simulate an outstanding balance
  4. Go to Settings and verify the Subscription menu item is visible
  5. Delete the workspace (Settings > Workspaces > workspace > Overview > Delete workspace)
  6. Go back to Settings and verify the Subscription menu item is still visible
  7. Click on Subscription and verify the page loads correctly
  8. Create a new workspace
  9. Run Onyx.set('nvp_private_amountOwed', 100) again in console
  10. Attempt to delete this workspace from the Workspaces list page (three-dot menu > Delete)
  11. Verify a modal appears warning about the outstanding balance
  12. Confirm the modal's "Go to subscription" button navigates to the Subscription settings page
  13. Repeat steps 10-12 from the Workspace overview page (workspace > Overview > Delete workspace)
  • Verify that no errors appear in the JS console

Offline tests

  1. Disconnect from the network
  2. With amountOwed > 0 and no workspaces, verify the Subscription menu item is still visible in Settings
  3. Attempt to delete the last workspace while offline with an outstanding balance — verify the guard modal still appears
  4. Reconnect and verify normal behavior resumes

QA Steps

Same as Tests above, performed on staging environment.

  • 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 there are no new alerts related to the canBeMissing param for useOnyx
  • 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
    • 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: N/A — no new CSS styles were added
    • 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: N/A — no new assets were added or modified
    • 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. N/A — this PR does not modify message editing/sending code
  • 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) N/A — no generic components were modified
  • 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. N/A — no Storybook stories are affected
  • 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. N/A — the modified pages are not accessed by direct deeplinks
  • 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: N/A — no UI layout or form input style changes were made
    • 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. N/A — no new pages were added
  • 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-native.mp4
Android: mWeb Chrome
mweb-chrome.mp4
iOS: Native
ios-native.mov
iOS: mWeb Safari
mweb-safari.mov
MacOS: Chrome / Safari
bug-fixed.mov

…xpensify#82200)

Keep Subscription page and menu item accessible when amountOwed > 0,
even after all workspaces are deleted. Add pre-deletion guard on last
paid workspace to redirect users to subscription settings to settle
their outstanding balance first.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@imgyf imgyf requested review from a team as code owners February 19, 2026 09:57
@melvin-bot
Copy link

melvin-bot bot commented Feb 19, 2026

Hey, I noticed you changed src/languages/en.ts in a PR from a fork. For security reasons, translations are not generated automatically for PRs from forks.

If you want to automatically generate translations for other locales, an Expensify employee will have to:

  1. Look at the code and make sure there are no malicious changes.
  2. Run the Generate static translations GitHub workflow. If you have write access and the K2 extension, you can simply click: [this button]

Alternatively, if you are an external contributor, you can run the translation script locally with your own OpenAI API key. To learn more, try running:

npx ts-node ./scripts/generateTranslations.ts --help

Typically, you'd want to translate only what you changed by running npx ts-node ./scripts/generateTranslations.ts --compare-ref main

@melvin-bot melvin-bot bot removed the request for review from a team February 19, 2026 09:57
@github-actions
Copy link
Contributor

github-actions bot commented Feb 19, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@melvin-bot melvin-bot bot requested a review from carlosmiceli February 19, 2026 09:57
@melvin-bot
Copy link

melvin-bot bot commented Feb 19, 2026

@carlosmiceli 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 February 19, 2026 09:57
@@ -544,6 +570,18 @@ function WorkspaceOverviewPage({policyDraft, policy: policyProp, route}: Workspa
shouldShowCancelButton={false}
Copy link
Contributor

Choose a reason for hiding this comment

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

❌ CONSISTENCY-3 (docs)

This ConfirmModal block (including its state isOutstandingBalanceModalOpen, the setIsOutstandingBalanceModalOpen setter, and the onConfirm/onCancel handlers) is duplicated nearly identically in WorkspacesListPage.tsx. Both instances share the same title, prompt, confirmText, cancelText, and navigation logic.

Consider extracting this into a shared custom hook (e.g., useOutstandingBalanceGuard) that encapsulates the modal state, the guard check (hasAmountOwed() && ownerPolicies.length === 1), and returns the modal component or its props. This would eliminate the duplication and ensure both pages stay in sync if the behavior changes.


Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

@github-actions
Copy link
Contributor

PR Review: Fix outstanding balance dead-end

Key concerns:

  1. Formatting noise - Most changes are Prettier reformatting, inflating diff from ~50 meaningful lines to 215+.

  2. Inconsistent amountOwed access - InitialSettingsPage uses getAmountOwed() during render; SubscriptionSettingsPage uses useOnyx hook. Use the same reactive pattern.

  3. Duplicated ConfirmModal - Outstanding balance modal is copy-pasted between WorkspaceOverviewPage and WorkspacesListPage. Extract into shared hook.

  4. Guard ordering - hasAmountOwed check before shouldBlockWorkspaceDeletionForInvoicifyUser. Verify priority.

  5. Different ownerPolicies source - WorkspaceOverviewPage uses ownerPoliciesSelector; WorkspacesListPage calls getOwnedPaidPolicies inline.

Copy link

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

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: edf21ee925

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

setPolicyIDToDelete(item.policyID);
setPolicyNameToDelete(item.title);

if (hasAmountOwed() && getOwnedPaidPolicies(policies, currentUserPersonalDetails?.accountID).length === 1) {

Choose a reason for hiding this comment

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

P2 Badge Restrict outstanding-balance guard to paid workspace deletions

This guard blocks deletion whenever the user has exactly one owned paid workspace, but it does not verify that the workspace being deleted is that paid workspace. In production, a user with one paid workspace (carrying the balance) plus any free workspace will be prevented from deleting the free workspace and incorrectly sent to Subscription, even though they are not deleting their last paid workspace. The same predicate pattern is also used in WorkspaceOverviewPage, so both delete entry points over-block.

Useful? React with 👍 / 👎.

@imgyf
Copy link
Contributor Author

imgyf commented Feb 19, 2026

I have read the CLA Document and I hereby sign the CLA

CLABotify added a commit to Expensify/CLA that referenced this pull request Feb 19, 2026
imgyf and others added 3 commits February 19, 2026 18:27
Extract duplicated ConfirmModal state, guard check, and modal component
from WorkspaceOverviewPage and WorkspacesListPage into a shared
useOutstandingBalanceGuard hook to keep both pages in sync.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Remove formatting noise: only meaningful changes, no Prettier reformatting
- Use consistent reactive pattern: useOnyx for amountOwed in both
  InitialSettingsPage and SubscriptionSettingsPage (instead of getAmountOwed)
- Use consistent ownerPoliciesSelector in both WorkspaceOverviewPage and
  WorkspacesListPage (instead of getOwnedPaidPolicies inline)
- Guard ordering verified: invoicify check runs first, then outstanding
  balance check

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@imgyf imgyf changed the title Fix: Prevent dead-end when closing account with outstanding balance Prevent dead-end when closing account with outstanding balance Feb 19, 2026
Copy link
Contributor

@joekaufmanexpensify joekaufmanexpensify left a comment

Choose a reason for hiding this comment

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

Good for product

@carlosmiceli
Copy link
Contributor

Shouldn't @Ollyws have been assigned as reviewer here?

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
imgyf and others added 2 commits February 21, 2026 03:15
…ore showing guard modal

The OutstandingBalanceModal was created via useCallback as a component, causing
unmount/remount issues where the modal never appeared on native platforms. Changed
to return a JSX element via useMemo instead.

Also added wouldBlockDeletion boolean so popover/dropdown menus close before the
guard modal shows — otherwise the open popover blocks the ConfirmModal on native.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@imgyf
Copy link
Contributor Author

imgyf commented Feb 20, 2026

Hi @carlosmiceli @joekaufmanexpensify @Ollyws , the PR is fully ready for review.

@imgyf imgyf requested a review from luacmartins March 7, 2026 03:50
@imgyf
Copy link
Contributor Author

imgyf commented Mar 9, 2026

@luacmartins please review again.

@luacmartins
Copy link
Contributor

@codex review

Copy link

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

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: 4a1d259022

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

@luacmartins
Copy link
Contributor

@imgyf ESLint check is failing. Maybe you can merge main to fix it?

@imgyf
Copy link
Contributor Author

imgyf commented Mar 11, 2026

@luacmartins merged main

@luacmartins luacmartins removed the request for review from carlosmiceli March 11, 2026 16:35
@luacmartins luacmartins merged commit e76d5b4 into Expensify:main Mar 11, 2026
30 checks passed
@OSBotify
Copy link
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.

@github-actions
Copy link
Contributor

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

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/luacmartins in version: 9.3.36-0 🚀

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

@IuliiaHerets
Copy link

Hi @imgyf. QA team is not able to enable the 'Outstanding balance' workspace when running the Onyx code on the web and opening the account on mobile. Does this PR apply to Native apps?

@imgyf
Copy link
Contributor Author

imgyf commented Mar 12, 2026

Hi @IuliiaHerets, yes the PR applies to Native apps too. You can see my videos in the PR description.

For Native apps testing, I did not run Onyx code on the web but instead added useEffect to simulate the condition.

@kavimuru
Copy link

@imgyf I don't think Applause can'add useEffect in native aops

@imgyf
Copy link
Contributor Author

imgyf commented Mar 12, 2026

@kavimuru sorry what's Applause? is there a way where you can actually get to the condition without using Onyx?

@luacmartins
Copy link
Contributor

@imgyf we don't have access to the console in staging builds, so we need different steps to test this

@imgyf
Copy link
Contributor Author

imgyf commented Mar 12, 2026

@luacmartins @kavimuru @IuliiaHerets Is testing on staging web where browser console is available acceptable? Because the UI logic is shared across all platforms, so web verification covers the fix.

If it is not acceptable, then QA would need to create an actual outstanding balance by:

  • Having a paid workspace with a billing method that fails/gets removed
  • This would naturally set amountOwed > 0 via the backend

@luacmartins
Copy link
Contributor

@imgyf we have to test on all platforms, including ios/android native

@imgyf
Copy link
Contributor Author

imgyf commented Mar 12, 2026

@luacmartins can we have QA create an actual outstanding balance by having a paid workspace with a billing method that fails/gets removed? This would naturally set amountOwed > 0 via the backend.

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/luacmartins in version: 9.3.36-10 🚀

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.

8 participants