🌐 US-Proxy
class="logged-out env-production page-responsive" style="word-wrap: break-word;" >
Skip to content

fix(admin): open billing portal in same tab to reflect edits on return - #1722

Merged
rohilsurana merged 1 commit into
mainfrom
feat/admin-refresh-billing-on-portal-return
Jul 1, 2026
Merged

fix(admin): open billing portal in same tab to reflect edits on return#1722
rohilsurana merged 1 commit into
mainfrom
feat/admin-refresh-billing-on-portal-return

Conversation

@rohilsurana

@rohilsurana rohilsurana commented Jul 1, 2026

Copy link
Copy Markdown
Member

What

Opens the Stripe customer portal in the same tab from the admin org Billing side panel (the pencil action from #1715), instead of a new tab.

This matches the client app's billing flow: the admin page navigates away to Stripe, and when the super user finishes (via Stripe's return link or the browser back button) they land back on a freshly loaded admin page — so any billing address / details they edited show up without any manual refresh.

Why

The new-tab approach left the admin panel showing the stale address after an edit, because the original tab was never reloaded. Rather than adding tab-visibility refetch logic, this mirrors the client app and lets a normal page navigation do the work.

How

  • Replaces the new-tab window.open (and its popup-blocker workaround) with window.location.href = checkoutUrl, the same pattern used in the client billing view.
  • Drops the now-unnecessary refresh plumbing (visibility listener, ref flag, and the fetchBillingAccountDetails context call).
  • successUrl/cancelUrl remain the current admin page, so Stripe returns the user here.

Test plan

  • eslint passes on the changed file.
  • Manual: open an org in the admin app → Billing → pencil → the page navigates to the Stripe portal → edit the billing address → return (Stripe's return link or back button) → the admin page reloads and shows the updated address.

@vercel

vercel Bot commented Jul 1, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
frontier Ready Ready Preview, Comment Jul 1, 2026 7:43am

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5a148f80-6779-4edd-9cf4-c89c14338506

📥 Commits

Reviewing files that changed from the base of the PR and between 7b05b8f and 80c0b10.

📒 Files selected for processing (1)
  • web/sdk/admin/views/organizations/details/side-panel/billing-details-section.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • web/sdk/admin/views/organizations/details/side-panel/billing-details-section.tsx

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Updated the billing portal launch flow to navigate the current page to the generated billing portal URL, improving consistency across browser scenarios.
    • Removed the previous pre-open/cleanup tab behavior to make portal redirects more reliable.

Walkthrough

The billing portal flow now skips pre-opening a separate tab and redirects the current page to the checkout URL returned by createCheckout. Error handling no longer manages portal tab cleanup.

Changes

Billing portal navigation update

Layer / File(s) Summary
In-place portal redirect
web/sdk/admin/views/organizations/details/side-panel/billing-details-section.tsx
Removes pre-opened tab setup, redirects the current tab to the returned checkoutUrl with window.location.href, and trims the error path to rely on the mutation error handling.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • raystack/frontier#1715: Modifies the same billing-details-section.tsx portal-opening flow that this PR changes from tab-based handling to in-place navigation.

Suggested reviewers: paanSinghCoder, rohanchkrabrty

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (2)
web/sdk/admin/views/organizations/details/side-panel/billing-details-section.tsx (2)

94-107: 🎯 Functional Correctness | 🔵 Trivial | 🏗️ Heavy lift

One-shot refresh flag may leave data stale on repeated portal round-trips.

portalOpenedRef.current is reset to false the moment the tab becomes visible again, so only the first return from the Stripe portal triggers a refetch. If the user keeps the portal tab open and toggles back to the admin tab multiple times while still editing (e.g., checks something in admin, returns to the portal, edits the address further, comes back again), subsequent returns won't refresh — reintroducing the exact stale-data problem this PR is meant to fix.

Consider not resetting the flag until the portal tab is actually known to be closed (e.g., track the portalTab/window reference and poll .closed, or listen for its unload/pagehide), so every return-to-tab visit while the portal is still open triggers a refresh.

💡 Illustrative approach
-  useEffect(() => {
-    const handleVisibilityChange = () => {
-      if (document.visibilityState === "visible" && portalOpenedRef.current) {
-        portalOpenedRef.current = false;
-        fetchBillingAccountDetails();
-      }
-    };
+  useEffect(() => {
+    const handleVisibilityChange = () => {
+      if (document.visibilityState === "visible" && portalOpenedRef.current) {
+        fetchBillingAccountDetails();
+        // Only stop refreshing once the portal tab itself has been closed.
+        if (portalTabRef.current?.closed) {
+          portalOpenedRef.current = false;
+        }
+      }
+    };
     document.addEventListener("visibilitychange", handleVisibilityChange);
     return () => {
       document.removeEventListener("visibilitychange", handleVisibilityChange);
     };
   }, [fetchBillingAccountDetails]);

100-100: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low value

Unhandled rejection risk on fetchBillingAccountDetails().

The refetch promise is fired without a .catch/await. If it rejects, this could surface as an unhandled promise rejection.

🛡️ Proposed fix
-        fetchBillingAccountDetails();
+        fetchBillingAccountDetails()?.catch(() => {
+          // errors are already surfaced via the query's error state
+        });

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 65ec65f6-485e-4c28-92d1-7397f5df75ec

📥 Commits

Reviewing files that changed from the base of the PR and between e829b65 and a1f1029.

📒 Files selected for processing (1)
  • web/sdk/admin/views/organizations/details/side-panel/billing-details-section.tsx

@rohilsurana
rohilsurana force-pushed the feat/admin-refresh-billing-on-portal-return branch from a1f1029 to 7b05b8f Compare July 1, 2026 07:38
@rohilsurana rohilsurana changed the title feat(admin): refresh billing details when returning from stripe portal fix(admin): open billing portal in same tab to reflect edits on return Jul 1, 2026
@rohilsurana
rohilsurana force-pushed the feat/admin-refresh-billing-on-portal-return branch from 7b05b8f to 80c0b10 Compare July 1, 2026 07:42
@rohilsurana
rohilsurana merged commit 1e95e03 into main Jul 1, 2026
8 checks passed
@rohilsurana
rohilsurana deleted the feat/admin-refresh-billing-on-portal-return branch July 1, 2026 07:44
@coveralls

coveralls commented Jul 1, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 28501806572

Warning

Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes.
Quick fix: rebase this PR. Learn more →

Coverage remained the same at 43.819%

Details

  • Coverage remained the same as the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 37096
Covered Lines: 16255
Line Coverage: 43.82%
Coverage Strength: 12.38 hits per line

💛 - Coveralls

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.

3 participants