'use client' import React, { useState } from 'react' import EditGuestBookEntryModal from './EditGuestBookEntryModal' interface GuestBookEntry { id: string fName: string lName: string side: string email?: string | null phone?: string | null address?: string | null notes?: string | null } export default function GuestBookList({ entries }: { entries: GuestBookEntry[] }) { const [editingEntry, setEditingEntry] = useState(null) function handleModalClose() { setEditingEntry(null) } async function handleUpdate(updated: { id: string fName: string lName: string email?: string phone?: string address?: string side?: string notes?: string }) { try { const res = await fetch(`/api/guestbook/${updated.id}`, { method: 'PATCH', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ fName: updated.fName, lName: updated.lName, email: updated.email, phone: updated.phone, address: updated.address, side: updated.side, notes: updated.notes, }), }) if (!res.ok) { const { message } = await res.json() throw new Error(message || 'Update failed') } // Optional: trigger a state update/refetch if needed setEditingEntry(null) } catch (err) { console.error('Update failed:', err) } } return (
{entries.map(entry => ( ))}
Name Email Phone Address Notes
{entry.fName + ' ' + entry.lName} (Side: {entry.side}) {entry.email || 'N/A'} {entry.phone || 'N/A'} {entry.address || 'N/A'} {entry.notes || 'N/A'}
{entries.map(entry => (

{entry.fName} {entry.lName}

Side: {entry.side}

Email: {entry.email || 'N/A'}

Phone: {entry.phone || 'N/A'}

Address: {entry.address || 'N/A'}

Notes: {entry.notes || 'N/A'}

))}
{editingEntry && ( )}
) }