From 231e33f76cd32086bb55af9d44b4cc73b4793c0e Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Sun, 11 Aug 2024 14:38:49 +0200 Subject: [PATCH] WIP load guests from API --- app/ui/guests/table.tsx | 79 ++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 40 deletions(-) diff --git a/app/ui/guests/table.tsx b/app/ui/guests/table.tsx index 7a31193..3f7d263 100644 --- a/app/ui/guests/table.tsx +++ b/app/ui/guests/table.tsx @@ -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(getData()); + return (
@@ -45,19 +42,21 @@ export default async function guestsTable() { - {guests.map((guest) => ( - - - - - - ))} + + {guests.map((guest) => ( + + + + + + ))} +
- {guest.name} - - {guest.email} - - Confirmed -
+ {guest.name} + + {guest.email} + + Confirmed +