/* Copyright (C) 2024 Manuel Bustillo*/ 'use client'; import { Guest } from '@/app/lib/definitions'; import { getCsrfToken } from '@/app/lib/utils'; import { classNames } from '@/app/ui/components/button'; import clsx from 'clsx'; import React from 'react'; import InlineTextField from '../components/form/inlineTextField'; import TableOfContents from '../components/table-of-contents'; export default function guestsTable({ guests, updateGuestStatus }: { guests: Guest[], updateGuestStatus: (id: string, status: string) => void }) { 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 handleGuestUpdate = (guest: Guest) => { fetch(`/api/guests/${guest.id}`, { method: 'PUT', body: JSON.stringify({ guest: { name: guest.name } }), headers: { 'Content-Type': 'application/json', 'X-CSRF-TOKEN': getCsrfToken(), } }) .catch((error) => console.error(error)); } const handleGuestChange = (e: React.MouseEvent, status: string) => { updateGuestStatus(e.currentTarget.getAttribute('data-guest-id') || '', status); } return ( ( { guest.name = newName; handleGuestUpdate(guest) }} /> {guest.group_name} {guest.status} {guest.status === 'considered' && ()} {(guest.status === 'invited' || guest.status === 'tentative') && ( <> {guest.status != 'tentative' && } )} )} /> ); }