Enhance subscription management with usage stats and tier changes#3540
Conversation
…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.
…ean up button class in SubscriptionSection
|
Warning Review limit reached
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 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 configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis 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. ChangesSubscription & Billing Flow Enhancement
Sequence DiagramsequenceDiagram
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
Estimated code review effort🎯 4 (Complex) | ⏱️ ~75 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsErrors were encountered while retrieving linked issues. Errors (1)
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. Comment |
|
New azure analytics_platform changes available for preview here |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/platform/src/modules/billing/components/SubscriptionSection.tsx (1)
562-620: 🏗️ Heavy liftAvoid imperative
refreshData()after tier-change; use keyed SWR/React Query (or make refresh cancellation-aware)
handleChangeTierConfirm(and other mutation handlers) callsawait refreshData()aftersubscriptionService.changeTier(...), but this billing component currently doesn’t use SWR/React Query hooks for subscription/plans—soinvalidateQueries(...)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
AbortControllerand 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
📒 Files selected for processing (5)
src/platform/src/modules/api-client/ApiClientPage.tsxsrc/platform/src/modules/billing/BillingPage.tsxsrc/platform/src/modules/billing/components/CheckoutDialog.tsxsrc/platform/src/modules/billing/components/SubscriptionSection.tsxsrc/platform/src/shared/services/subscriptionService.ts
💤 Files with no reviewable changes (1)
- src/platform/src/modules/api-client/ApiClientPage.tsx
|
New azure analytics_platform changes available for preview here |
Summary of Changes (What does this PR do?)
Status of maturity (all need to be checked before merging):
Screenshots (optional)
Summary by CodeRabbit