Loading...
Loading...
> Shows the user's current AI credit balance with a progress bar indicating usage against monthly allowance. Color-coded to show remaining capacity.
1import { BalanceDisplay } from "@/components/credits"
1<BalanceDisplay />
1<BalanceDisplay compact />
1// Automatically shows warning when balance < 50%
1// Automatically shows critical when balance < 20%
1// Tier displayed automatically from user's subscription
| Prop | Type | Default | Description |
|---|---|---|---|
| className | string | - | Additional CSS classes to apply. |
| compact | boolean | false | Show minimal display with just the credit count. |
Add to user dashboard to show current credit balance. Automatically fetches from /api/credits/balance.
1'use client';23import { BalanceDisplay } from '@/components/credits';45export default function DashboardPage() {6 return (7 <div className="space-y-6">8 <h1>Dashboard</h1>910 {/* Auto-fetches balance, tier, and allowance */}11 <BalanceDisplay />1213 {/* Compact mode for sidebars/headers */}14 <BalanceDisplay compact />15 </div>16 );17}
The component expects GET /api/credits/balance to return this format:
1// GET /api/credits/balance response2{3 "balance": 750,4 "monthlyAllowance": 1000,5 "tier": "starter",6 "lastRefill": "2024-12-01T00:00:00.000Z"7}89// Already implemented at:10// src/app/api/credits/balance/route.ts
Progress bar automatically changes color based on remaining credits:
1// Green (bg-primary): > 50% remaining2// Yellow (bg-warning): 20-50% remaining3// Red (bg-destructive): < 20% remaining45// Example: 750/1000 = 75% = Green6// Example: 350/1000 = 35% = Yellow7// Example: 150/1000 = 15% = Red