/* Copyright (C) 2024 Manuel Bustillo*/ 'use client'; import clsx from 'clsx'; import React, { useState, useEffect } from 'react'; import { Guest } from '@/app/lib/definitions'; import { getCsrfToken } from '@/app/lib/utils'; import {classNames} from '@/app/ui/components/button'; export default function guestsTable() { const [guests, setGuests] = useState>([]); function loadGuests() { fetch("/api/guests.json") .then((response) => response.json()) .then((data) => { setGuests(data.data.map((record: any) => { return ({ id: record.id, name: record.attributes.name, group_name: record.attributes.group_name, status: record.attributes.status }); })); }, (error) => { return []; }); }; const handleInviteGuest = (e: React.MouseEvent) => handleGuestChange(e, 'invited'); const handleConfirmGuest = (e: React.MouseEvent) => handleGuestChange(e, 'confirmed'); const handleDeclineGuest = (e: React.MouseEvent) => handleGuestChange(e, 'declined'); const handleTentativeGuest = (e: React.MouseEvent) => handleGuestChange(e, 'tentative'); const handleGuestChange = (e: React.MouseEvent, status:string) => { fetch("/api/guests/bulk_update.json", { method: 'POST', body: JSON.stringify({ properties: { status: status }, guest_ids: [e.currentTarget.getAttribute('data-guest-id')] }), headers: { 'Content-Type': 'application/json', 'X-CSRF-TOKEN': getCsrfToken(), } }) .then(() => loadGuests()) .catch((error) => console.error(error)); } guests.length === 0 && loadGuests(); return (
{guests.map((guest) => ( ))}
Guests

There are {guests.length} guests in the list

Name Group Status Actions
{guest.name} {guest.group_name} {guest.status} {guest.status === 'Considered' && ()} {(guest.status === 'Invited' || guest.status === 'Tentative') && ( <> {guest.status != 'Tentative' && } )}
); }