'use client'; import { useState, useEffect } from 'react'; import { Badge } from '@/components/ui/badge'; import { User } from 'lucide-react'; interface ContactCellProps { contactId?: number; } export function ContactCell({ contactId }: ContactCellProps) { const [contactName, setContactName] = useState(null); const [loading, setLoading] = useState(false); useEffect(() => { if (!contactId) { setContactName(null); return; } const fetchContact = async () => { setLoading(true); try { const response = await fetch(`/api/contacts/${contactId}`); if (response.ok) { const data = await response.json(); if (data.contact) { setContactName(`${data.contact.firstName} ${data.contact.lastName}`); } } } catch (err) { console.error('Failed to fetch contact:', err); } finally { setLoading(false); } }; fetchContact(); }, [contactId]); if (loading) { return Loading...; } if (!contactId) { return -; } if (contactName) { return ( {contactName} ); } return ID: {contactId}; }