Compare commits
1 Commits
main
...
invitation
Author | SHA1 | Date | |
---|---|---|---|
faf0ee4dbd |
@ -2,41 +2,15 @@
|
||||
|
||||
'use client';
|
||||
|
||||
import { AbstractApi } from '@/app/api/abstract-api';
|
||||
import { TableSimulation, TableSimulationSerializer } from '@/app/lib/tableSimulation';
|
||||
import Arrangement from '@/app/ui/arrangements/arrangement';
|
||||
import React, { useState } from 'react';
|
||||
import ArrangementsTable from '@/app/ui/arrangements/arrangements-table';
|
||||
import { classNames } from '@/app/ui/components/button';
|
||||
import { Toast } from 'primereact/toast';
|
||||
import React, { useRef, useState } from 'react';
|
||||
|
||||
export default function Page() {
|
||||
const toast = useRef<Toast>(null);
|
||||
|
||||
const show = () => {
|
||||
toast.current?.show({
|
||||
severity: 'success',
|
||||
summary: 'Simulation created',
|
||||
detail: 'Table distributions will be calculated shortly, please come back in some minutes'
|
||||
});
|
||||
};
|
||||
|
||||
const [currentArrangement, setCurrentArrangement] = useState<string | null>(null);
|
||||
|
||||
function createSimulation() {
|
||||
const api = new AbstractApi<TableSimulation>();
|
||||
const serializer = new TableSimulationSerializer();
|
||||
api.create(serializer, new TableSimulation(), show);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
<div className="flex flex-col w-full items-center justify-between">
|
||||
<Toast ref={toast} />
|
||||
<button onClick={createSimulation} className={classNames('primary')}>Add new</button>
|
||||
</div>
|
||||
|
||||
<ArrangementsTable onArrangementSelected={setCurrentArrangement} />
|
||||
{currentArrangement && <Arrangement key={currentArrangement} id={currentArrangement} />}
|
||||
</>
|
||||
|
@ -12,7 +12,6 @@ export function loadTableSimulations(onLoad?: (tableSimulations: TableArrangemen
|
||||
id: record.id,
|
||||
name: record.name,
|
||||
discomfort: record.discomfort,
|
||||
valid: record.valid,
|
||||
});
|
||||
}));
|
||||
}, (error) => {
|
||||
|
@ -12,8 +12,7 @@ export type TableArrangement = {
|
||||
number: number;
|
||||
name: string;
|
||||
guests?: Guest[];
|
||||
discomfort?: number;
|
||||
valid?: boolean;
|
||||
discomfort?: number
|
||||
}
|
||||
|
||||
export type User = {
|
||||
|
@ -14,8 +14,9 @@ export class Guest implements Entity {
|
||||
color?: string;
|
||||
status?: GuestStatus;
|
||||
children?: Guest[];
|
||||
invitationId?: string;
|
||||
|
||||
constructor(id?: string, name?: string, group_name?: string, groupId?: string, color?: string, status?: GuestStatus, children?: Guest[]) {
|
||||
constructor(id?: string, name?: string, group_name?: string, groupId?: string, color?: string, status?: GuestStatus, children?: Guest[], invitationId?: string) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.group_name = group_name;
|
||||
@ -23,12 +24,13 @@ export class Guest implements Entity {
|
||||
this.color = color;
|
||||
this.status = status;
|
||||
this.children = children;
|
||||
this.invitationId = invitationId;
|
||||
}
|
||||
}
|
||||
|
||||
export class GuestSerializer implements Serializable<Guest> {
|
||||
fromJson(data: any): Guest {
|
||||
return new Guest(data.id, data.name, data.group?.name, data.group?.id, data.color, data.status, data.children);
|
||||
return new Guest(data.id, data.name, data.group?.name, data.group?.id, data.color, data.status, data.children, data.invitation_id);
|
||||
}
|
||||
|
||||
toJson(guest: Guest): string {
|
||||
|
@ -19,12 +19,12 @@ export type Table = {
|
||||
}
|
||||
|
||||
export class TableSimulation implements Entity {
|
||||
id?: string;
|
||||
id: string;
|
||||
tables: Table[];
|
||||
|
||||
constructor(id?: string, tables?: Table[]) {
|
||||
constructor(id: string, tables: Table[]) {
|
||||
this.id = id;
|
||||
this.tables = tables || [];
|
||||
this.tables = tables;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,57 +7,42 @@ import { TableArrangement } from '@/app/lib/definitions';
|
||||
import { classNames } from "../components/button";
|
||||
import TableOfContents from "../components/table-of-contents";
|
||||
import { loadTableSimulations } from "@/app/api/tableSimulations";
|
||||
import { ArchiveBoxXMarkIcon, CheckBadgeIcon } from "@heroicons/react/24/outline";
|
||||
import { Tooltip } from "primereact/tooltip";
|
||||
import clsx from "clsx";
|
||||
|
||||
export default function ArrangementsTable({ onArrangementSelected }: { onArrangementSelected: (arrangementId: string) => void }) {
|
||||
const [arrangements, setArrangements] = useState<Array<TableArrangement>>([]);
|
||||
const [arrangementsLoaded, setArrangementsLoaded] = useState(false);
|
||||
export default function ArrangementsTable ({onArrangementSelected}: {onArrangementSelected: (arrangementId: string) => void}) {
|
||||
const [arrangements, setArrangements] = useState<Array<TableArrangement>>([]);
|
||||
const [arrangementsLoaded, setArrangementsLoaded] = useState(false);
|
||||
|
||||
function refreshSimulations() {
|
||||
loadTableSimulations((arrangements) => {
|
||||
setArrangements(arrangements);
|
||||
setArrangementsLoaded(true);
|
||||
});
|
||||
}
|
||||
function refreshSimulations() {
|
||||
loadTableSimulations((arrangements) => {
|
||||
setArrangements(arrangements);
|
||||
setArrangementsLoaded(true);
|
||||
});
|
||||
}
|
||||
|
||||
function arrangementClicked(e: React.MouseEvent<HTMLElement>) {
|
||||
onArrangementSelected(e.currentTarget.getAttribute('data-arrangement-id') || '');
|
||||
}
|
||||
function arrangementClicked(e: React.MouseEvent<HTMLElement>) {
|
||||
onArrangementSelected(e.currentTarget.getAttribute('data-arrangement-id') || '');
|
||||
}
|
||||
|
||||
!arrangementsLoaded && refreshSimulations();
|
||||
!arrangementsLoaded && refreshSimulations();
|
||||
|
||||
return (
|
||||
<TableOfContents
|
||||
headers={['Name', 'Discomfort', 'Actions', 'Status']}
|
||||
caption='Simulations'
|
||||
elements={arrangements}
|
||||
rowRender={(arrangement) => (
|
||||
<tr key={arrangement.id} className={clsx("border-b", {
|
||||
"bg-white odd:bg-white even:bg-gray-50": arrangement.valid,
|
||||
"bg-red-50 odd:bg-red-50 even:bg-red-100": !arrangement.valid
|
||||
})}>
|
||||
<th scope="row" className="px-6 py-4 font-medium text-gray-900 whitespace-nowrap">
|
||||
{arrangement.name}
|
||||
</th>
|
||||
<td className="px-6 py-4">
|
||||
{arrangement.discomfort}
|
||||
</td>
|
||||
<td>
|
||||
<button data-arrangement-id={arrangement.id} onClick={arrangementClicked} className={classNames('primary')}>Load</button>
|
||||
</td>
|
||||
<td>
|
||||
<Tooltip target=".tooltip-status" />
|
||||
|
||||
{
|
||||
arrangement.valid ?
|
||||
<CheckBadgeIcon className='size-6 tooltip-status' data-pr-position="right" data-pr-tooltip="Simulation is valid" /> :
|
||||
<ArchiveBoxXMarkIcon className='size-6 tooltip-status' data-pr-position="right" data-pr-tooltip="Simulation is expired due to attendance or affinity changes" />
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
/>
|
||||
);
|
||||
return(
|
||||
<TableOfContents
|
||||
headers={['Name', 'Discomfort', 'Actions']}
|
||||
caption='Simulations'
|
||||
elements={arrangements}
|
||||
rowRender={(arrangement) => (
|
||||
<tr key={arrangement.id} 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">
|
||||
{arrangement.name}
|
||||
</th>
|
||||
<td className="px-6 py-4">
|
||||
{arrangement.discomfort}
|
||||
</td>
|
||||
<td>
|
||||
<button data-arrangement-id={arrangement.id} onClick={arrangementClicked} className={classNames('primary')}>Load</button>
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
/>
|
||||
);
|
||||
}
|
@ -3,9 +3,10 @@
|
||||
'use client';
|
||||
|
||||
import { AbstractApi } from '@/app/api/abstract-api';
|
||||
import { Guest , GuestSerializer} from '@/app/lib/guest';
|
||||
import { PencilIcon, TrashIcon } from '@heroicons/react/24/outline';
|
||||
import { Guest, GuestSerializer } from '@/app/lib/guest';
|
||||
import { EnvelopeIcon, FunnelIcon, PencilIcon, TrashIcon, UserPlusIcon } from '@heroicons/react/24/outline';
|
||||
import clsx from 'clsx';
|
||||
import { useState } from 'react';
|
||||
import TableOfContents from '../components/table-of-contents';
|
||||
|
||||
export default function guestsTable({ guests, onUpdate, onEdit }: {
|
||||
@ -16,22 +17,40 @@ export default function guestsTable({ guests, onUpdate, onEdit }: {
|
||||
|
||||
const api = new AbstractApi<Guest>();
|
||||
const serializer = new GuestSerializer();
|
||||
const [invitationId, setInvitationId] = useState<string | undefined>(undefined);
|
||||
const [selecting, setSelecting] = useState<boolean>(false);
|
||||
|
||||
function toggleInvitationId(id: string | undefined) {
|
||||
console.log('toggleInvitationId', id, invitationId);
|
||||
|
||||
if (id === invitationId) {
|
||||
setInvitationId(undefined);
|
||||
} else {
|
||||
setInvitationId(id);
|
||||
}
|
||||
|
||||
console.log('invitationId', invitationId);
|
||||
}
|
||||
|
||||
return (
|
||||
<TableOfContents
|
||||
headers={['Name', 'Group', 'Status', 'Actions']}
|
||||
headers={['Name', 'Group', 'Status', 'Invitation', 'Actions']}
|
||||
caption='Guests'
|
||||
elements={guests}
|
||||
rowRender={(guest) => (
|
||||
<tr key={guest.id} className="bg-white border-b odd:bg-white odd:dark:bg-gray-900 even:bg-gray-50 even:dark:bg-gray-800">
|
||||
<td scope="row" className="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white">
|
||||
<tr key={guest.id} className={clsx("bg-white odd:bg-white even:bg-gray-50 border-b", {
|
||||
"opacity-25": invitationId && !selecting && guest.invitationId !== invitationId,
|
||||
"hover:bg-emerald-100" : selecting && guest.invitationId !== invitationId && guest.status !== 'considered',
|
||||
"opacity-25 hover:cursor-not-allowed" : selecting && (guest.invitationId === invitationId || guest.status === 'considered')
|
||||
})} >
|
||||
<td scope="row" className="px-6 py-4 font-medium text-gray-900 whitespace-nowrap">
|
||||
{guest.name}
|
||||
</td>
|
||||
<td className="px-6 py-4">
|
||||
{guest.group_name}
|
||||
</td>
|
||||
<td className="px-6 py-4">
|
||||
<span className="flex items-center text-sm dark:text-white me-3">
|
||||
<span className="flex items-center text-sm me-3">
|
||||
<span className={clsx(
|
||||
'flex w-2.5 h-2.5 rounded-full me-1.5 flex-shrink-0',
|
||||
{
|
||||
@ -46,10 +65,21 @@ export default function guestsTable({ guests, onUpdate, onEdit }: {
|
||||
{guest.status}
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
{
|
||||
guest.invitationId &&
|
||||
<div className="flex">
|
||||
{!selecting && <FunnelIcon className='size-6 cursor-pointer' onClick={() => toggleInvitationId(guest?.invitationId)} />}
|
||||
{ invitationId === guest.invitationId && !selecting && <UserPlusIcon className='size-6 cursor-pointer' onClick={() => setSelecting(!selecting)}/>}
|
||||
{ selecting && invitationId !== guest.invitationId && <UserPlusIcon className='size-6 cursor-pointer' />}
|
||||
</div>
|
||||
}
|
||||
</td>
|
||||
<td>
|
||||
<div className="flex flex-row items-center">
|
||||
<TrashIcon className='size-6 cursor-pointer' onClick={() => { api.destroy(serializer, guest, onUpdate)}} />
|
||||
<TrashIcon className='size-6 cursor-pointer' onClick={() => { api.destroy(serializer, guest, onUpdate) }} />
|
||||
<PencilIcon className='size-6 cursor-pointer' onClick={() => onEdit(guest)} />
|
||||
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
18
package.json
18
package.json
@ -8,31 +8,31 @@
|
||||
"dependencies": {
|
||||
"@heroicons/react": "^2.1.4",
|
||||
"@tailwindcss/forms": "^0.5.7",
|
||||
"autoprefixer": "10.4.21",
|
||||
"autoprefixer": "10.4.20",
|
||||
"bcrypt": "^5.1.1",
|
||||
"clsx": "^2.1.1",
|
||||
"next": "15.3.1",
|
||||
"next": "15.1.6",
|
||||
"next-auth": "5.0.0-beta.25",
|
||||
"postcss": "8.5.3",
|
||||
"postcss": "8.5.1",
|
||||
"primeicons": "^7.0.0",
|
||||
"primereact": "^10.8.2",
|
||||
"react": "19.0.0-rc-f38c22b244-20240704",
|
||||
"react-dom": "19.0.0-rc-f38c22b244-20240704",
|
||||
"tailwindcss": "3.4.17",
|
||||
"typescript": "5.8.3",
|
||||
"typescript": "5.7.3",
|
||||
"use-debounce": "^10.0.1",
|
||||
"uuid": "11.1.0",
|
||||
"uuid": "11.0.5",
|
||||
"zod": "^3.23.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@playwright/test": "^1.46.0",
|
||||
"@types/bcrypt": "^5.0.2",
|
||||
"@types/node": "22.14.1",
|
||||
"@types/react": "18.3.20",
|
||||
"@types/react-dom": "18.3.6"
|
||||
"@types/node": "22.10.10",
|
||||
"@types/react": "18.3.18",
|
||||
"@types/react-dom": "18.3.5"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=23.0.0"
|
||||
},
|
||||
"packageManager": "pnpm@9.15.9+sha512.68046141893c66fad01c079231128e9afb89ef87e2691d69e4d40eee228988295fd4682181bae55b58418c3a253bde65a505ec7c5f9403ece5cc3cd37dcf2531"
|
||||
"packageManager": "pnpm@9.15.4+sha512.b2dc20e2fc72b3e18848459b37359a32064663e5627a51e4c74b2c29dd8e8e0491483c3abb40789cfd578bf362fb6ba8261b05f0387d76792ed6e23ea3b1b6a0"
|
||||
}
|
||||
|
520
pnpm-lock.yaml
generated
520
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user