diff --git a/app/dashboard/tables/page.tsx b/app/dashboard/tables/page.tsx index 2aec187..7f55a77 100644 --- a/app/dashboard/tables/page.tsx +++ b/app/dashboard/tables/page.tsx @@ -1,13 +1,18 @@ /* Copyright (C) 2024 Manuel Bustillo*/ -import { lusitana } from '@/app/ui/fonts'; - -export default function Page () { +'use client'; + +import Arrangement from '@/app/ui/arrangements/arrangement'; +import React, { useState } from 'react'; +import ArrangementsTable from '@/app/ui/arrangements/arrangements-table'; + +export default function Page() { + const [currentArrangement, setCurrentArrangement] = useState(null); + return ( -
-
-

Table distributions

-
-
- ); + <> + + {currentArrangement && } + + ) } \ No newline at end of file diff --git a/app/lib/definitions.ts b/app/lib/definitions.ts index 70eacd2..48a5918 100644 --- a/app/lib/definitions.ts +++ b/app/lib/definitions.ts @@ -21,9 +21,24 @@ export type Customer = { export type Guest = { id: string; name: string; - email: string; - group_name: string; - status: 'Considered' | 'Invited' | 'Confirmed' | 'Declined' | 'Tentative'; + email?: string; + group_name?: string; + status?: 'Considered' | 'Invited' | 'Confirmed' | 'Declined' | 'Tentative'; +} + +export type Banana = { + id: string; + name: string; + email?: string; + group_name?: string; + status?: 'Considered' | 'Invited' | 'Confirmed' | 'Declined' | 'Tentative'; +} + +export type TableArrangement = { + id: string; + number: number; + guests?: Guest[]; + discomfort?: number } export type Group = { diff --git a/app/ui/arrangements/arrangement.tsx b/app/ui/arrangements/arrangement.tsx new file mode 100644 index 0000000..f51baea --- /dev/null +++ b/app/ui/arrangements/arrangement.tsx @@ -0,0 +1,44 @@ +/* Copyright (C) 2024 Manuel Bustillo*/ + +'use client'; + +import React, { useState } from 'react'; +import { TableArrangement, Guest } from '@/app/lib/definitions'; +import { lusitana } from '@/app/ui/fonts'; +import { Table } from '@/app/ui/components/table'; + +export default function Arrangement({ id }: { id: string }) { + + const [tables, setTables] = useState>([]); + + function loadTables() { + fetch(`/api/tables_arrangements/${id}`) + .then((response) => response.json()) + .then((data) => { + setTables(data.map((record: any) => { + return ({ + id: record.number, + guests: record.guests + }); + })); + }, (error) => { + return []; + }); + } + + tables.length === 0 && loadTables(); + + return ( +
+
+

Table distributions

+
+ {tables.map((table) => ( + + ))} + + + + ) + +} \ No newline at end of file diff --git a/app/ui/arrangements/arrangements-table.tsx b/app/ui/arrangements/arrangements-table.tsx new file mode 100644 index 0000000..12a2712 --- /dev/null +++ b/app/ui/arrangements/arrangements-table.tsx @@ -0,0 +1,73 @@ +/* Copyright (C) 2024 Manuel Bustillo*/ + +'use client' + +import React, { useState } from "react" +import { TableArrangement } from '@/app/lib/definitions'; +import { classNames } from "../components/button"; + +export default function ArrangementsTable ({onArrangementSelected}: {onArrangementSelected: (arrangementId: string) => void}) { + const [arrangements, setArrangements] = useState>([]); + + function loadArrangements() { + fetch("/api/tables_arrangements") + .then((response) => response.json()) + .then((data) => { + setArrangements(data.map((record: any) => { + return ({ + id: record.id, + discomfort: record.discomfort + }); + })); + }, (error) => { + return []; + }); + } + + function arrangementClicked(e: React.MouseEvent) { + onArrangementSelected(e.currentTarget.getAttribute('data-arrangement-id') || ''); + } + + arrangements.length === 0 && loadArrangements(); + + return( +
+
+ + + + + + + + + + {arrangements.map((arrangement) => ( + + + + + + ))} + +
+ Simulations +

+ There are {arrangements.length} simmulations in the list +

+
+ ID + + Discomfort + + Actions +
+ {arrangement.id} + + {arrangement.discomfort} + + +
+
+ ); +} \ No newline at end of file diff --git a/app/ui/components/button.tsx b/app/ui/components/button.tsx new file mode 100644 index 0000000..76906a2 --- /dev/null +++ b/app/ui/components/button.tsx @@ -0,0 +1,14 @@ +/* Copyright (C) 2024 Manuel Bustillo*/ + +import clsx from "clsx"; + +type ButtonColor = 'primary' | 'blue' | 'green' | 'red' | 'yellow'; + +export function classNames(type: ButtonColor) { + return(clsx("text-white py-1 px-2 mx-1 rounded", { + 'bg-blue-400 hover:bg-blue-600': type === 'primary' || type === 'blue', + 'bg-green-500 hover:bg-green-600': type === 'green', + 'bg-red-500 hover:bg-red-600': type === 'red', + 'bg-yellow-500 hover:bg-yellow-700': type === 'yellow' + })) +} \ No newline at end of file diff --git a/app/ui/components/table.tsx b/app/ui/components/table.tsx new file mode 100644 index 0000000..a042f4b --- /dev/null +++ b/app/ui/components/table.tsx @@ -0,0 +1,33 @@ +/* Copyright (C) 2024 Manuel Bustillo*/ + +import { Guest } from "@/app/lib/definitions"; + + +function GuestRow({ guests }: { guests: Guest[] }) { + return (
+ { + guests.map((guest) => { + + return ( +
+ {guest.name} +
+ ) + }) + } + +
) +} + +export function Table({ guests }: { guests: Guest[] }) { + const halfwayThrough = Math.floor(guests.length / 2) + const arrayFirstHalf = guests.slice(0, halfwayThrough); + const arraySecondHalf = guests.slice(halfwayThrough, guests.length); + + return ( +
+ + +
+ ) +} \ No newline at end of file diff --git a/app/ui/guests/table.tsx b/app/ui/guests/table.tsx index af2752b..7590738 100644 --- a/app/ui/guests/table.tsx +++ b/app/ui/guests/table.tsx @@ -6,6 +6,7 @@ import clsx from 'clsx'; import React, { useState, useEffect } from 'react'; import { Guest } from '@/app/lib/definitions'; import { getCsrfToken } from '@/app/lib/utils'; +import {classNames} from '@/app/ui/components/button'; export default function guestsTable() { const [guests, setGuests] = useState>([]); @@ -48,7 +49,6 @@ export default function guestsTable() { } guests.length === 0 && loadGuests(); - const ctaClassName = "text-white py-1 px-2 mx-1 rounded"; return (
@@ -105,14 +105,14 @@ export default function guestsTable() { - {guest.status === 'Considered' && ()} {(guest.status === 'Invited' || guest.status === 'Tentative') && ( <> - - {guest.status != 'Tentative' && } - + + {guest.status != 'Tentative' && } + )}