import { useEffect, useState } from "react"; import { Link } from "react-router-dom"; import { api } from "../api/client"; import type { ContactListItem } from "../types"; export function ContactList() { const [contacts, setContacts] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { api.contacts .list() .then(setContacts) .catch((err) => setError(err.message)) .finally(() => setLoading(false)); }, []); const handleDelete = async (id: number) => { if (!confirm("Delete this contact?")) return; try { await api.contacts.delete(id); setContacts((prev) => prev.filter((c) => c.id !== id)); } catch (err) { setError(err instanceof Error ? err.message : "Delete failed"); } }; if (loading) return
Loading...
; if (error) return
Error: {error}
; return (

Contacts

Add Contact
{contacts.length === 0 ? (

No contacts yet.

) : ( {contacts.map((contact) => ( ))}
Name Job Timezone Actions
{contact.name} {contact.current_job || "-"} {contact.timezone || "-"} Edit
)}
); }