Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 | "use client";
import { fetchApi } from "@/lib/api";
import { useCallback, useEffect, useState } from "react";
import PageIntro from "@/components/PageIntro";
import { Globe, Loader2, Plus, RefreshCw, Trash2, Wallet } from "lucide-react";
interface Participant {
participantId: string;
name: string | null;
participantType: string | null;
source: string | null;
walletType: string | null;
country: string | null;
dspCatalogUrl: string | null;
crawlerEnabled: boolean | null;
onboardedAt: string | null;
datasetCount: number;
}
interface DirectoryResponse {
participants: Participant[];
summary: {
total: number;
crawlable: number;
bySource: Record<string, number>;
};
}
const SOURCE_BADGE: Record<string, string> = {
seed: "bg-blue-900/40 text-blue-300 border-blue-700",
dcp: "bg-purple-900/40 text-purple-300 border-purple-700",
"business-wallet": "bg-emerald-900/40 text-emerald-300 border-emerald-700",
"private-wallet": "bg-amber-900/40 text-amber-300 border-amber-700",
};
const EMPTY_FORM = {
participantId: "",
name: "",
participantType: "DATA_HOLDER",
walletType: "business",
source: "business-wallet",
country: "",
dspCatalogUrl: "",
};
export default function ParticipantsAdminPage() {
const [data, setData] = useState<DirectoryResponse | null>(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const [form, setForm] = useState(EMPTY_FORM);
const [saving, setSaving] = useState(false);
const [notice, setNotice] = useState<string | null>(null);
const load = useCallback(async () => {
setLoading(true);
setError(null);
try {
const res = await fetchApi("/api/admin/participants");
if (!res.ok) throw new Error(`HTTP ${res.status}`);
setData(await res.json());
} catch (err) {
setError(
err instanceof Error ? err.message : "Failed to load participants",
);
} finally {
setLoading(false);
}
}, []);
useEffect(() => {
load();
}, [load]);
async function addParticipant(e: React.FormEvent) {
e.preventDefault();
setSaving(true);
setNotice(null);
try {
const res = await fetchApi("/api/admin/participants", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(form),
});
const body = await res.json().catch(() => ({}));
if (!res.ok) {
setNotice(body.error ?? `HTTP ${res.status}`);
} else {
setNotice(`Added ${form.participantId}`);
setForm(EMPTY_FORM);
await load();
}
} finally {
setSaving(false);
}
}
async function removeParticipant(participantId: string) {
setNotice(null);
const res = await fetchApi(
`/api/admin/participants?id=${encodeURIComponent(participantId)}`,
{ method: "DELETE" },
);
const body = await res.json().catch(() => ({}));
if (!res.ok) {
setNotice(body.error ?? `HTTP ${res.status}`);
} else {
setNotice(`Removed ${participantId}`);
await load();
}
}
return (
<div className="min-h-screen bg-[var(--bg)]">
<div className="max-w-6xl mx-auto px-6 py-10">
<PageIntro
title="Participant Directory"
icon={Globe}
description="Wallets and participants the catalog crawler discovers datasets from. Adding a participant here makes their DSP catalog a crawl target on the next 5-minute tick — no restart required."
infoText="source shows how the participant entered the directory: seed (demo bootstrap), dcp (trust-anchor discovery), business-wallet / private-wallet (manual onboarding). Only entries with a DSP catalog URL and crawling enabled are fetched."
/>
{notice && (
<div
role="status"
className="mb-4 rounded border border-[var(--border)] bg-[var(--surface-2)] px-4 py-2 text-sm text-[var(--text-primary)]"
>
{notice}
</div>
)}
{/* Summary row */}
{data && (
<div
className="mb-6 flex flex-wrap gap-4 text-sm text-[var(--text-secondary)]"
data-testid="participants-summary"
>
<span>{data.summary.total} participants</span>
<span>·</span>
<span>{data.summary.crawlable} crawlable</span>
{Object.entries(data.summary.bySource).map(([s, n]) => (
<span key={s} className="flex items-center gap-1">
· {s}: {n}
</span>
))}
<button
onClick={load}
aria-label="Refresh participants"
className="ml-auto flex items-center gap-1 text-[var(--accent)] hover:underline"
>
<RefreshCw size={14} /> Refresh
</button>
</div>
)}
{loading && (
<div className="flex items-center gap-2 py-8 text-[var(--text-secondary)]">
<Loader2 size={16} className="animate-spin" /> Loading participant
directory…
</div>
)}
{error && !loading && (
<div className="rounded border border-red-700 bg-red-900/30 px-4 py-3 text-sm text-red-300">
{error}
</div>
)}
{/* Directory table */}
{data && !loading && (
<div className="overflow-x-auto rounded-lg border border-[var(--border)]">
<table className="w-full text-sm" data-testid="participants-table">
<thead>
<tr className="border-b border-[var(--border)] bg-[var(--surface-2)] text-left text-[var(--text-secondary)]">
<th className="px-4 py-3 font-medium">Participant</th>
<th className="px-4 py-3 font-medium">Source</th>
<th className="px-4 py-3 font-medium">Wallet</th>
<th className="px-4 py-3 font-medium">Country</th>
<th className="px-4 py-3 font-medium">Datasets</th>
<th className="px-4 py-3 font-medium">DSP Catalog</th>
<th className="px-4 py-3 font-medium sr-only">Actions</th>
</tr>
</thead>
<tbody>
{data.participants.map((p) => (
<tr
key={p.participantId}
className="border-b border-[var(--border)] last:border-0"
>
<td className="px-4 py-3">
<div className="font-medium text-[var(--text-primary)]">
{p.name ?? "—"}
</div>
<div className="font-mono text-xs text-[var(--text-secondary)]">
{p.participantId}
</div>
</td>
<td className="px-4 py-3">
<span
className={`inline-block rounded border px-2 py-0.5 text-xs ${
SOURCE_BADGE[p.source ?? ""] ??
"bg-gray-800 text-gray-300 border-gray-600"
}`}
>
{p.source ?? "unknown"}
</span>
</td>
<td className="px-4 py-3 text-[var(--text-secondary)]">
<span className="flex items-center gap-1">
<Wallet size={13} /> {p.walletType ?? "—"}
</span>
</td>
<td className="px-4 py-3 text-[var(--text-secondary)]">
{p.country ?? "—"}
</td>
<td className="px-4 py-3 text-[var(--text-secondary)]">
{p.datasetCount}
</td>
<td className="px-4 py-3">
{p.dspCatalogUrl ? (
<span
className={`font-mono text-xs ${
p.crawlerEnabled
? "text-[var(--text-secondary)]"
: "text-[var(--text-secondary)] line-through"
}`}
title={
p.crawlerEnabled
? "Crawled every 5 minutes"
: "Crawling disabled"
}
>
{p.dspCatalogUrl}
</span>
) : (
<span className="text-xs text-[var(--text-secondary)]">
not crawlable
</span>
)}
</td>
<td className="px-4 py-3 text-right">
{p.source !== "seed" && (
<button
onClick={() => removeParticipant(p.participantId)}
aria-label={`Remove ${p.name ?? p.participantId}`}
className="text-red-400 hover:text-red-300"
>
<Trash2 size={15} />
</button>
)}
</td>
</tr>
))}
</tbody>
</table>
</div>
)}
{/* Onboard form */}
<form
onSubmit={addParticipant}
className="mt-8 rounded-lg border border-[var(--border)] bg-[var(--surface-2)] p-6"
data-testid="participant-form"
>
<h2 className="mb-4 flex items-center gap-2 text-lg font-semibold text-[var(--text-primary)]">
<Plus size={18} /> Onboard participant wallet
</h2>
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3">
<label className="text-sm text-[var(--text-secondary)]">
Participant DID *
<input
required
value={form.participantId}
onChange={(e) =>
setForm({ ...form, participantId: e.target.value })
}
placeholder="did:web:clinic.example:participant"
className="mt-1 w-full rounded border border-[var(--border)] bg-[var(--bg)] px-3 py-2 font-mono text-xs text-[var(--text-primary)]"
/>
</label>
<label className="text-sm text-[var(--text-secondary)]">
Display name *
<input
required
value={form.name}
onChange={(e) => setForm({ ...form, name: e.target.value })}
placeholder="Fictional Clinic GmbH"
className="mt-1 w-full rounded border border-[var(--border)] bg-[var(--bg)] px-3 py-2 text-[var(--text-primary)]"
/>
</label>
<label className="text-sm text-[var(--text-secondary)]">
Participant type
<select
value={form.participantType}
onChange={(e) =>
setForm({ ...form, participantType: e.target.value })
}
className="mt-1 w-full rounded border border-[var(--border)] bg-[var(--bg)] px-3 py-2 text-[var(--text-primary)]"
>
<option>DATA_HOLDER</option>
<option>DATA_USER</option>
<option>HDAB</option>
</select>
</label>
<label className="text-sm text-[var(--text-secondary)]">
Wallet type
<select
value={form.walletType}
onChange={(e) =>
setForm({ ...form, walletType: e.target.value })
}
className="mt-1 w-full rounded border border-[var(--border)] bg-[var(--bg)] px-3 py-2 text-[var(--text-primary)]"
>
<option value="business">business</option>
<option value="private">private</option>
</select>
</label>
<label className="text-sm text-[var(--text-secondary)]">
Country (ISO-2)
<input
value={form.country}
onChange={(e) => setForm({ ...form, country: e.target.value })}
placeholder="DE"
maxLength={2}
className="mt-1 w-full rounded border border-[var(--border)] bg-[var(--bg)] px-3 py-2 text-[var(--text-primary)]"
/>
</label>
<label className="text-sm text-[var(--text-secondary)]">
DSP catalog URL
<input
value={form.dspCatalogUrl}
onChange={(e) =>
setForm({ ...form, dspCatalogUrl: e.target.value })
}
placeholder="https://clinic.example/api/dsp/catalog"
className="mt-1 w-full rounded border border-[var(--border)] bg-[var(--bg)] px-3 py-2 font-mono text-xs text-[var(--text-primary)]"
/>
</label>
</div>
<button
type="submit"
disabled={saving}
className="mt-4 flex items-center gap-2 rounded-lg bg-[var(--accent)] px-4 py-2 font-medium text-white transition-colors hover:bg-[var(--accent-hover)] disabled:opacity-50 dark:text-gray-900"
>
{saving ? (
<Loader2 size={15} className="animate-spin" />
) : (
<Plus size={15} />
)}
Add to directory
</button>
</form>
</div>
</div>
);
}
|