Settings down to eight tabs; Domains become a tab of DNS
Notifications gains Alert tickets, Display gains Badge colours, and a new Data tab holds Backup, Logs and Cache. Domains is the 'Domain names' tab of DNS. Old addresses redirect; the docs, the Privacy page and the links from alerts and the agenda name the new places. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1432b148e9
commit
ddd0aa622a
23 files changed
+153
-65
No files matched your search
@@ -0,0 +1,249 @@
|
||||
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 <span className="badge bg-red-lt text-red">Expired {Math.abs(d.daysLeft ?? 0)} d ago</span>;
|
||||
case "expiring":
|
||||
return <span className="badge bg-yellow-lt text-yellow">{d.daysLeft} d left</span>;
|
||||
case "ok":
|
||||
return <span className="badge bg-green-lt text-green">{d.daysLeft} d left</span>;
|
||||
default:
|
||||
return <span className="badge bg-secondary-lt text-secondary">Unknown</span>;
|
||||
}
|
||||
}
|
||||
|
||||
/** 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<DomainList | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [notice, setNotice] = useState<string | null>(null);
|
||||
const [name, setName] = useState("");
|
||||
const [adding, setAdding] = useState(false);
|
||||
const [refreshingAll, setRefreshingAll] = useState(false);
|
||||
const [checkingId, setCheckingId] = useState<number | null>(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 (
|
||||
<>
|
||||
<div className="d-flex align-items-center mb-3">
|
||||
<h3 className="mb-0">Domain names</h3>
|
||||
{canEdit && (
|
||||
<button className="btn btn-outline-secondary ms-auto" onClick={refreshAll} disabled={refreshingAll}>
|
||||
{refreshingAll ? "Checking…" : "Check all now"}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
<div className="text-secondary mb-3">
|
||||
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.
|
||||
</div>
|
||||
<ErrorNotice error={error} />
|
||||
{notice && <div className="alert alert-info">{notice}</div>}
|
||||
|
||||
{canEdit && (
|
||||
<form onSubmit={add} className="card mb-3">
|
||||
<div className="card-body row g-2 align-items-end">
|
||||
<div className="col-md-6">
|
||||
<label className="form-label">Track another domain</label>
|
||||
<input
|
||||
className="form-control"
|
||||
required
|
||||
placeholder="e.g. example.se"
|
||||
value={name}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div className="col-md-3">
|
||||
<button type="submit" className="btn btn-primary" disabled={adding || !name.trim()}>
|
||||
{adding ? "Looking it up…" : "Add domain"}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
)}
|
||||
|
||||
<div className="card mb-3">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">Registrations</h3>
|
||||
<SearchBox value={tableSearch.query} onChange={tableSearch.setQuery} className="ms-3" />
|
||||
<div className="card-actions">
|
||||
<button className="btn btn-sm btn-outline-secondary" onClick={exportCsv} disabled={!sorted || sorted.length === 0}>
|
||||
Export CSV
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="table-responsive">
|
||||
<table className="table table-vcenter card-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<SortableTh<DomainRecord> label="Domain" sortKeyName="name" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
|
||||
<SortableTh<DomainRecord> label="Expires" sortKeyName="expiresAt" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
|
||||
<SortableTh<DomainRecord> label="Registrar" sortKeyName="registrar" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
|
||||
<SortableTh<DomainRecord> label="Last checked" sortKeyName="lastCheckedAt" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
|
||||
{canEdit && <th className="w-1">Actions</th>}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{pageItems?.map((d) => (
|
||||
<tr key={d.id}>
|
||||
<td>
|
||||
{d.name}
|
||||
<span className="badge bg-secondary-lt text-secondary ms-2">{d.origin === "zone" ? "DNS zone" : "Manual"}</span>
|
||||
</td>
|
||||
<td>
|
||||
{d.expiresAt ? (
|
||||
<>
|
||||
{statusBadge(d)} <span className="text-secondary small ms-1">{d.expiresAt}</span>
|
||||
</>
|
||||
) : (
|
||||
<span className="text-secondary">—</span>
|
||||
)}
|
||||
</td>
|
||||
<td className="text-secondary">
|
||||
{d.registrar ?? "—"}
|
||||
{d.lookupSource && <span className="small ms-1">· {d.lookupSource.toUpperCase()}</span>}
|
||||
</td>
|
||||
<td>
|
||||
{d.lastCheckedAt ? (
|
||||
<span className="text-secondary" title={formatDateTime(new Date(d.lastCheckedAt))}>
|
||||
{formatAgo(d.lastCheckedAt)}
|
||||
</span>
|
||||
) : (
|
||||
<span className="text-secondary">not yet</span>
|
||||
)}
|
||||
{d.lastCheckError && <div className={`small ${d.expiresAt ? "text-warning" : "text-secondary"}`}>{d.lastCheckError}</div>}
|
||||
</td>
|
||||
{canEdit && (
|
||||
<td>
|
||||
<div className="btn-list flex-nowrap">
|
||||
<button className="btn btn-sm btn-outline-secondary" onClick={() => check(d)} disabled={checkingId === d.id}>
|
||||
{checkingId === d.id ? "Checking…" : "Check now"}
|
||||
</button>
|
||||
{d.origin === "manual" && (
|
||||
<button className="btn btn-sm btn-outline-danger" onClick={() => remove(d)}>
|
||||
Remove
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</td>
|
||||
)}
|
||||
</tr>
|
||||
))}
|
||||
{data && data.domains.length === 0 && (
|
||||
<EmptyRow colSpan={canEdit ? 5 : 4} title="No domains tracked yet" hint={canEdit ? "Domains for your DNS zones appear after the next daily check, or when you press “Check all now”. You can also add one by hand above." : "Domains for your DNS zones appear after the next daily check."} />
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<Pagination page={page} pageCount={pageCount} totalCount={totalCount} onPageChange={setPage} />
|
||||
</div>
|
||||
|
||||
{data && (
|
||||
<div className="text-secondary small">
|
||||
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.
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user