Skip to content

Enhance subscription management with usage stats and tier changes#3540

Merged
Baalmart merged 4 commits into
stagingfrom
oauth-setup
May 26, 2026
Merged

Enhance subscription management with usage stats and tier changes#3540
Baalmart merged 4 commits into
stagingfrom
oauth-setup

Conversation

@OchiengPaul442

@OchiengPaul442 OchiengPaul442 commented May 25, 2026

Copy link
Copy Markdown
Contributor

Summary of Changes (What does this PR do?)

  • Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Status of maturity (all need to be checked before merging):

  • I've tested this locally
  • I consider this code done

Screenshots (optional)

Summary by CodeRabbit

  • New Features
    • Added "Usage & Limits" sub-tab to the Billing page for monitoring API usage and plan limits.
    • Enhanced subscription plan management with support for upgrading and downgrading between tiers.
    • Improved plan change dialogs with clearer messaging, plan comparison cards, and feature highlights.
    • Added support for scheduling subscription downgrades to take effect on the next billing period.

Review Change Stack

…ier change functionality

- Added UsageStats component to BillingPage for monitoring API usage.
- Updated BillingPage to include a new sub-tab for usage statistics.
- Enhanced CheckoutDialog to support tier upgrades and downgrades with appropriate messaging.
- Refactored SubscriptionSection to manage tier changes, including scheduling downgrades and handling plan actions.
- Implemented changeTier method in subscriptionService to facilitate tier changes with backend integration.
- Improved UI elements for better user experience and clarity on subscription status and actions.
@coderabbitai

coderabbitai Bot commented May 25, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@OchiengPaul442, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 39 minutes and 1 second. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2d153544-2936-4033-9e7d-49ed1e154048

📥 Commits

Reviewing files that changed from the base of the PR and between e8f78c5 and 344e58a.

📒 Files selected for processing (1)
  • src/platform/src/modules/feedback/components/FeedbackLauncher.tsx
📝 Walkthrough

Walkthrough

This PR implements subscription tier changes (upgrade and downgrade) with support for scheduled tier transitions at the next billing period. It extends the checkout flow to handle multiple plan-action modes and reorganizes usage statistics from the API client page to a dedicated billing page tab.

Changes

Subscription & Billing Flow Enhancement

Layer / File(s) Summary
Tier-change service API
src/platform/src/shared/services/subscriptionService.ts
New ChangeTierResponse type and changeTier() method authenticate, PATCH tier changes to /users/transactions/change-tier, normalize response payloads, and return either success with normalized tier/effective-from data or failure with comingSoon flag for payment-provider unavailability.
CheckoutDialog mode and plan preview
src/platform/src/modules/billing/components/CheckoutDialog.tsx
Extended props (currentPlan, mode, accessUntilLabel) enable mode-aware title/buttons and render plan comparison cards with feature lists; supports checkout, upgrade, and downgrade flows with conditional downgrade scheduling messaging.
SubscriptionSection state, styles, and notice generation
src/platform/src/modules/billing/components/SubscriptionSection.tsx
Adds planActionMode and pendingTierChange state, style constants (statusBadgeStyles, noticeToneStyles), helpers (getPaidTier, isSwitchablePaidStatus), effect to clear pending tier when matched, and refactors status notices to tone-based structure supporting past_due, cancelled, paused, and renewal-disabled cases.
Tier-change handlers and plan action config
src/platform/src/modules/billing/components/SubscriptionSection.tsx
closePlanDialog gates closes during in-flight actions; plan-dialog open handlers set planActionMode based on action type; handleChangeTierConfirm calls changeTier service and updates pendingTierChange; getPlanActionConfig computes per-plan button labels, modes, disabled states, and variant styling based on current tier/status and upgrade/downgrade type.
SubscriptionSection UI with dynamic badges and plan routing
src/platform/src/modules/billing/components/SubscriptionSection.tsx
Active-tier card renders status/renewal/scheduled-downgrade badges and tone-based notice blocks; plan cards show current/scheduled badges with conditionally-styled action buttons; plan-action-button routes to checkout or plan dialog based on computed mode; CheckoutDialog wired with mode, current plan, access-until label, and mode-aware confirmation routing.
Usage stats tab reorganization
src/platform/src/modules/billing/BillingPage.tsx, src/platform/src/modules/api-client/ApiClientPage.tsx
BillingPage imports and renders UsageStats as a new "Usage & Limits" sub-tab; ApiClientPage removes UsageStats component and imports trackApiClientAction for token-action analytics alignment.

Sequence Diagram

sequenceDiagram
  participant User
  participant SubscriptionSection
  participant CheckoutDialog
  participant SubscriptionService
  participant Backend as Backend API
  User->>SubscriptionSection: Click upgrade/downgrade plan
  SubscriptionSection->>CheckoutDialog: Open with mode & plan details
  CheckoutDialog->>User: Display plan comparison
  User->>CheckoutDialog: Confirm tier change
  CheckoutDialog->>SubscriptionSection: onConfirm()
  SubscriptionSection->>SubscriptionService: changeTier(newTier)
  SubscriptionService->>Backend: PATCH /users/transactions/change-tier
  Backend-->>SubscriptionService: ChangeTierResponse
  SubscriptionSection->>SubscriptionSection: Update pendingTierChange state
  SubscriptionSection->>User: Render scheduled/current badges & notice
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes


Possibly related PRs

  • airqo-platform/AirQo-frontend#3538: Both PRs refactor the subscription status/notice UI in SubscriptionSection.tsx with tone-based rendering and status badge styling updates.

Suggested reviewers

  • Baalmart

Poem

📈 Tiers now shift on command, from Standard to Premium gold,
With badges that whisper of changes yet to unfold,
The checkout dialog speaks in modes—upgrade, downgrade, anew,
While usage stats find their home where billing shines through. ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately captures the main objectives of the PR: adding usage statistics to the billing page and implementing tier change functionality across subscription management.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch oauth-setup

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • JIRA integration encountered authorization issues. Please disconnect and reconnect the integration in the CodeRabbit UI.

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 and usage tips.

@github-actions

Copy link
Copy Markdown
Contributor

New azure analytics_platform changes available for preview here

@OchiengPaul442
OchiengPaul442 requested a review from Baalmart May 25, 2026 21:38

@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 (1)
src/platform/src/modules/billing/components/SubscriptionSection.tsx (1)

562-620: 🏗️ Heavy lift

Avoid imperative refreshData() after tier-change; use keyed SWR/React Query (or make refresh cancellation-aware)

  • handleChangeTierConfirm (and other mutation handlers) calls await refreshData() after subscriptionService.changeTier(...), but this billing component currently doesn’t use SWR/React Query hooks for subscription/plans—so invalidateQueries(...) isn’t directly applicable without first introducing stable query/SWR keys + revalidation on success.
  • Either add keyed subscription/plans hooks and revalidate/mutate those keys after successful mutations, or keep the imperative refresh but wire AbortController and ensure cancellation/abort errors don’t show as user-facing failures.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/platform/src/modules/billing/components/SubscriptionSection.tsx` around
lines 562 - 620, handleChangeTierConfirm currently calls the imperative await
refreshData() after subscriptionService.changeTier; either switch to using keyed
data hooks and invalidate/mutate those keys on success (introduce a
subscriptions/plans query key and use your SWR/React Query mutate/invalidate
function instead of refreshData) or make refreshData cancellation-aware by
accepting an AbortSignal (add AbortController in handleChangeTierConfirm, pass
controller.signal into refreshData, have refreshData abort fetches and throw an
AbortError that you catch and ignore in the catch block) so aborted revalidation
does not surface as a user-facing failure; update other mutation handlers
similarly to use the same pattern and reference functions:
handleChangeTierConfirm, subscriptionService.changeTier, refreshData, and any
new query/mutate hooks or AbortController usage.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/platform/src/modules/billing/components/SubscriptionSection.tsx`:
- Around line 562-620: handleChangeTierConfirm currently calls the imperative
await refreshData() after subscriptionService.changeTier; either switch to using
keyed data hooks and invalidate/mutate those keys on success (introduce a
subscriptions/plans query key and use your SWR/React Query mutate/invalidate
function instead of refreshData) or make refreshData cancellation-aware by
accepting an AbortSignal (add AbortController in handleChangeTierConfirm, pass
controller.signal into refreshData, have refreshData abort fetches and throw an
AbortError that you catch and ignore in the catch block) so aborted revalidation
does not surface as a user-facing failure; update other mutation handlers
similarly to use the same pattern and reference functions:
handleChangeTierConfirm, subscriptionService.changeTier, refreshData, and any
new query/mutate hooks or AbortController usage.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0215c31a-4706-453a-86e2-9d03429ff9da

📥 Commits

Reviewing files that changed from the base of the PR and between 74503a9 and e8f78c5.

📒 Files selected for processing (5)
  • src/platform/src/modules/api-client/ApiClientPage.tsx
  • src/platform/src/modules/billing/BillingPage.tsx
  • src/platform/src/modules/billing/components/CheckoutDialog.tsx
  • src/platform/src/modules/billing/components/SubscriptionSection.tsx
  • src/platform/src/shared/services/subscriptionService.ts
💤 Files with no reviewable changes (1)
  • src/platform/src/modules/api-client/ApiClientPage.tsx

@github-actions

Copy link
Copy Markdown
Contributor

New azure analytics_platform changes available for preview here

@Baalmart
Baalmart merged commit 914339b into staging May 26, 2026
19 of 20 checks passed
@Baalmart
Baalmart deleted the oauth-setup branch May 26, 2026 04:58
@Baalmart Baalmart mentioned this pull request May 26, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants