import { useEffect, useState } from "react"; import { api, type CurrentUser, type DomainList, type DomainRecord } from "../api/client"; import { downloadCsv } from "../utils/csv"; import { formatDateTime } from "../utils/date"; import { formatAgo } from "../utils/duration"; import { readableError } from "../utils/errors"; import { useSortable } from "../hooks/useSortable"; import { usePagination } from "../hooks/usePagination"; import SortableTh from "../components/SortableTh"; import Pagination from "../components/Pagination"; import { confirmDialog } from "../utils/dialogs"; import { ErrorNotice } from "../components/Notice"; import { SearchBox } from "../components/TableToolbar"; import { useTableSearch } from "../hooks/useTableSearch"; import { EmptyRow } from "../components/EmptyState"; function statusBadge(d: DomainRecord) { switch (d.status) { case "expired": return Expired {Math.abs(d.daysLeft ?? 0)} d ago; case "expiring": return {d.daysLeft} d left; case "ok": return {d.daysLeft} d left; default: return Unknown; } } /** When each domain registration expires — the "Domain names" side of the DNS page. */ export default function DomainsView({ user }: { user: CurrentUser }) { const canEdit = user.role === "admin" || user.role === "operator"; const [data, setData] = useState(null); const [error, setError] = useState(null); const [notice, setNotice] = useState(null); const [name, setName] = useState(""); const [adding, setAdding] = useState(false); const [refreshingAll, setRefreshingAll] = useState(false); const [checkingId, setCheckingId] = useState(null); useEffect(() => { api.domains .list() .then(setData) .catch((err) => setError(readableError(err))); }, []); const tableSearch = useTableSearch(data?.domains); const { sorted, sortKey, sortDir, requestSort } = useSortable(tableSearch.filtered, "expiresAt", "asc", { url: true }); const { pageItems, page, setPage, pageCount, totalCount } = usePagination(sorted); async function add(e: React.FormEvent) { e.preventDefault(); setError(null); setNotice(null); setAdding(true); try { const res = await api.domains.add(name.trim()); setName(""); if (res.resolvedFrom) setNotice(`${res.resolvedFrom} is part of ${res.domain.name}, so that's the registration being tracked.`); setData(await api.domains.list()); } catch (err) { setError(readableError(err)); } finally { setAdding(false); } } async function refreshAll() { setError(null); setNotice(null); setRefreshingAll(true); try { setData(await api.domains.refresh()); } catch (err) { setError(readableError(err)); } finally { setRefreshingAll(false); } } async function check(d: DomainRecord) { setError(null); setNotice(null); setCheckingId(d.id); try { await api.domains.check(d.id); setData(await api.domains.list()); } catch (err) { setError(readableError(err)); } finally { setCheckingId(null); } } async function remove(d: DomainRecord) { if (!(await confirmDialog({ title: "Stop tracking domain", message: `Stop tracking ${d.name}?`, confirmLabel: "Stop tracking", danger: true }))) return; setError(null); try { await api.domains.remove(d.id); setData(await api.domains.list()); } catch (err) { setError(readableError(err)); } } function exportCsv() { if (!sorted) return; downloadCsv( "domains.csv", ["Domain", "Expires", "Days left", "Registrar", "Source", "Origin", "Last checked", "Problem"], sorted.map((d) => [ d.name, d.expiresAt ?? "", d.daysLeft ?? "", d.registrar ?? "", d.lookupSource ?? "", d.origin === "zone" ? "DNS zone" : "manual", d.lastCheckedAt ? formatDateTime(new Date(d.lastCheckedAt)) : "", d.lastCheckError ?? "", ]), ); } return ( <>

Domain names

{canEdit && ( )}
When each domain registration expires, read from the registry itself. Domains for the DNS zones you've added show up here automatically; add any others by hand.
{notice &&
{notice}
} {canEdit && (
setName(e.target.value)} />
)}

Registrations

label="Domain" sortKeyName="name" activeKey={sortKey} direction={sortDir} onSort={requestSort} /> label="Expires" sortKeyName="expiresAt" activeKey={sortKey} direction={sortDir} onSort={requestSort} /> label="Registrar" sortKeyName="registrar" activeKey={sortKey} direction={sortDir} onSort={requestSort} /> label="Last checked" sortKeyName="lastCheckedAt" activeKey={sortKey} direction={sortDir} onSort={requestSort} /> {canEdit && } {pageItems?.map((d) => ( {canEdit && ( )} ))} {data && data.domains.length === 0 && ( )}
Actions
{d.name} {d.origin === "zone" ? "DNS zone" : "Manual"} {d.expiresAt ? ( <> {statusBadge(d)} {d.expiresAt} ) : ( — )} {d.registrar ?? "—"} {d.lookupSource && · {d.lookupSource.toUpperCase()}} {d.lastCheckedAt ? ( {formatAgo(d.lastCheckedAt)} ) : ( not yet )} {d.lastCheckError &&
{d.lastCheckError}
}
{d.origin === "manual" && ( )}
{data && (
Expiry is read daily from the registry — over RDAP where the TLD offers it, otherwise from its WHOIS server (.se and .nu, for example). You're reminded every day from {data.warnDays} days before a domain expires until it's renewed. A registry that doesn't publish expiry dates (.de, .eu) can be tracked but has no date to warn about.
)} ); }