Enhance billing and subscription management: Added payment method checks in ProtectedRoute, improved error handling in billing components, and optimized API calls to reduce throttling. Updated user account handling in various components to ensure accurate plan and subscription data display.

This commit is contained in:
IGNY8 VPS (Salman)
2025-12-07 10:07:28 +00:00
parent 46fc6dcf04
commit 508b6b4220
26 changed files with 518 additions and 69 deletions

View File

@@ -0,0 +1,46 @@
## Session Configuration Summary (Signup → Activation → Billing)
This doc captures all changes made in this session across backend and frontend to stabilize signup, onboarding, plans, payments, throttling, and admin flows.
### Backend Changes
- Registration slug collision handling
- Now generates unique account slugs by appending numeric suffixes to avoid `IntegrityError` on duplicate slugs during signup.
- File: `backend/igny8_core/auth/serializers.py`
- Plans endpoint throttling removed
- `/api/v1/auth/plans/` no longer uses throttling to prevent 429 responses during onboarding/plan fetch.
- File: `backend/igny8_core/auth/views.py`
### Frontend Changes
- Plans visibility and throttling behavior
- Removed plan filtering to only Starter/Growth/Scale; all active plans returned by the API are shown.
- Added a 429 retry: on throttling while loading billing/plans, shows “throttled, retrying” and auto-retries once after 2 seconds.
- File: `frontend/src/pages/account/PlansAndBillingPage.tsx`
- Signup redirect hard fallback
- After successful signup, still calls router navigate to `/account/plans`, and also forces a 500ms hard redirect to `/account/plans` if navigation stalls.
- File: `frontend/src/components/auth/SignUpForm.tsx`
- Payment method preference
- Auto-selects payment method id 14 when available and best-effort sets it as default; prefers enabled methods.
- File: `frontend/src/pages/account/PlansAndBillingPage.tsx`
- Admin subscriptions actions and linking
- Added Activate/Cancel and Refresh actions on `/admin/subscriptions`.
- `/admin/accounts` “Manage” links now deep-link to `/admin/subscriptions?account_id=...`.
- Files: `frontend/src/pages/admin/AdminSubscriptionsPage.tsx`, `frontend/src/pages/admin/AdminAllAccountsPage.tsx`
- Upgrade gating helper
- Introduced `isUpgradeError` / `showUpgradeToast` and applied to Sites list to surface upgrade prompts on 402/403. ModuleGuard imported/prepared.
- Files: `frontend/src/utils/upgrade.ts`, `frontend/src/pages/Sites/List.tsx`, `frontend/src/components/common/ModuleGuard.tsx`
- Balance error UX
- Shows “Balance unavailable” with retry; clears stale balance on error instead of silently showing defaults.
- Files: `frontend/src/components/dashboard/CreditBalanceWidget.tsx`, `frontend/src/store/billingStore.ts`
### Behavior Notes / Outcomes
- Signup now survives duplicate slug cases (unique slug generation).
- Plans fetch should not be throttled; all active plans returned by the API will render.
- If SPA navigation fails post-signup, the hard redirect ensures landing on `/account/plans`.
- Payment method id 14 is preferred when present; otherwise any default/available method can be used.
- Admins can activate/cancel subscriptions from the subscriptions page; Manage links carry `account_id`.
- Upgrade prompts now surface on 402/403 in Sites list; balance widgets show proper error/retry state.
### Operational Dependencies / Reminders
- Ensure the backend exposes at least one active plan; otherwise the list will remain empty.
- Ensure at least one payment method exists (id 14 preferred) so plan selection/purchases are not blocked.