"use client"; import { useState, ReactNode } from "react"; import { Button } from "@/components/ui/button"; import { Dialog, DialogClose, DialogContent, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { getLiveNodes } from "@/lib/dockship/node"; import { Combobox } from "../ui/combobox"; import { deployApp } from "@/lib/dockship/deploy"; import { useAsync } from "@/hooks/use-async"; import { Application, Port } from "@/lib/types"; import { getApps } from "@/lib/dockship/application"; import { Plus } from "lucide-react"; export default function DeployAppDialog({ defaultApp, children, ports: initialPorts, nodeId: defaultNode, }: { defaultApp?: string; nodeId?: string; ports?: Port[]; children: ReactNode; }) { const { value: nodes } = useAsync("liveNodes", [], getLiveNodes); const { value: apps } = useAsync("apps", [], getApps); const [name, setName] = useState(""); const [app, setApp] = useState(defaultApp || ""); const [node, setNode] = useState(defaultNode || ""); const [ports, setPorts] = useState(initialPorts || []); const [newPort, setNewPort] = useState({ containerPort: "", hostPort: "", protocol: "tcp", }); const addPort = () => { if (!newPort.containerPort || !newPort.hostPort) return; setPorts([...ports, newPort]); setNewPort({ containerPort: "", hostPort: "", protocol: "tcp" }); }; const removePort = (index: number) => { setPorts(ports.filter((_, i) => i !== index)); }; const deploy = async () => { console.log("Deploying:", { name, app, node, ports }); await deployApp(name, app, node, ports); }; return ( {children} Deploy Application
{/* Name */}
setName(e.target.value)} placeholder="My app" />
{/* Application */}
({ label: app.name, value: app.id, }))} placeholder="Select App..." listPlaceholder="No apps found :(" />
{/* Node */}
node.liveData) .map((node) => ({ label: node.name, value: node.node_id }))} placeholder="Select Node..." listPlaceholder="No nodes found :(" />
{/* Ports */}
setNewPort({ ...newPort, containerPort: e.target.value }) } /> setNewPort({ ...newPort, hostPort: e.target.value }) } /> setNewPort({ ...newPort, protocol: v as "tcp" | "udp", }) } data={[ { label: "TCP", value: "tcp" }, { label: "UDP", value: "udp" }, ]} placeholder="Select protocol..." listPlaceholder="No protocols found :(" />
{ports.length > 0 && (
    {ports.map((p, i) => (
  • {p.containerPort} → {p.hostPort} ( {p.protocol.toUpperCase()})
  • ))}
)}
); }