2024-11-02 10:26:40 +00:00
|
|
|
/* Copyright (C) 2024 Manuel Bustillo*/
|
|
|
|
|
2024-11-02 11:24:48 +01:00
|
|
|
'use client';
|
|
|
|
|
|
|
|
import React, { useState } from 'react';
|
2024-12-09 20:57:30 +01:00
|
|
|
import { TableArrangement } from '@/app/lib/definitions';
|
2024-11-02 11:24:48 +01:00
|
|
|
import { lusitana } from '@/app/ui/fonts';
|
|
|
|
import { Table } from '@/app/ui/components/table';
|
2024-12-08 14:02:29 +01:00
|
|
|
import { getSlug } from '@/app/lib/utils';
|
2024-11-02 11:24:48 +01:00
|
|
|
|
|
|
|
export default function Arrangement({ id }: { id: string }) {
|
|
|
|
|
|
|
|
const [tables, setTables] = useState<Array<TableArrangement>>([]);
|
|
|
|
|
|
|
|
function loadTables() {
|
2024-12-08 14:02:29 +01:00
|
|
|
fetch(`/api/${getSlug()}/tables_arrangements/${id}`)
|
2024-11-02 11:24:48 +01:00
|
|
|
.then((response) => response.json())
|
|
|
|
.then((data) => {
|
|
|
|
setTables(data.map((record: any) => {
|
|
|
|
return ({
|
2024-11-02 12:52:12 +01:00
|
|
|
id: record.number,
|
2024-11-02 11:24:48 +01:00
|
|
|
guests: record.guests
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
}, (error) => {
|
|
|
|
return [];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
tables.length === 0 && loadTables();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="w-full">
|
|
|
|
<div className="w-full items-center justify-between">
|
2024-11-02 12:52:12 +01:00
|
|
|
<h1 className={`${lusitana.className} text-2xl my-5`}>Table distributions</h1>
|
2024-11-02 11:24:48 +01:00
|
|
|
<div className="flex flex-row flex-wrap justify-around">
|
|
|
|
{tables.map((table) => (
|
2024-11-03 08:18:24 +01:00
|
|
|
<Table key={table.number} guests={table.guests || []} style="rounded" />
|
2024-11-02 11:24:48 +01:00
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|