import { Button } from "@/components/ui/button" import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog" import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs" import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { $publicKey, pb } from "@/lib/stores" import { cn, copyToClipboard, isReadOnlyUser } from "@/lib/utils" import { i18n } from "@lingui/core" import { t, Trans } from "@lingui/macro" import { useStore } from "@nanostores/react" import { ChevronDownIcon, Copy, PlusIcon } from "lucide-react" import { memo, MutableRefObject, useRef, useState } from "react" import { basePath, navigate } from "./router" import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "./ui/dropdown-menu" import { SystemRecord } from "@/types" export function AddSystemButton({ className }: { className?: string }) { const [open, setOpen] = useState(false) let opened = useRef(false) if (open) { opened.current = true } return ( {opened.current && } ) } /** * SystemDialog component for adding or editing a system. * @param {Object} props - The component props. * @param {function} props.setOpen - Function to set the open state of the dialog. * @param {SystemRecord} [props.system] - Optional system record for editing an existing system. */ export const SystemDialog = memo(({ setOpen, system }: { setOpen: (open: boolean) => void; system?: SystemRecord }) => { const port = useRef() as MutableRefObject const publicKey = useStore($publicKey) function copyDockerCompose(port: string) { copyToClipboard(`services: beszel-agent: image: "henrygd/beszel-agent" container_name: "beszel-agent" restart: unless-stopped network_mode: host volumes: - /var/run/docker.sock:/var/run/docker.sock:ro # monitor other disks / partitions by mounting a folder in /extra-filesystems # - /mnt/disk/.beszel:/extra-filesystems/sda1:ro environment: PORT: ${port} KEY: "${publicKey}"`) } function copyDockerRun(port: string) { copyToClipboard( `docker run -d --name beszel-agent --network host --restart unless-stopped -v /var/run/docker.sock:/var/run/docker.sock:ro -e KEY="${publicKey}" -e PORT=${port} henrygd/beszel-agent:latest` ) } function copyInstallCommand(port: string) { let cmd = `curl -sL https://raw.githubusercontent.com/henrygd/beszel/main/supplemental/scripts/install-agent.sh -o install-agent.sh && chmod +x install-agent.sh && ./install-agent.sh -p ${port} -k "${publicKey}"` // add china mirrors flag if zh-CN if ((i18n.locale + navigator.language).includes("zh-CN")) { cmd += ` --china-mirrors` } copyToClipboard(cmd) } async function handleSubmit(e: SubmitEvent) { e.preventDefault() const formData = new FormData(e.target as HTMLFormElement) const data = Object.fromEntries(formData) as Record data.users = pb.authStore.record!.id try { setOpen(false) if (system) { await pb.collection("systems").update(system.id, { ...data, status: "pending" }) } else { await pb.collection("systems").create(data) } navigate(basePath) // console.log(record) } catch (e) { console.log(e) } } return ( {system ? `${t`Edit`} ${system?.name}` : Add New System} Docker Binary {/* Docker (set tab index to prevent auto focusing content in edit system dialog) */} The agent must be running on the system to connect. Copy the docker-compose.yml for the agent below. {/* Binary */} The agent must be running on the system to connect. Copy the installation command for the agent below.

Click to copy

{/* Docker */}
copyDockerRun(port.current.value)}> Copy docker run
{/* Binary */} {/* Save */}
) })