WIP load guests from API
This commit is contained in:
parent
8c6b19a96e
commit
231e33f76c
@ -1,33 +1,30 @@
|
||||
import Image from 'next/image';
|
||||
import { UpdateInvoice, DeleteInvoice } from '@/app/ui/guests/buttons';
|
||||
import gueststatus from '@/app/ui/guests/status';
|
||||
import { formatDateToLocal, formatCurrency } from '@/app/lib/utils';
|
||||
'use client'
|
||||
|
||||
import { Guest } from '@/app/lib/definitions';
|
||||
import { useState, Suspense } from 'react';
|
||||
|
||||
export default async function guestsTable() {
|
||||
const guests: Guest[] = [
|
||||
{
|
||||
id: '1',
|
||||
name: 'John Doe',
|
||||
email: 'foo@bar.com'
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
name: 'Jane Doe',
|
||||
email: 'jane@bar.com',
|
||||
},
|
||||
{
|
||||
id: '3',
|
||||
name: 'John Doe',
|
||||
email: 'foo@bar.com'
|
||||
},
|
||||
{
|
||||
id: '4',
|
||||
name: 'Jane Doe',
|
||||
email: 'jane@bar.com',
|
||||
},
|
||||
];
|
||||
export default function guestsTable() {
|
||||
|
||||
const url = "http://localhost:3001/guests.json";
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
const [guests, setGuests] = useState<Guest[]>(getData());
|
||||
|
||||
return (
|
||||
<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">
|
||||
@ -45,19 +42,21 @@ export default async function guestsTable() {
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{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 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>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user