import { Button } from '@/components/ui/button' import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from '@/components/ui/dialog' import { TooltipProvider, Tooltip, TooltipTrigger, TooltipContent } from '@/components/ui/tooltip' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import { $publicKey, pb } from '@/lib/stores' import { Copy, Plus } from 'lucide-react' import { useState, useRef, MutableRefObject, useEffect } from 'react' import { useStore } from '@nanostores/react' import { copyToClipboard } from '@/lib/utils' import { SystemStats } from '@/types' export function AddServerButton() { const [open, setOpen] = useState(false) const port = useRef() as MutableRefObject const publicKey = useStore($publicKey) function copyDockerCompose(port: string) { copyToClipboard(`services: agent: image: 'henrygd/qoma-agent' container_name: 'qoma-agent' restart: unless-stopped ports: - '${port}:45876' volumes: - /var/run/docker.sock:/var/run/docker.sock environment: - KEY="${publicKey}"`) } useEffect(() => { if (publicKey || !open) { return } // get public key pb.send('/getkey', {}).then(({ key }) => { $publicKey.set(key) }) }, [open]) async function handleSubmit(e: SubmitEvent) { e.preventDefault() const formData = new FormData(e.target as HTMLFormElement) const data = Object.fromEntries(formData) as Record data.status = 'down' data.stats = { c: 0, d: 0, dp: 0, du: 0, m: 0, mp: 0, mu: 0, } as SystemStats try { setOpen(false) await pb.collection('systems').create(data) // console.log(record) } catch (e) { console.log(e) } } return ( Add New System The agent must be running on the server to connect. Copy the{' '} docker-compose.yml for the agent below.

Click to copy

) }