'use client' import { useState } from 'react' import { useRouter } from 'next/navigation' export type SiteWithZones = { id: string name: string address: string | null zones: Array<{ id: string; name: string; qr_code_token: string }> } interface Props { sites: SiteWithZones[] } export function SiteZoneManager({ sites }: Props) { const router = useRouter() const [siteName, setSiteName] = useState('') const [zoneName, setZoneName] = useState('') const [zoneSiteId, setZoneSiteId] = useState('') const [busy, setBusy] = useState(false) const [error, setError] = useState(null) const post = async (payload: Record) => { setBusy(true) setError(null) const res = await fetch('/ims/api/admin/sites', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload), }) setBusy(false) if (!res.ok) { const data = await res.json().catch(() => ({})) setError(data.error ?? 'Save failed') return false } router.refresh() return true } return (

Sites & Zones

setSiteName(e.target.value)} className="border border-gray-300 rounded-lg px-3 py-2 text-sm w-48" />
setZoneName(e.target.value)} className="border border-gray-300 rounded-lg px-3 py-2 text-sm w-48" />
{error &&

{error}

}
{sites.map(site => (

{site.name}

{site.address &&

{site.address}

} {site.zones.length > 0 ? ( ) : (

No zones

)}
))} {sites.length === 0 &&

No sites yet

}
) }