Refactor main host setup

This commit is contained in:
2026-09-20 15:37:57 +01:00
parent 3c1d2b61f6
commit 69111e461e
47 changed files with 669 additions and 591 deletions
@@ -0,0 +1,50 @@
import { useState } from "react";
import { Trash2 } from "lucide-react";
import Button from "@/src/components/twui/layout/Button";
import fetchApi from "@/src/components/twui/utils/fetch/fetchApi";
import type { ApiReqParams } from "@/src/types";
import type { APIResponseObject } from "@moduletrace/bunext/types";
export default function DeleteHostButton({ host_id }: { host_id: number }) {
const [deleting, setDeleting] = useState(false);
async function handleDelete() {
if (
!window.confirm(
`Delete host #${host_id}? All clients and their configurations will be removed.`,
)
) {
return;
}
setDeleting(true);
const res = await fetchApi<ApiReqParams, APIResponseObject>(
`/api/admin/delete-host`,
{
method: "DELETE",
body: { host_id },
},
);
if (!res.success) {
setDeleting(false);
window.alert(res.msg || "Could not delete the host");
return;
}
window.location.pathname = "/admin/hosts";
}
return (
<Button
title="Delete Host"
size="small"
variant="ghost"
color="error"
beforeIcon={<Trash2 size={14} />}
disabled={deleting}
onClick={handleDelete}
/>
);
}