Settings billing now shows live AI credits and opens checkout
Settings → Billing & usage → AI credits is no longer a sample-data preview. The page reads the live firm credits payload through the generated Kubb hooks, shows balance and cycle usage, lists per-lawyer usage rows from the backend response, and lets a settings-write admin create a Stripe Checkout top-up order.
What changed
CreditsPage now calls
useAppGetFirmCredits(). Loading, load failure, zero
balance, and empty per-lawyer usage states are localized and
render without falling back to sample data.
The usage panel now renders the real
byLawyer rows. The current DTO exposes
userId and creditsUsed, so the UI shows
exactly those values instead of inventing lawyer names.
The disabled top-up card is live. It accepts a whole-credit
amount, calls useAppCreateCreditTopup() with
successUrl and cancelUrl, then redirects
the browser to the returned checkoutUrl.
On ?topup=success or ?topup=cancel, the
page refetches credits, cleans the query string, and shows a short
localized status message.
Removed preview scaffolding
- Removed the preview badge and the old "checkout launches once payments are live" copy.
-
Deleted
src/components/settings/billing/fixtures.ts. -
Removed the stale billing-local preview instructions and updated the
Page Card catalog reason for
settings.credits.
Where it lives
-
src/components/settings/billing/credits-page.tsx— live query, checkout mutation, return handling, localized states. -
src/components/agents/chat-credit-indicator.tsx— dormant pill now readsuseAppGetChatCredits()instead of the deleted fixture. -
messages/en.json+messages/hi.json— added all user-facing billing copy in both locales. -
src/components/settings/billing/credits-page.test.tsx— focused coverage for live rendering, top-up payload, and Stripe return refetch.
Verify
pnpm test src/components/settings/billing/credits-page.test.tsx pnpm lint pnpm typecheck pnpm build git diff --check git status --short # Hard rule: pnpm codegen was NOT run.
- Focused behavior verifies live balance / usage rendering, absence of preview copy, top-up request URLs, and return refetch.
-
Contract use imports existing generated
hooks and DTO types from
src/gen; no generated files changed.
Files changed
8 file(s), +512 / -210 lines
| Path | Role | + | - |
|---|---|---|---|
| messages/en.json | Config | +16 | -3 |
| messages/hi.json | Config | +16 | -3 |
| src/components/agents/chat-credit-indicator.tsx | Component | +7 | -7 |
| src/components/settings/billing/AGENTS.md | Component | +0 | -54 |
| src/components/settings/billing/credits-page.test.tsx | Component | +184 | -0 |
| src/components/settings/billing/credits-page.tsx | Component | +288 | -79 |
| src/components/settings/billing/fixtures.ts | Component | +0 | -63 |
| src/lib/surface-registry/page-card/catalog.ts | Library | +1 | -1 |