diff --git a/src/components/AddHostModal.tsx b/src/components/AddHostModal.tsx new file mode 100644 index 0000000..5c5214b --- /dev/null +++ b/src/components/AddHostModal.tsx @@ -0,0 +1,81 @@ +import { useState } from "react"; +import { api } from "../api"; + +interface Props { + onClose: () => void; + onAdded: () => void; +} + +export function AddHostModal({ onClose, onAdded }: Props) { + const [name, setName] = useState(""); + const [ip, setIp] = useState(""); + const [port, setPort] = useState("47984"); + const [error, setError] = useState(null); + const [saving, setSaving] = useState(false); + + async function handleSubmit(e: React.FormEvent) { + e.preventDefault(); + setSaving(true); + setError(null); + try { + await api.addManualHost(name, ip, parseInt(port, 10) || 47984); + onAdded(); + onClose(); + } catch (err: unknown) { + setError(err instanceof Error ? err.message : "Failed to add host"); + } finally { + setSaving(false); + } + } + + return ( +
+
e.stopPropagation()} + > +

Add Host Manually

+
+ setName(e.target.value)} + required + /> + setIp(e.target.value)} + required + /> + setPort(e.target.value)} + type="number" + /> + {error &&

{error}

} +
+ + +
+
+
+
+ ); +}