Skip to content

[codex] add recharge controls and dashboard subscription summary#4255

Closed
BoJun9527 wants to merge 1 commit intoQuantumNous:mainfrom
BoJun9527:codex/recharge-controls-dashboard-summary
Closed

[codex] add recharge controls and dashboard subscription summary#4255
BoJun9527 wants to merge 1 commit intoQuantumNous:mainfrom
BoJun9527:codex/recharge-controls-dashboard-summary

Conversation

@BoJun9527
Copy link
Copy Markdown

@BoJun9527 BoJun9527 commented Apr 14, 2026

What changed

  • added allow_recharge user-level controls across backend persistence, self APIs, top-up access checks, and admin user management UI
  • added a dashboard subscription summary with primary subscription selection, quota usage display, popover details, and iterative UI refinements
  • added regression coverage for subscription summary shaping, recharge access behavior, and PostgreSQL-specific allow_recharge query handling

Why

  • the deployment includes a custom allow_recharge workflow, so the local source needed to preserve and codify that behavior instead of losing it on the next release
  • users needed a compact way to see current subscription usage from the dashboard header without drilling into the subscription page
  • recent UI iterations also fixed a runtime render error in the dashboard summary and aligned the progress rail with the visible content width

Impact

  • admins can explicitly allow or restrict wallet recharge per user
  • recharge-restricted users are blocked from the normal recharge flow while still keeping subscription-related surfaces available
  • dashboard users now see a compact subscription usage summary and can expand for reset timing/details

Root cause

  • the custom allow_recharge behavior existed outside the current repo state, so it had to be reintroduced into source before publishing a new build
  • the dashboard summary component previously referenced t(...) without a guaranteed translator prop, which could crash the whole page during render
  • the trigger rail originally used the button width for its progress line, causing the misalignment seen in the final UI review

Validation

  • node --test /Users/bojun/codex/.tmp/new-api/web/src/helpers/rechargeAccess.test.js /Users/bojun/codex/.tmp/new-api/web/src/helpers/dashboardSubscriptionSummary.test.js
  • local linux/amd64 Docker builds succeeded repeatedly for deployment packaging
  • deployed and health-checked on the US server through rolling docker load updates

Notes

  • direct push to QuantumNous/new-api was denied, so this PR is opened from the fork BoJun9527/new-api

Summary by CodeRabbit

  • New Features
    • Primary subscription and active subscription count now displayed in subscription information
    • Recharge functionality can be restricted per user by administrators
    • Dashboard displays subscription summary with quota usage and reset information
    • New user permission setting to control recharge access

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 14, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7892539c-db23-426a-b127-4f498b020d24

📥 Commits

Reviewing files that changed from the base of the PR and between 8c8661d and 9359b7a.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (28)
  • controller/subscription.go
  • controller/subscription_self_test.go
  • controller/topup.go
  • controller/topup_access.go
  • controller/topup_access_test.go
  • controller/topup_creem.go
  • controller/topup_stripe.go
  • controller/topup_waffo.go
  • controller/user.go
  • controller/user_recharge_test.go
  • go.mod
  • model/subscription.go
  • model/user.go
  • model/user_allow_recharge_test.go
  • web/src/components/dashboard/DashboardHeader.jsx
  • web/src/components/dashboard/DashboardSubscriptionSummary.jsx
  • web/src/components/dashboard/index.jsx
  • web/src/components/layout/SiderBar.jsx
  • web/src/components/layout/headerbar/UserArea.jsx
  • web/src/components/table/users/modals/AddUserModal.jsx
  • web/src/components/table/users/modals/EditUserModal.jsx
  • web/src/components/topup/RechargeCard.jsx
  • web/src/components/topup/index.jsx
  • web/src/helpers/dashboardSubscriptionSummary.js
  • web/src/helpers/dashboardSubscriptionSummary.test.js
  • web/src/helpers/rechargeAccess.js
  • web/src/helpers/rechargeAccess.test.js
  • web/src/hooks/dashboard/useDashboardData.js

Walkthrough

This PR implements an allow-recharge access control system, adding an AllowRecharge field to the User model with permission guards on all top-up endpoints. It extends subscription endpoints to expose plan details and primary subscription selection, and provides frontend UI for managing and enforcing these permissions across dashboard and top-up flows.

Changes

Cohort / File(s) Summary
User Model & Field
model/user.go, model/user_allow_recharge_test.go
Added AllowRecharge boolean field (default true) to User struct; updated GetUserById to query directly without pre-filled ID; modified User.Edit to persist allow_recharge alongside other editable fields. Test verifies query behavior on PostgreSQL.
User Controller Endpoints
controller/user.go, controller/user_recharge_test.go
Updated Register and CreateUser to initialize AllowRecharge (defaulting true); extended GetSelf response to include allow_recharge; refactored UpdateUser and CreateUser to decode into generic map first, preserving AllowRecharge as optional field. Tests verify persistence and API exposure.
Subscription Model & Selection
model/subscription.go
Extended SubscriptionSummary with optional Plan field; added new SubscriptionPlanSummary type with plan id/title/quota-reset; introduced SelectPrimarySubscriptionSummary to deterministically choose primary subscription by consumption status and stable ordering; updated buildSubscriptionSummaries to batch-fetch and attach plan data.
Subscription Controller & Tests
controller/subscription.go, controller/subscription_self_test.go
Updated GetSubscriptionSelf to compute and include primary_subscription via SelectPrimarySubscriptionSummary; added active_subscription_count field to response. Tests verify primary subscription selection with plan details and multiple subscription handling.
Recharge Access Control Guard
controller/topup_access.go, controller/topup_access_test.go
Added new ensureRechargeAllowed function that checks User.AllowRecharge, emitting error message when false; guards validate user exists and permission is enabled. Tests verify allow/deny behavior for authenticated users.
Top-up Endpoint Guards
controller/topup.go, controller/topup_creem.go, controller/topup_stripe.go, controller/topup_waffo.go
Added ensureRechargeAllowed precondition checks to GetTopUpInfo, RequestEpay, RequestAmount, RequestCreemPay, RequestStripeAmount, RequestStripePay, and RequestWaffoPay; guards execute before request parsing/validation.
Frontend - User Management
web/src/components/table/users/modals/AddUserModal.jsx, web/src/components/table/users/modals/EditUserModal.jsx
Added allow_recharge form field (toggle switch, default true) to both user creation and editing modals; toggling impacts wallet management access. Form includes localized labels and explanatory text.
Frontend - Navigation Access Control
web/src/components/layout/SiderBar.jsx, web/src/components/layout/headerbar/UserArea.jsx
Updated menu/dropdown entries to conditionally show top-up navigation via canAccessWalletManagement helper; entries hidden when user has allow_recharge: false. Dependencies updated to reflect user state changes.
Frontend - Top-up Components
web/src/components/topup/RechargeCard.jsx, web/src/components/topup/index.jsx
Added walletAccessAllowed prop to RechargeCard to conditionally render warning banner when access denied; updated index.jsx to derive walletAccessAllowed from user state and conditionally fetch top-up configuration, resetting state when access is revoked. Dependency array updated.
Frontend - Dashboard Subscription Display
web/src/components/dashboard/DashboardSubscriptionSummary.jsx, web/src/components/dashboard/DashboardHeader.jsx, web/src/components/dashboard/index.jsx
Added new DashboardSubscriptionSummary component rendering clickable popover with active subscription badges, used/total amounts, reset times, and progress bars. Updated DashboardHeader to include component in layout; updated index.jsx to fetch subscription summary concurrently with quota data and pass to header.
Frontend - Subscription & Access Helpers
web/src/helpers/dashboardSubscriptionSummary.js, web/src/helpers/dashboardSubscriptionSummary.test.js, web/src/helpers/rechargeAccess.js, web/src/helpers/rechargeAccess.test.js
Added helpers for formatting subscription amounts/reset times, building view-models and trigger text from subscription payloads, computing progress display; added canAccessWalletManagement and isRechargeRestricted access predicates. Comprehensive test coverage for all helpers.
Dashboard Hook
web/src/hooks/dashboard/useDashboardData.js
Added dashboardSubscriptionSummary state and loadDashboardSubscriptionSummary callback to fetch subscription data from /api/subscription/self and transform into dashboard display format. Updated refresh to load subscription summary concurrently with quota data.
Dependencies
go.mod
Added indirect dependency github.com/DATA-DOG/go-sqlmock v1.5.2 for testing with mocked database queries.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • Calcium-Ion
  • seefs001
  • creamlike1024

🐰 A guard hops forth with a bouncy check,
"Allow recharge?" it asks with a peck!
Plan titles gleam in dashboard light,
Primary subscriptions sorted just right, 💳✨
Users manage their wallets with newfound delight!

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@BoJun9527
Copy link
Copy Markdown
Author

Closing per request. Keeping the pushed git branch only.

@BoJun9527 BoJun9527 closed this Apr 14, 2026
@BoJun9527 BoJun9527 deleted the codex/recharge-controls-dashboard-summary branch April 14, 2026 19:23
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