/** * InitiateConnectionDialog Component * Dialog for initiating a new federation connection */ import { useState, useEffect } from "react"; interface InitiateConnectionDialogProps { open: boolean; onInitiate: (url: string) => void; onCancel: () => void; isLoading?: boolean; error?: string; } /** * Validate if a string is a valid URL */ function isValidUrl(url: string): boolean { try { const parsedUrl = new URL(url); return parsedUrl.protocol === "http:" || parsedUrl.protocol === "https:"; } catch { return false; } } export function InitiateConnectionDialog({ open, onInitiate, onCancel, isLoading = false, error, }: InitiateConnectionDialogProps): React.JSX.Element | null { const [url, setUrl] = useState(""); const [validationError, setValidationError] = useState(""); // Clear input when dialog closes useEffect(() => { if (!open) { setUrl(""); setValidationError(""); } }, [open]); if (!open) { return null; } const handleConnect = (): void => { // Validate URL if (!url.trim()) { setValidationError("Please enter a URL"); return; } if (!isValidUrl(url)) { setValidationError("Please enter a valid URL (must start with http:// or https://)"); return; } setValidationError(""); onInitiate(url); }; const handleKeyPress = (e: React.KeyboardEvent): void => { if (e.key === "Enter" && url.trim() && !isLoading) { handleConnect(); } }; return (
{/* Header */}

Connect to Remote Instance

Enter the URL of the Mosaic Stack instance you'd like to connect to

{/* URL Input */}
{ setUrl(e.target.value); setValidationError(""); }} onKeyDown={handleKeyPress} disabled={isLoading} placeholder="https://mosaic.example.com" className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 disabled:bg-gray-100 disabled:cursor-not-allowed" /> {validationError &&

{validationError}

}
{/* Error Message */} {error && (

{error}

)} {/* Actions */}
); }