WIP load guests from API
This commit is contained in:
		
							parent
							
								
									8c6b19a96e
								
							
						
					
					
						commit
						231e33f76c
					
				@ -1,32 +1,29 @@
 | 
			
		||||
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';
 | 
			
		||||
import { Guest } from '@/app/lib/definitions';
 | 
			
		||||
'use client'
 | 
			
		||||
 | 
			
		||||
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',
 | 
			
		||||
    },
 | 
			
		||||
  ];
 | 
			
		||||
import { Guest } from '@/app/lib/definitions';
 | 
			
		||||
import { useState, Suspense } from 'react';
 | 
			
		||||
 | 
			
		||||
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">
 | 
			
		||||
@ -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