'use client'; import clsx from 'clsx'; import React, { useState, useEffect } from 'react'; import { Guest } from '@/app/lib/definitions'; export default function guestsTable() { const [guests, setGuests] = useState>([]); function loadGuests() { fetch("http://localhost:3001/guests.json") .then((response) => response.json()) .then((data) => { setGuests(data.data.map((record: any) => { return ({ id: record.id, name: record.attributes.name, email: record.attributes.email, group_name: record.attributes.group_name, status: record.attributes.status }); })); }, (error) => { return []; } ); }; function handleInviteGuest() { fetch("http://localhost:3001/guests/123.json", { method: 'PATCH', body: JSON.stringify({ guest: { status: 'Invited' } }) }) .then((response) => console.log(response.json())) .catch((error) => console.error(error)); } guests.length === 0 && loadGuests(); return (
{guests.map((guest) => ( ))}
Guests

There are {guests.length} guests in the list

Name Email Group Status Actions
{guest.name} {guest.email} {guest.group_name} {guest.status} {guest.status === 'Considered' && ()}
); }