"use client"; import { useRef, useState } from "react"; import { Button } from "@kandev/ui/button"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@kandev/ui/dialog"; import { Input } from "@kandev/ui/input"; import { Label } from "@kandev/ui/label"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@kandev/ui/tabs"; import { cn } from "@/lib/utils"; type InstallTab = "url" | "upload"; type InstallPluginDialogProps = { open: boolean; busy: boolean; error: string | null; onOpenChange: (open: boolean) => void; onSubmitUrl: (url: string) => void; onSubmitFile: (file: File) => void; }; /** * Replaces the old "Register plugin" manifest-paste dialog with the * install-based flow (docs/plans/plugins/GRPC-CONTRACT.md §7): install from a * remote tarball URL, or upload a .tar.gz package directly. No credentials * are ever shown — installing a plugin has nothing to copy or reveal. */ export function InstallPluginDialog({ open, busy, error, onOpenChange, onSubmitUrl, onSubmitFile, }: InstallPluginDialogProps) { const [tab, setTab] = useState("url"); const [url, setUrl] = useState(""); const handleOpenChange = (next: boolean) => { if (!next) { setUrl(""); setTab("url"); } onOpenChange(next); }; return ( Install plugin Install a plugin package from a URL, or upload a .tar.gz file directly. setTab(v as InstallTab)}> From URL Upload file {error && (
{error}
)}
); } function UrlTab({ url, setUrl, busy, onSubmit, }: { url: string; setUrl: (v: string) => void; busy: boolean; onSubmit: (url: string) => void; }) { return (
setUrl(e.target.value)} placeholder="https://example.com/acme-tools-1.0.0.tar.gz" className="font-mono text-sm" />
); } function UploadTab({ busy, onSubmit }: { busy: boolean; onSubmit: (file: File) => void }) { const inputRef = useRef(null); const [file, setFile] = useState(null); const [isDragging, setIsDragging] = useState(false); const handleDragOver = (e: React.DragEvent) => { e.preventDefault(); e.stopPropagation(); }; const handleDragEnter = (e: React.DragEvent) => { e.preventDefault(); e.stopPropagation(); if (e.dataTransfer.types.includes("Files")) setIsDragging(true); }; const handleDragLeave = (e: React.DragEvent) => { e.preventDefault(); e.stopPropagation(); setIsDragging(false); }; const handleDrop = (e: React.DragEvent) => { e.preventDefault(); e.stopPropagation(); setIsDragging(false); const dropped = e.dataTransfer.files[0]; if (dropped) setFile(dropped); }; return (
inputRef.current?.click()} className={cn( "flex flex-col items-center justify-center gap-2 rounded-lg border border-dashed border-border/70 p-6 text-center text-sm text-muted-foreground cursor-pointer", isDragging && "border-primary bg-primary/5 ring-1 ring-primary/30", )} > {file ? ( {file.name} ) : ( "Drag and drop a .tar.gz package here, or click to browse" )} setFile(e.target.files?.[0] ?? null)} className="hidden" />
); }