import { useState } from "react"; import { Pencil, Trash2 } from "lucide-react"; import Link from "@/src/components/twui/layout/Link"; import Row from "@/src/components/twui/layout/Row"; import Span from "@/src/components/twui/layout/Span"; import formatUnixTimestamp from "@/src/utils/format-unix-timestamp"; import adminCrudHandler from "@/src/functions/frontend/admin-crud-handler"; import type { BUN_SQLITE_WGUI_CLIENTS, BUN_SQLITE_WGUI_CLIENT_RULES, } from "@/db/types/db"; import deriveClientAccessLabel from "@/src/functions/frontend/derive-client-access-label"; type Props = { client: BUN_SQLITE_WGUI_CLIENTS; rules?: BUN_SQLITE_WGUI_CLIENT_RULES[]; }; export default function ClientRow({ client, rules }: Props) { const [deleting, setDeleting] = useState(false); const host_id = Number(client.host_id || 0); const access = deriveClientAccessLabel({ rules }); async function handleDelete() { if ( !window.confirm( `Delete client "${client?.name || `#${client?.id}`}"? The client will be removed from the host and its config file deleted.`, ) ) { return; } setDeleting(true); const res = await adminCrudHandler({ action: "delete", table: "clients", id: client?.id, }); if (!res.success) { setDeleting(false); window.alert(res.msg || "Could not delete client"); return; } window.location.reload(); } return ( {client.name || "—"} {typeof host_id == "number" ? ( {host_id == 0 ? "Main" : `Host #${host_id}`} ) : ( — )} {client.wg_ip_address || "—"} {client.allowed_ips || "—"} {access.text} {client.public_key ? `${client.public_key.slice(0, 16)}…` : "—"} {formatUnixTimestamp({ timestamp: client.created_at })} ); }