'use client'; import { useState } from 'react'; import { StatusDot } from '@/components/ui/primitives'; import { adminFetch } from '@/lib/admin-fetch'; import { fmtInt, fmtPct } from '@/lib/format'; import { Time } from '@/lib/time'; import type { AdminProbe } from '@/lib/types'; import { AdminPage, ErrorNote, Field, Panel, Toast, btnCls, btnPrimary, inputCls, useAdmin } from './shared'; const EMPTY = { probe_id: '', name: '', region: 'na-east', country: 'CA', city: '', provider: '', asn: 0, lat: 0, lon: 0 }; export function Probes() { const { data, err, reload } = useAdmin<{ probes: AdminProbe[] }>('/probes'); const [form, setForm] = useState(null); const [key, setKey] = useState<{ probe_id: string; key: string } | null>(null); const [msg, setMsg] = useState(null); const [actErr, setActErr] = useState(null); const [busy, setBusy] = useState(false); const run = async (fn: () => Promise, ok: string) => { setBusy(true); setActErr(null); try { await fn(); setMsg(ok); reload(); } catch (e) { setActErr(String(e)); } finally { setBusy(false); setTimeout(() => setMsg(null), 3000); } }; return ( setForm({ ...EMPTY })}> + probe } > {key && (
{key.key}
)} {form && (
{ e.preventDefault(); void run(async () => { const res = await adminFetch('/probes', { method: 'POST', body: { ...form, asn: Number(form.asn), lat: Number(form.lat), lon: Number(form.lon) } }); setKey({ probe_id: res.probe_id, key: res.key }); setForm(null); }, 'Probe registered'); }} > {( [ ['probe_id', 'text'], ['name', 'text'], ['region', 'text'], ['country', 'text'], ['city', 'text'], ['provider', 'text'], ['asn', 'number'], ['lat', 'number'], ['lon', 'number'], ] as [keyof typeof EMPTY, string][] ).map(([k, type]) => ( setForm({ ...form, [k]: type === 'number' ? Number(e.target.value) : e.target.value })} className={`${inputCls} num w-full`} /> ))}
)}
{(data?.probes ?? []).map((p) => ( ))}
Probe Status Region Location Provider ASN Meas./h Uptime Version Last seen Enabled
{p.probe_id} {p.name} {p.region} {p.city}, {p.country} {p.lat}, {p.lon} {p.provider} {p.asn} {fmtInt(p.measurements_1h)} {fmtPct(p.uptime_24h, 1)} {p.version ?? '—'} {p.last_seen ?
); }