52 lines
1.7 KiB
TypeScript
52 lines
1.7 KiB
TypeScript
'use client'
|
|
|
|
import { useState } from 'react'
|
|
import { UserManager, type AdminUser, type SiteOption } from './user-manager'
|
|
import { SiteZoneManager, type SiteWithZones } from './site-zone-manager'
|
|
import { TruckManager, type Truck } from './truck-manager'
|
|
|
|
type Tab = 'users' | 'sites' | 'trucks'
|
|
|
|
interface Props {
|
|
users: AdminUser[]
|
|
sites: SiteWithZones[]
|
|
siteOptions: SiteOption[]
|
|
trucks: Truck[]
|
|
}
|
|
|
|
export function AdminPanel({ users, sites, siteOptions, trucks }: Props) {
|
|
const [tab, setTab] = useState<Tab>('users')
|
|
|
|
const tabs: { id: Tab; label: string; count: number }[] = [
|
|
{ id: 'users', label: 'Users', count: users.length },
|
|
{ id: 'sites', label: 'Sites & Zones', count: sites.length },
|
|
{ id: 'trucks', label: 'Trucks', count: trucks.length },
|
|
]
|
|
|
|
return (
|
|
<div>
|
|
<div className="flex gap-1 border-b border-divider mb-6">
|
|
{tabs.map(t => (
|
|
<button
|
|
key={t.id}
|
|
onClick={() => setTab(t.id)}
|
|
className={`px-4 py-2.5 text-sm font-medium border-b -mb-px transition-colors cursor-pointer ${
|
|
tab === t.id
|
|
? 'border-accent text-ink'
|
|
: 'border-transparent text-gray-500 hover:text-gray-700'
|
|
}`}
|
|
>
|
|
{t.label}
|
|
<span className={`ml-1.5 text-xs px-1.5 py-0.5 ${
|
|
tab === t.id ? 'bg-neutral-100 text-ink' : 'bg-gray-100 text-gray-500'
|
|
}`}>{t.count}</span>
|
|
</button>
|
|
))}
|
|
</div>
|
|
{tab === 'users' && <UserManager users={users} sites={siteOptions} />}
|
|
{tab === 'sites' && <SiteZoneManager sites={sites} />}
|
|
{tab === 'trucks' && <TruckManager trucks={trucks} />}
|
|
</div>
|
|
)
|
|
}
|