import { Button, InputAdornment, LinearProgress, ListSubheader, MenuItem, Select, Switch, TextField, } from "@mui/material"; import { Controller, SubmitHandler, UseFormReturn } from "react-hook-form"; import { FlakeBadge } from "../flakeBadge/flakeBadge"; import { createVm, useInspectFlakeAttrs } from "@/api/default/default"; import { VmConfig } from "@/api/model"; import { Dispatch, SetStateAction, useEffect, useState } from "react"; import { toast } from "react-hot-toast"; import { useAppState } from "../hooks/useAppContext"; interface VmPropLabelProps { children: React.ReactNode; } const VmPropLabel = (props: VmPropLabelProps) => (
{props.children}
); interface VmPropContentProps { children: React.ReactNode; } const VmPropContent = (props: VmPropContentProps) => (
{props.children}
); interface VmDetailsProps { formHooks: UseFormReturn; setVmUuid: Dispatch>; } export const ConfigureVM = (props: VmDetailsProps) => { const { formHooks, setVmUuid } = props; const { control, handleSubmit, watch, setValue } = formHooks; const [isStarting, setStarting] = useState(false); const { setAppState } = useAppState(); const { isLoading, data } = useInspectFlakeAttrs({ url: watch("flake_url") }); useEffect(() => { if (!isLoading && data?.data) { setValue("flake_attr", data.data.flake_attrs[0] || ""); } }, [isLoading, setValue, data]); const onSubmit: SubmitHandler = async (data) => { setStarting(true); console.log(data); const response = await createVm(data); const { uuid } = response?.data || null; setVmUuid(() => uuid); setStarting(false); if (response.statusText === "OK") { toast.success(("Joined @ " + uuid) as string); setAppState((s) => ({ ...s, isJoined: true })); } else { toast.error("Could not join"); } }; return (
General
Flake Machine {!isLoading && ( ( )} /> )}
VM
CPU Cores } /> Graphics ( )} /> Memory Size ( MiB ), }} /> )} />
{isStarting && }
); };