import React, { useState, useEffect } from 'react'; import { useNavigate } from 'react-router-dom'; import { Users, LogOut, Search, Eye, Mail, Phone, Building2, User, Calendar } from 'lucide-react'; interface Contact { id: string; first_name: string; last_name: string; email?: string; phone?: string; company?: string; position?: string; created_at: string; } export function GuestContactsPage() { const navigate = useNavigate(); const [contacts, setContacts] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const [search, setSearch] = useState(''); const [guestInfo, setGuestInfo] = useState<{ name: string; email: string } | null>(null); useEffect(() => { // Fetch guest info fetch('/api/v1/guest/me', { credentials: 'include' }) .then((res) => { if (!res.ok) throw new Error('Not authenticated'); return res.json(); }) .then((data) => setGuestInfo({ name: data.name, email: data.email })) .catch(() => { navigate('/guest/login'); }); }, [navigate]); useEffect(() => { fetchContacts(); }, []); const fetchContacts = async (query?: string) => { setLoading(true); setError(null); try { const url = query ? `/api/v1/contacts?search=${encodeURIComponent(query)}&limit=50` : '/api/v1/contacts?limit=50'; const response = await fetch(url, { credentials: 'include', headers: { 'X-CSRF-Token': '', }, }); if (!response.ok) { throw new Error('Failed to load contacts'); } const data = await response.json(); setContacts(data.items || data.data || data || []); } catch (err: any) { setError(err.message || 'Failed to load contacts'); } finally { setLoading(false); } }; const handleSearch = (e: React.FormEvent) => { e.preventDefault(); fetchContacts(search); }; const handleLogout = async () => { try { await fetch('/api/v1/guest/logout', { method: 'POST', credentials: 'include', }); } catch { // ignore } navigate('/guest/login'); }; return (
{/* Header */}

Shared Contacts

{guestInfo && ( {guestInfo.name} ({guestInfo.email}) )}
{/* Search */}
setSearch(e.target.value)} placeholder="Search shared contacts..." className="block w-full pl-10 pr-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm placeholder-gray-400 dark:placeholder-gray-500 text-gray-900 dark:text-white dark:bg-gray-800 focus:outline-none focus:ring-primary-500 focus:border-primary-500 sm:text-sm" />
{/* Error */} {error && (

{error}

)} {/* Loading */} {loading && (
)} {/* Contacts Grid */} {!loading && !error && ( <>

{contacts.length} contact{contacts.length !== 1 ? 's' : ''} shared with you

{contacts.length === 0 ? (

No contacts

No contacts have been shared with you yet.

) : (
{contacts.map((contact) => (

{contact.first_name} {contact.last_name}

{contact.company && (

{contact.company}

)}
{contact.email && (

{contact.email}

)} {contact.phone && (

{contact.phone}

)} {contact.position && (

{contact.position}

)}

Created: {new Date(contact.created_at).toLocaleDateString()}

))}
)} )}
); }