import { useState, type Dispatch, type ReactNode, type SetStateAction } from "react"; import { X } from "lucide-react"; import Modal from "@/src/components/twui/elements/Modal"; import Input from "@/src/components/twui/form/Input"; import AdminButton from "@/src/components/general/admin-button"; import Form from "@/src/components/twui/form/Form"; import Stack from "@/src/components/twui/layout/Stack"; import Span from "@/src/components/twui/layout/Span"; import H3 from "@/src/components/twui/layout/H3"; import Row from "@/src/components/twui/layout/Row"; import adminCrudHandler from "@/src/functions/frontend/admin-crud-handler"; import type { BUN_SQLITE_WGUI_CLIENTS } from "@/db/types/db"; type Props = { open: boolean; setOpen: Dispatch>; onCreated?: () => void; }; type FormFieldProps = { label: string; htmlFor: string; children: ReactNode; }; type FormData = { client_name?: string; tunnel_ip?: string; allowed_ips?: string; }; export default function ClientFormModal({ open, setOpen, onCreated }: Props) { const [busy, setBusy] = useState(false); const [error, setError] = useState(); async function handleSubmit(data: FormData) { setBusy(true); setError(undefined); const res = await adminCrudHandler({ action: "insert", table: "clients", insert_data: [ { name: data.client_name || "", wg_ip_address: data.tunnel_ip || "", allowed_ips: data.allowed_ips || "", }, ], }); setBusy(false); if (!res.success) { setError(res.msg || "Could not add client"); return; } setOpen(false); onCreated?.(); } return (

Add client

The client is added to your WireGuard network
{ handleSubmit(data as FormData); }} > {error ? ( {error} ) : null} setOpen(false)} disabled={busy}> Cancel {busy ? "Adding…" : "Add client"}
); }