import { useState, useEffect, useCallback } from 'react'; import { Shield, Lock, Globe, RefreshCw, CheckCircle, AlertCircle, ChevronDown, Upload, ToggleLeft, ToggleRight, } from 'lucide-react'; import { connectivityAPI, wireguardAPI } from '../services/api'; // ── Toast helpers (same pattern as Store.jsx) ───────────────────────────────── function toastEvent(msg, type = 'success') { window.dispatchEvent( new CustomEvent('connectivity-toast', { detail: { msg, type } }) ); } function Toast({ toasts }) { return (
{toasts.map((t) => (
{t.type === 'success' ? ( ) : ( )} {t.msg}
))}
); } function useToasts() { const [toasts, setToasts] = useState([]); useEffect(() => { const handler = (e) => { const id = Date.now(); setToasts((prev) => [...prev, { ...e.detail, id }]); setTimeout( () => setToasts((prev) => prev.filter((t) => t.id !== id)), 3000 ); }; window.addEventListener('connectivity-toast', handler); return () => window.removeEventListener('connectivity-toast', handler); }, []); return toasts; } // ── Status badge ────────────────────────────────────────────────────────────── function StatusBadge({ status }) { if (status === 'active') { return ( Active ); } if (status === 'configured') { return ( Configured ); } if (status === 'error') { return ( Error ); } // not configured return ( Not configured ); } // ── WireGuard External card ─────────────────────────────────────────────────── function WireguardExitCard({ exitInfo, onUploaded }) { const [confText, setConfText] = useState(''); const [uploading, setUploading] = useState(false); const status = exitInfo?.status || 'not_configured'; const handleUpload = async () => { if (!confText.trim()) return; setUploading(true); try { await connectivityAPI.uploadWireguard(confText.trim()); toastEvent('WireGuard config uploaded'); setConfText(''); onUploaded(); } catch (err) { const msg = err.response?.data?.error || err.response?.data?.message || 'Failed to upload WireGuard config'; toastEvent(msg, 'error'); } finally { setUploading(false); } }; return (

WireGuard External

Route traffic through an external WireGuard VPN tunnel