// client/src/features/machines/AddMachineModal.tsx import { useState } from "react"; import { api } from "../../lib/api.js"; interface Props { onClose: () => void; onCreated: () => void; } export function AddMachineModal({ onClose, onCreated }: Props) { const [form, setForm] = useState({ name: "", hostname: "", port: 22, username: "", password: "", sudoPassword: "" }); const [error, setError] = useState(null); const [busy, setBusy] = useState(false); const set = (k: string, v: string | number) => setForm({ ...form, [k]: v }); async function submit() { setBusy(true); setError(null); try { await api.createMachine({ ...form, port: Number(form.port), sudoPassword: form.sudoPassword || null }); onCreated(); onClose(); } catch (e) { setError((e as Error).message); } finally { setBusy(false); } } return (
AJOUTER UNE MACHINE
{(["name", "hostname", "username"] as const).map((k) => ( set(k, e.target.value)} /> ))} set("port", e.target.value)} /> set("password", e.target.value)} /> set("sudoPassword", e.target.value)} /> {error &&
{error}
}
); }