import { useState } from "react"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Switch } from "@/components/ui/switch"; import { Button } from "@/components/ui/button"; import { Info, PlusIcon } from "lucide-react"; import { Tooltip, TooltipContent, TooltipTrigger } from "../ui/tooltip"; // hostname[:port][/path] — explicitly no protocol/scheme allowed const HOSTNAME_PATTERN = /^(?!.*:\/\/)[a-zA-Z0-9.-]+(:\d{1,5})?(\/[a-zA-Z0-9\-._~%!$&'()*+,;=:@/]*)?$/; function validateHostname(value: string): string | null { if (!value.trim()) { return "Hostname is required"; } if (value.includes("://")) { return "Don't include a protocol (e.g. https://)"; } if (!HOSTNAME_PATTERN.test(value)) { return "Invalid hostname format"; } return null; } type AddServerDialogProps = { onAdd: (hostname: string, isSecure: boolean) => Promise | void; }; export function AddServerDialog({ onAdd }: AddServerDialogProps) { const [open, setOpen] = useState(false); const [hostname, setHostname] = useState(""); const [isSecure, setIsSecure] = useState(false); const [error, setError] = useState(null); const [submitting, setSubmitting] = useState(false); function handleHostnameChange(value: string) { setHostname(value); if (error) { setError(validateHostname(value)); } } async function handleSubmit() { const validationError = validateHostname(hostname); if (validationError) { setError(validationError); return; } setSubmitting(true); try { await onAdd(hostname.trim(), isSecure); setHostname(""); setIsSecure(true); setError(null); setOpen(false); } catch (e) { setError(e instanceof Error ? e.message : "Failed to add server"); } finally { setSubmitting(false); } } return ( ( )} /> Add a Server Enter the server's address to connect.
handleHostnameChange(e.target.value)} aria-invalid={!!error} /> {error &&

{error}

}

TLS is not recommended because there is a encryption layer already built in to Enclave

); }