import { RotateCcw, Wrench } from "lucide-react"; import fetchApi from "@/src/components/twui/utils/fetch/fetchApi"; import Panel from "@/src/components/general/panel"; import type { ApiReqParams } from "@/src/types"; import type { APIResponseObject } from "@moduletrace/bunext/types"; import type useSystemSetupStatus from "../(hooks)/use-system-setup-status"; import SetupActionRow from "../(partials)/setup-action-row"; import SetupCaddyAction from "../(partials)/setup-caddy-action"; import SetupUpdateWgUiAction from "../(partials)/setup-update-wg-ui-action"; type Props = { setup: ReturnType; }; const WG_TOOL_COMMANDS = [`wg`, `wg-quick`, `ip`, `curl`]; export default function SetupActionsSection({ setup }: Props) { const setup_status = setup.setup_status; if (!setup_status) { return null; } const have_wg_tools = setup_status.tools .filter((tool) => WG_TOOL_COMMANDS.includes(tool.command)) .every((tool) => tool.installed); const have_caddy = Boolean( setup_status.tools.find((tool) => tool.name.startsWith("caddy")) ?.installed, ); const show_restart = !setup_status.is_dev && setup_status.init_system !== "unknown"; return ( } button_title={have_wg_tools ? "Update tools" : "Install tools"} on_run={async () => { const res = await fetchApi( `/api/admin/setup-wireguard-tools`, { method: "POST" }, ); setup.refresh(); return res; }} /> setup.refresh()} /> {show_restart ? ( } button_title="Restart" confirm_params={{ title: "Restart wg-ui?", message: `The ${setup_status.service_name} service restarts and this dashboard goes briefly offline.`, confirm_label: "Restart service", tone: "danger", }} on_run={async () => { const res = await fetchApi( `/api/admin/restart-wg-ui-service`, { method: "POST" }, ); setup.refresh(); return res; }} /> ) : null} ); }