2024-08-11 14:38:49 +02:00
|
|
|
'use client'
|
|
|
|
|
2024-08-11 13:12:03 +02:00
|
|
|
import { Guest } from '@/app/lib/definitions';
|
2024-08-11 14:38:49 +02:00
|
|
|
import { useState, Suspense } from 'react';
|
|
|
|
|
|
|
|
export default function guestsTable() {
|
|
|
|
|
|
|
|
const url = "http://localhost:3001/guests.json";
|
2024-08-11 12:03:11 +02:00
|
|
|
|
2024-08-11 14:38:49 +02:00
|
|
|
const getData = (): Guest[] => {
|
|
|
|
var guests: Guest[] = [];
|
|
|
|
fetch(url)
|
|
|
|
.then((response) => response.json())
|
|
|
|
.then((data) => {
|
|
|
|
data.data.map((record: any) => {
|
|
|
|
guests.push({
|
|
|
|
id: record.id,
|
|
|
|
name: record.attributes.name,
|
|
|
|
email: record.attributes.email,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return guests;
|
|
|
|
}
|
2024-08-11 12:03:11 +02:00
|
|
|
|
2024-08-11 14:38:49 +02:00
|
|
|
const [guests, setGuests] = useState<Guest[]>(getData());
|
|
|
|
|
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">
|
|
|
|
<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">
|
|
|
|
Status
|
|
|
|
</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
2024-08-11 14:38:49 +02:00
|
|
|
<Suspense fallback="<tr><td colspan=3> Loading data</td></tr>">
|
|
|
|
{guests.map((guest) => (
|
|
|
|
<tr className="bg-white border-b odd:bg-white odd:dark:bg-gray-900 even:bg-gray-50 even:dark:bg-gray-800">
|
|
|
|
<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">
|
|
|
|
Confirmed
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
))}
|
|
|
|
</Suspense>
|
2024-08-11 13:12:03 +02:00
|
|
|
</tbody>
|
|
|
|
</table>
|
2024-08-11 12:03:11 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|