'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 []; } ); }; const handleInviteGuest = (e: React.MouseEvent) => { fetch("http://localhost:3001/guests/bulk-status-change.json", { method: 'POST', body: JSON.stringify({ status: "Invited", guest_ids: [e.currentTarget.getAttribute('data-guest-id')] }) }) .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' && ()}
); }