87 lines
2.9 KiB
TypeScript
Raw Normal View History

2024-08-11 14:38:49 +02:00
'use client'
2024-08-11 13:12:03 +02:00
import { Guest } from '@/app/lib/definitions';
import { useState, Suspense, useEffect } from 'react';
import clsx from 'clsx';
2024-08-11 14:38:49 +02:00
export default function guestsTable() {
const [guests, setGuests] = useState<Guest[]>([]);
2024-08-11 12:03:11 +02:00
useEffect(() => {
if (guests.length > 0) {
return;
}
fetch("http://localhost:3001/guests.json")
2024-08-11 14:38:49 +02:00
.then((response) => response.json())
.then((data) => {
setGuests(data.data.map((record: any) => {
return ({
2024-08-11 14:38:49 +02:00
id: record.id,
name: record.attributes.name,
email: record.attributes.email,
group_name: record.attributes.group_name,
status: record.attributes.status
2024-08-11 14:38:49 +02:00
});
}))
2024-08-11 14:38:49 +02:00
});
});
2024-08-11 12:03:11 +02:00
return (
2024-08-11 13:12:03 +02:00
<div className="w-full relative overflow-x-auto shadow-md sm:rounded-lg">
<p className="py-3">There are {guests.length} guests in the list</p>
2024-08-11 13:12:03 +02:00
<table className="w-full text-sm text-left rtl:text-right text-gray-500 dark:text-gray-400">
<thead className="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400">
<tr>
<th scope="col" className="px-6 py-3">
Name
</th>
<th scope="col" className="px-6 py-3">
Email
</th>
<th scope="col" className="px-6 py-3">
Group
2024-08-11 13:12:03 +02:00
</th>
<th scope="col" className="px-6 py-3">
Status
</th>
2024-08-11 13:12:03 +02:00
</tr>
</thead>
<tbody>
<Suspense>
2024-08-11 14:38:49 +02:00
{guests.map((guest) => (
<tr key={guest.id} className="bg-white border-b odd:bg-white odd:dark:bg-gray-900 even:bg-gray-50 even:dark:bg-gray-800">
2024-08-11 14:38:49 +02:00
<th scope="row" className="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white">
{guest.name}
</th>
<td className="px-6 py-4">
{guest.email}
</td>
<td className="px-6 py-4">
{guest.group_name}
2024-08-11 14:38:49 +02:00
</td>
<td className="px-6 py-4">
<span className="flex items-center text-sm dark:text-white 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',
}
)}>
{/* <span className="flex w-2.5 h-2.5 rounded-full me-1.5 flex-shrink-0 bg-blue-600"> */}
</span>
{guest.status}
</span>
</td>
2024-08-11 14:38:49 +02:00
</tr>
))}
</Suspense>
2024-08-11 13:12:03 +02:00
</tbody>
</table>
2024-08-11 12:03:11 +02:00
</div>
);
}