90 lines
3.4 KiB
TypeScript
Raw Permalink Normal View History

/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
2024-10-27 21:11:45 +00:00
'use client';
2024-08-11 14:38:49 +02:00
import { AbstractApi } from '@/app/api/abstract-api';
2025-01-28 09:00:09 +01:00
import { Guest, GuestSerializer } from '@/app/lib/guest';
import { EnvelopeIcon, FunnelIcon, PencilIcon, TrashIcon, UserPlusIcon } from '@heroicons/react/24/outline';
2024-11-17 16:10:01 +01:00
import clsx from 'clsx';
2025-01-28 09:00:09 +01:00
import { useState } from 'react';
2024-11-17 16:10:01 +01:00
import TableOfContents from '../components/table-of-contents';
2024-08-11 14:38:49 +02:00
export default function guestsTable({ guests, onUpdate, onEdit }: {
guests: Guest[],
onUpdate: () => void,
onEdit: (guest: Guest) => void
}) {
const api = new AbstractApi<Guest>();
const serializer = new GuestSerializer();
2025-01-28 09:00:09 +01:00
const [invitationId, setInvitationId] = useState<string | undefined>(undefined);
const [selecting, setSelecting] = useState<boolean>(false);
function toggleInvitationId(id: string | undefined) {
console.log('toggleInvitationId', id, invitationId);
if (id === invitationId) {
setInvitationId(undefined);
} else {
setInvitationId(id);
}
console.log('invitationId', invitationId);
}
2024-08-11 12:03:11 +02:00
return (
<TableOfContents
2025-01-28 09:00:09 +01:00
headers={['Name', 'Group', 'Status', 'Invitation', 'Actions']}
caption='Guests'
elements={guests}
rowRender={(guest) => (
2025-01-28 09:00:09 +01:00
<tr key={guest.id} className={clsx("bg-white odd:bg-white even:bg-gray-50 border-b", {
"opacity-25": invitationId && !selecting && guest.invitationId !== invitationId,
"hover:bg-emerald-100" : selecting && guest.invitationId !== invitationId && guest.status !== 'considered',
"opacity-25 hover:cursor-not-allowed" : selecting && (guest.invitationId === invitationId || guest.status === 'considered')
})} >
<td scope="row" className="px-6 py-4 font-medium text-gray-900 whitespace-nowrap">
{guest.name}
2024-11-11 07:45:16 +01:00
</td>
<td className="px-6 py-4">
{guest.group_name}
</td>
<td className="px-6 py-4">
2025-01-28 09:00:09 +01:00
<span className="flex items-center text-sm me-3">
<span className={clsx(
'flex w-2.5 h-2.5 rounded-full me-1.5 flex-shrink-0',
{
'bg-gray-400': guest.status === 'considered',
'bg-blue-400': guest.status === 'invited',
'bg-green-600': guest.status === 'confirmed',
'bg-red-400': guest.status === 'declined',
'bg-yellow-400': guest.status === 'tentative',
}
)}>
</span>
{guest.status}
</span>
</td>
2025-01-28 09:00:09 +01:00
<td>
{
guest.invitationId &&
<div className="flex">
{!selecting && <FunnelIcon className='size-6 cursor-pointer' onClick={() => toggleInvitationId(guest?.invitationId)} />}
{ invitationId === guest.invitationId && !selecting && <UserPlusIcon className='size-6 cursor-pointer' onClick={() => setSelecting(!selecting)}/>}
{ selecting && invitationId !== guest.invitationId && <UserPlusIcon className='size-6 cursor-pointer' />}
</div>
}
</td>
<td>
2024-11-17 18:29:50 +01:00
<div className="flex flex-row items-center">
2025-01-28 09:00:09 +01:00
<TrashIcon className='size-6 cursor-pointer' onClick={() => { api.destroy(serializer, guest, onUpdate) }} />
<PencilIcon className='size-6 cursor-pointer' onClick={() => onEdit(guest)} />
2025-01-28 09:00:09 +01:00
2024-11-17 18:29:50 +01:00
</div>
</td>
</tr>
)}
/>
2024-11-17 16:10:01 +01:00
);
2024-08-11 12:03:11 +02:00
}