Skip to content

improvement(settings): add View Invoices button to subscription billing details#3726

Merged
waleedlatif1 merged 3 commits intostagingfrom
waleedlatif1/view-invoices-btn
Mar 24, 2026
Merged

improvement(settings): add View Invoices button to subscription billing details#3726
waleedlatif1 merged 3 commits intostagingfrom
waleedlatif1/view-invoices-btn

Conversation

@waleedlatif1
Copy link
Collaborator

Summary

  • Add "View Invoices" button to the billing details card on the subscription settings page
  • Opens Stripe billing portal in a new tab using synchronous window.open to avoid popup blockers
  • Only visible to paid users with billing access (hidden for team members and enterprise members without permissions)

Type of Change

  • New feature / improvement

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Mar 23, 2026

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Mar 24, 2026 0:04am

Request Review

@cursor
Copy link

cursor bot commented Mar 23, 2026

PR Summary

Low Risk
Low risk UI-only change that reuses existing useOpenBillingPortal mutation to navigate to Stripe; main risk is incorrect permission gating or new-tab navigation edge cases (popup blockers/window reuse).

Overview
Adds a "View Invoices" action to the subscription billing details card for paid workspaces, shown only when the user is not in team-member view and is not an enterprise member.

Clicking the button opens the Stripe billing portal in a new tab via a synchronous window.open, then redirects that tab to the portal URL returned by useOpenBillingPortal (with basic error logging/cleanup on failure).

Written by Cursor Bugbot for commit 8cc2fb0. Configure here.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 24, 2026

Greptile Summary

This PR adds a "View Invoices" button to the billing details card on the subscription settings page, allowing paid users (excluding team members and enterprise non-admins) to open the Stripe billing portal in a new tab.

Key changes:

  • New View Invoices Button rendered inside the existing billing details div, gated by subscription.isPaid && !permissions.showTeamMemberView && !permissions.isEnterpriseMember — consistent with the adjacent "Next Billing Date" row's permission logic
  • Uses the window.open('', '_blank') synchronous pre-open pattern to avoid popup blockers; on success navigates the pre-opened window to the Stripe URL, on popup-blocked falls back to redirecting the current page
  • Reuses the existing openBillingPortal mutation (useOpenBillingPortal) with the same context/organizationId derivation already used elsewhere in the file
  • The only non-blocking concern is that the onError handler silently closes the blank tab without any user-visible notification; no toast infrastructure currently exists in this component

Confidence Score: 4/5

  • Safe to merge — focused, well-scoped addition that reuses existing patterns with correct permission gating
  • The change is small and self-contained, correctly reuses the existing openBillingPortal mutation and mirrors the exact same permission conditions already applied to the "Next Billing Date" row. The only non-critical gap is the absence of a user-facing error notification, which is consistent with how the rest of the file handles billing portal errors today.
  • No files require special attention

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/settings/components/subscription/subscription.tsx Adds "View Invoices" button using the existing openBillingPortal mutation with correct permission gating (isPaid && !showTeamMemberView && !isEnterpriseMember); uses the standard window.open('', '_blank') trick to avoid popup blockers; error handling silently closes the blank tab without user feedback

Sequence Diagram

sequenceDiagram
    actor User
    participant Button as View Invoices Button
    participant Browser as Browser (new tab)
    participant Mutation as openBillingPortal
    participant API as /api/billing/portal
    participant Stripe as Stripe Billing Portal

    User->>Button: Click "View Invoices"
    Button->>Browser: window.open('', '_blank') — synchronous pre-open
    Button->>Mutation: mutate({ context, organizationId, returnUrl })
    Mutation->>API: POST /api/billing/portal
    API->>Stripe: Create portal session
    Stripe-->>API: { url }
    API-->>Mutation: { url }
    alt Success
        Mutation-->>Browser: portalWindow.location.href = url
        Browser->>Stripe: Navigate to billing portal
    else Error (popup blocked — portalWindow is null)
        Mutation-->>Button: data.url available
        Button->>Browser: window.location.href = url (current tab)
    else Mutation error
        Mutation-->>Browser: portalWindow?.close()
        Note over Button: logger.error only, no user toast
    end
Loading

Reviews (1): Last reviewed commit: "lint" | Re-trigger Greptile

@waleedlatif1 waleedlatif1 merged commit 88bc16b into staging Mar 24, 2026
6 checks passed
@waleedlatif1 waleedlatif1 deleted the waleedlatif1/view-invoices-btn branch March 24, 2026 00:04
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.

1 participant