import React, { useState } from "react"; import { X, Loader2 } from "lucide-react"; import { Button } from "@/components/ui"; import type { ClusterInfo } from "@/lib/tauriCommands"; import { addClusterCmd } from "@/lib/tauriCommands"; interface AddClusterModalProps { isOpen: boolean; onClose: () => void; onAdd: (cluster: ClusterInfo) => void; } export function AddClusterModal({ isOpen, onClose, onAdd }: AddClusterModalProps) { const [id, setId] = useState(""); const [name, setName] = useState(""); const [kubeconfig, setKubeconfig] = useState(""); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(""); if (!isOpen) return null; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(""); if (!id.trim() || !name.trim() || !kubeconfig.trim()) { setError("All fields are required"); return; } setIsLoading(true); try { const cluster = await addClusterCmd(id, name, kubeconfig); onAdd(cluster); onClose(); setId(""); setName(""); setKubeconfig(""); } catch (err) { setError(err instanceof Error ? err.message : "Failed to add cluster"); } finally { setIsLoading(false); } }; return (

Add Kubernetes Cluster

{error && (
{error}
)}
setId(e.target.value)} placeholder="e.g., prod-cluster-01" className="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50" disabled={isLoading} />
setName(e.target.value)} placeholder="e.g., Production Cluster" className="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50" disabled={isLoading} />