import { useState } from "react"; import { HardDrive, Loader2 } from "lucide-react"; import { useCreateAmiMutation } from "@/api/aws/ec2.mutations"; interface Props { instanceId: string; instanceName: string; onClose: () => void; onCreated: () => void; } export function CreateAmiModal({ instanceId, instanceName, onClose, onCreated }: Props) { const [name, setName] = useState(`${instanceName}-ami`); const [description, setDescription] = useState(""); const [noReboot, setNoReboot] = useState(false); const [err, setErr] = useState(""); const mutation = useCreateAmiMutation(); function handleSubmit() { if (!name.trim()) { setErr("Name is required."); return; } setErr(""); mutation.mutate( { instanceId, input: { name: name.trim(), description: description || undefined, noReboot } }, { onSuccess: () => { onCreated(); onClose(); }, onError: (e) => setErr(e instanceof Error ? e.message : "AMI creation failed."), }, ); } return (
{ if (e.target === e.currentTarget) onClose(); }}>

Create AMI

Image name

setName(e.target.value)} onKeyDown={(e) => e.key === "Escape" && onClose()} />

Description — optional

setDescription(e.target.value)} />

No reboot — skip instance restart before imaging

{err &&

{err}

}
); }