import { useEffect, useState } from 'react' import { Link } from 'react-router-dom' import { ChevronLeft, RefreshCw } from 'lucide-react' import { api } from '../../api/client' interface BandwidthAccount { id: number username: string domain: string status: string bandwidthUsedMb: number package?: { name: string; bandwidthMb: number } } export default function BandwidthUsage() { const [items, setItems] = useState([]) const [loading, setLoading] = useState(false) const fetchData = async () => { setLoading(true) try { const r = await api.get('/nixserver/accounts/bandwidth') setItems(r.data.data) } finally { setLoading(false) } } useEffect(() => { fetchData() }, []) const statusColor: Record = { active: 'bg-emerald-500/10 text-emerald-400 border-emerald-500/20', suspended: 'bg-amber-500/10 text-amber-400 border-amber-500/20', terminated: 'bg-red-500/10 text-red-400 border-red-500/20', } return (
Accounts / View Bandwidth Usage

View Bandwidth Usage

{items.length} account{items.length !== 1 ? 's' : ''}, sorted by usage

{['Username', 'Domain', 'Bandwidth Used', 'Bandwidth Limit', '% Used', 'Status'].map(h => ( ))} {loading && ( )} {!loading && items.map(acc => { const limit = acc.package?.bandwidthMb ?? 0 const pct = limit > 0 ? Math.min(100, Math.round((acc.bandwidthUsedMb / limit) * 100)) : 0 const barColor = pct >= 90 ? 'bg-red-500' : pct >= 70 ? 'bg-amber-500' : 'bg-indigo-500' return ( ) })} {!loading && items.length === 0 && ( )}
{h}
Loading...
{acc.username} {acc.domain} {acc.bandwidthUsedMb.toLocaleString()} MB {limit > 0 ? `${limit.toLocaleString()} MB` : '—'} {limit > 0 ? (
{pct}%
) : ( No limit )}
{acc.status}
No accounts found
) }