UI: fixup machine details

This commit is contained in:
Johannes Kirschbauer
2024-12-10 15:16:38 +01:00
parent d9d0e916bb
commit 84989fbfcb

View File

@@ -1,12 +1,9 @@
import { callApi, ClanService, SuccessData, SuccessQuery } from "@/src/api"; import { callApi, SuccessData, SuccessQuery } from "@/src/api";
import { get_iwd_service } from "@/src/api/wifi";
import { activeURI } from "@/src/App"; import { activeURI } from "@/src/App";
import { BackButton } from "@/src/components/BackButton"; import { BackButton } from "@/src/components/BackButton";
import { Button } from "@/src/components/button"; import { Button } from "@/src/components/button";
import { FileInput } from "@/src/components/FileInput"; import { FileInput } from "@/src/components/FileInput";
import Icon from "@/src/components/icon"; import Icon from "@/src/components/icon";
import { RndThumbnail } from "@/src/components/noiseThumbnail";
import { SelectInput } from "@/src/components/SelectInput";
import { TextInput } from "@/src/components/TextInput"; import { TextInput } from "@/src/components/TextInput";
import { selectSshKeys } from "@/src/hooks"; import { selectSshKeys } from "@/src/hooks";
import { import {
@@ -16,9 +13,10 @@ import {
setValue, setValue,
} from "@modular-forms/solid"; } from "@modular-forms/solid";
import { useParams } from "@solidjs/router"; import { useParams } from "@solidjs/router";
import { createQuery, useQueryClient } from "@tanstack/solid-query"; import { createQuery } from "@tanstack/solid-query";
import { createSignal, For, Show, Switch, Match, JSXElement } from "solid-js"; import { createSignal, For, Show } from "solid-js";
import toast from "solid-toast"; import toast from "solid-toast";
import { MachineAvatar } from "./avatar";
type MachineFormInterface = MachineData & { type MachineFormInterface = MachineData & {
sshKey?: File; sshKey?: File;
@@ -65,7 +63,7 @@ const InstallMachine = (props: InstallMachineProps) => {
} }
const loading_toast = toast.loading( const loading_toast = toast.loading(
"Installing machine. Grab coffee (15min)...", "Installing machine. Grab coffee (15min)..."
); );
const r = await callApi("install_machine", { const r = await callApi("install_machine", {
opts: { opts: {
@@ -248,13 +246,13 @@ const MachineForm = (props: MachineDetailsProps) => {
...values.machine, ...values.machine,
// TODO: Remove this workaround // TODO: Remove this workaround
tags: Array.from( tags: Array.from(
values.machine.tags || props.initialData.machine.tags || [], values.machine.tags || props.initialData.machine.tags || []
), ),
}, },
}); });
if (machine_response.status === "error") { if (machine_response.status === "error") {
toast.error( toast.error(
`Failed to set machine: ${machine_response.errors[0].message}`, `Failed to set machine: ${machine_response.errors[0].message}`
); );
} }
if (machine_response.status === "success") { if (machine_response.status === "success") {
@@ -305,24 +303,9 @@ const MachineForm = (props: MachineDetailsProps) => {
return ( return (
<> <>
<Form onSubmit={handleSubmit}> <Form onSubmit={handleSubmit}>
<figure>
<div
class="avatar placeholder"
classList={
{
// online: onlineStatusQuery.data === "Online",
// offline: onlineStatusQuery.data === "Offline",
}
}
>
<div class="w-32 rounded-lg border p-2 bg-def-4 border-inv-3">
<RndThumbnail name={machineName() || "M"} />
</div>
</div>
</figure>
<div class="card-body"> <div class="card-body">
<span class="text-xl text-primary-800">General</span> <span class="text-xl text-primary-800">General</span>
<MachineAvatar name={machineName()} />
<Field name="machine.name"> <Field name="machine.name">
{(field, props) => ( {(field, props) => (
<TextInput <TextInput
@@ -455,7 +438,7 @@ const MachineForm = (props: MachineDetailsProps) => {
// disabled={!online()} // disabled={!online()}
onClick={() => { onClick={() => {
const modal = document.getElementById( const modal = document.getElementById(
"install_modal", "install_modal"
) as HTMLDialogElement | null; ) as HTMLDialogElement | null;
modal?.showModal(); modal?.showModal();
}} }}
@@ -561,7 +544,7 @@ function WifiModule(props: MachineWifiProps) {
}); });
const [nets, setNets] = createSignal<1[]>( const [nets, setNets] = createSignal<1[]>(
new Array(props.initialData.length || 1).fill(1), new Array(props.initialData.length || 1).fill(1)
); );
const handleSubmit = async (values: WifiForm) => { const handleSubmit = async (values: WifiForm) => {
@@ -572,7 +555,7 @@ function WifiModule(props: MachineWifiProps) {
...acc, ...acc,
[curr.ssid || ""]: { ssid: curr.ssid, password: curr.password }, [curr.ssid || ""]: { ssid: curr.ssid, password: curr.password },
}), }),
{}, {}
); );
console.log("submitting", values, networks); console.log("submitting", values, networks);