import React, { PropsWithChildren } from "react"; import { useNavigate } from "react-router-dom"; import { VMApi, VMInfo } from "../api/VMApi"; import { useSnackbar } from "../hooks/providers/SnackbarProvider"; import { VirtWebRouteContainer } from "../widgets/VirtWebRouteContainer"; import { Button, Paper, Typography } from "@mui/material"; import { TextInput } from "../widgets/forms/TextInput"; import { ServerApi } from "../api/ServerApi"; import { validate as validateUUID } from "uuid"; import { SelectInput } from "../widgets/forms/SelectInput"; import { CheckboxInput } from "../widgets/forms/CheckboxInput"; export function CreateVMRoute(): React.ReactElement { const snackbar = useSnackbar(); const navigate = useNavigate(); const [vm] = React.useState(VMInfo.NewEmpty); const create = async (v: VMInfo) => { const res = await VMApi.Create(v); snackbar("The virtual machine was successfully created!"); v.uuid = res.uuid; navigate(v.ViewURL); }; return ( navigate("/vms")} /> ); } export function EditVMRoute(): React.ReactElement { return <>todo; } function EditVMInner(p: { vm: VMInfo; isCreating: boolean; onCancel: () => void; onSave: (vm: VMInfo) => Promise; }): React.ReactElement { const [changed, setChanged] = React.useState(false); const [, updateState] = React.useState(); const forceUpdate = React.useCallback(() => updateState({}), []); const valueChanged = () => { setChanged(true); forceUpdate(); }; return ( {changed && ( )} } > {/* Metadata section */} { p.vm.name = v ?? ""; valueChanged(); }} size={ServerApi.Config.constraints.name_size} /> { p.vm.genid = v; valueChanged(); }} checkValue={(v) => validateUUID(v)} /> { p.vm.title = v; valueChanged(); }} size={ServerApi.Config.constraints.title_size} /> { p.vm.description = v; valueChanged(); }} multiline={true} /> {/* General section */} { p.vm.architecture = v! as any; valueChanged(); }} value={p.vm.architecture} options={[ { label: "i686", value: "i686" }, { label: "x86_64", value: "x86_64" }, ]} /> { p.vm.boot_type = v! as any; valueChanged(); }} value={p.vm.boot_type} options={[ { label: "UEFI with Secure Boot", value: "UEFISecureBoot" }, { label: "UEFI", value: "UEFI" }, ]} /> { p.vm.memory = Number(v ?? "0"); valueChanged(); }} checkValue={(v) => Number(v) > ServerApi.Config.constraints.memory_size.min && Number(v) < ServerApi.Config.constraints.memory_size.max } /> { p.vm.vnc_access = v; valueChanged(); }} /> ); } function EditSection( p: { title: string } & PropsWithChildren ): React.ReactElement { return ( {p.title} {p.children} ); }