// client/src/features/machines/AddMachineModal.tsx import { useEffect, useState } from "react"; import type { AptProxyMode, MachineKind, OsFamily } from "@shared/types.js"; import type { DefaultAptProxy } from "../../lib/api.js"; import { api } from "../../lib/api.js"; interface Props { onClose: () => void; onCreated: () => void; } const OS_OPTIONS: { value: OsFamily; label: string }[] = [ { value: "debian", label: "Debian" }, { value: "ubuntu", label: "Ubuntu" }, { value: "proxmox", label: "Proxmox VE" }, { value: "raspbian", label: "Raspberry Pi OS" }, { value: "unknown", label: "Autre / auto" }, ]; const KIND_OPTIONS: { value: MachineKind; label: string }[] = [ { value: "vm", label: "VM" }, { value: "physical", label: "Physique" }, { value: "proxmox_host", label: "Hôte Proxmox" }, { value: "lxc", label: "LXC / conteneur" }, { value: "raspberry_pi", label: "Raspberry Pi" }, { value: "workstation", label: "Workstation / GPU" }, { value: "unknown", label: "Inconnu" }, ]; export function AddMachineModal({ onClose, onCreated }: Props) { const [form, setForm] = useState({ name: "", hostname: "", port: 22, username: "", password: "", sudoPassword: "", osFamily: "debian" as OsFamily, machineKind: "vm" as MachineKind, }); const [error, setError] = useState(null); const [busy, setBusy] = useState(false); const [proxyDefault, setProxyDefault] = useState(null); const [useProxy, setUseProxy] = useState(false); const set = (k: string, v: string | number) => setForm({ ...form, [k]: v }); useEffect(() => { void (async () => { try { const s = await api.getSettings(); if (s.defaultAptProxy.url) { setProxyDefault(s.defaultAptProxy); setUseProxy(true); } } catch { /* pas de défaut configuré */ } })(); }, []); async function submit() { setBusy(true); setError(null); try { const proxy = useProxy && proxyDefault?.url ? { aptProxyMode: proxyDefault.mode === "direct" ? "runtime" : proxyDefault.mode, aptProxyUrl: proxyDefault.url } : {}; await api.createMachine({ ...form, port: Number(form.port), sudoPassword: form.sudoPassword || null, ...proxy }); 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)} /> {proxyDefault?.url && ( )}
« Autre / auto » détecte l'OS via os-release. Détection complète (type, virt) ensuite via ⚙ Sonder.
{error &&
{error}
}
); }