"use client"; import Link from "next/link"; import { useEffect, useState } from "react"; import { useParams, useRouter } from "next/navigation"; import { formatUid } from "@/lib/rfid/uid"; type Site = { id: string; name: string; code: string; notes: string | null }; type Tag = { id: string; label: string; frequency: string; protocol: string; uid: string; updatedAt: string; }; export default function SitePage() { const { id } = useParams<{ id: string }>(); const router = useRouter(); const [site, setSite] = useState(null); const [tags, setTags] = useState([]); const [error, setError] = useState(null); useEffect(() => { async function load() { const [siteRes, tagsRes] = await Promise.all([ fetch(`/api/v1/sites/${id}`), fetch(`/api/v1/tags?siteId=${id}`), ]); if (siteRes.status === 401 || tagsRes.status === 401) { router.push("/login"); return; } if (!siteRes.ok) { setError("Site not found"); return; } setSite(await siteRes.json()); const tagData = await tagsRes.json(); setTags(tagData.tags); } load(); }, [id, router]); async function deleteSite() { if (!confirm("Delete this site and all its tags?")) return; const res = await fetch(`/api/v1/sites/${id}`, { method: "DELETE" }); if (!res.ok) { setError("Failed to delete site"); return; } router.push("/"); } if (error) return
{error}
; if (!site) return

Loading…

; return (
{site.code}

{site.name}

{site.notes &&

{site.notes}

}
Add tag
{tags.length === 0 ? (

No tags at this site yet.

) : ( tags.map((tag) => (
{tag.label}
{formatUid(tag.uid)} · {tag.protocol.replaceAll("_", " ")}
{tag.frequency} )) )}
); }