Add host setup functions and client components

This commit is contained in:
2026-09-13 10:52:30 +01:00
parent 76679aabe7
commit 86eb3a0b05
53 changed files with 1284 additions and 1325 deletions
+77
View File
@@ -0,0 +1,77 @@
import { useEffect, useState, type ComponentProps } from "react";
import Button from "../twui/layout/Button";
import useStatus from "../twui/hooks/useStatus";
import fetchApi from "../twui/utils/fetch/fetchApi";
import type { ApiReqParams } from "@/src/types";
import Row from "../twui/layout/Row";
import Input from "../twui/form/Input";
import Stack from "../twui/layout/Stack";
import { Network } from "lucide-react";
import Span from "../twui/layout/Span";
import { AppData } from "@/src/data/app-data";
type Props = {
button_props?: Omit<ComponentProps<typeof Button>, "title">;
};
export default function SetupMainHostButton({ button_props }: Props) {
const { loading, setLoading, ready, setReady } = useStatus();
const [wgIP, setWgIP] = useState<string>(AppData["DefaultPrivateIP"]);
useEffect(() => {
fetchApi<ApiReqParams>(
`/api/admin/check-private-ip-address-availability`,
{
method: "POST",
body: { ip_address: wgIP },
},
).then((res) => {
console.log(`res`, res);
});
}, [wgIP]);
return (
<Stack className="w-full items-stretch">
<Input
defaultValue={wgIP}
changeHandler={(v) => {
setWgIP(v);
}}
prefix={<Network size={17} opacity={0.5} />}
suffix={
<Span className="text-sm opacity-50 whitespace-nowrap">
Selected Wireguard IP Address
</Span>
}
autoFocus
/>
<Button
title="Setup Main Host"
{...button_props}
loading={loading}
onClick={() => {
setLoading(true);
fetchApi<ApiReqParams>(`/api/admin/setup-main-host`, {
method: "POST",
body: {
ip_address: ``,
},
})
.then((res) => {
console.log(`res`, res);
})
.finally(() => {
setTimeout(() => {
setLoading(false);
}, 4000);
});
}}
>
Setup Main Host
</Button>
</Stack>
);
}