import { useState } from 'react'; import { Search, UserPlus, Loader2, AlertCircle, CheckCircle, Settings } from 'lucide-react'; import { toast } from 'sonner'; import { useNavigate } from 'react-router-dom'; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, } from '@/components/ui/dialog'; import { Input } from '@/components/ui/input'; import { Button } from '@/components/ui/button'; import { Label } from '@/components/ui/label'; import { useConnections } from '@/hooks/useConnections'; import { useSettings } from '@/hooks/useSettings'; import { getErrorMessage } from '@/lib/api'; interface ConnectionSearchProps { open: boolean; onOpenChange: (open: boolean) => void; } export default function ConnectionSearch({ open, onOpenChange }: ConnectionSearchProps) { const { search, isSearching, sendRequest, isSending } = useConnections(); const { settings } = useSettings(); const navigate = useNavigate(); const [umbralName, setUmbralName] = useState(''); const [found, setFound] = useState(null); const [sent, setSent] = useState(false); const acceptConnectionsEnabled = settings?.accept_connections ?? false; const handleSearch = async () => { if (!umbralName.trim()) return; setFound(null); setSent(false); try { const result = await search(umbralName.trim()); setFound(result.found); } catch { setFound(false); } }; const handleSend = async () => { try { await sendRequest(umbralName.trim()); setSent(true); toast.success('Connection request sent'); } catch (err) { toast.error(getErrorMessage(err, 'Failed to send request')); } }; const handleClose = () => { setUmbralName(''); setFound(null); setSent(false); onOpenChange(false); }; return ( Find Umbra User Search for a user by their umbral name to send a connection request.
{!acceptConnectionsEnabled ? (

You need to enable Accept Connections in your settings before you can send or receive connection requests.

) : ( <>
{ setUmbralName(e.target.value); setFound(null); setSent(false); }} onKeyDown={(e) => { if (e.key === 'Enter') handleSearch(); }} maxLength={50} />
{found === false && (
User not found
)} {found === true && !sent && (
{umbralName.charAt(0).toUpperCase()}
{umbralName}
)} {sent && (
Connection request sent
)} )}
); }