2024-10-27 21:11:45 +00:00
|
|
|
/* Copyright (C) 2024 Manuel Bustillo*/
|
|
|
|
|
2024-11-17 16:10:01 +01:00
|
|
|
'use client';
|
|
|
|
|
2024-11-17 19:18:20 +01:00
|
|
|
import { loadGroups } from '@/app/api/groups';
|
|
|
|
import { loadGuests } from '@/app/api/guests';
|
2024-11-17 16:10:01 +01:00
|
|
|
import { Group, Guest } from '@/app/lib/definitions';
|
2024-11-17 19:18:20 +01:00
|
|
|
import { classNames } from '@/app/ui/components/button';
|
|
|
|
import GuestFormDialog from '@/app/ui/components/guest-form-dialog';
|
2024-11-17 16:10:01 +01:00
|
|
|
import GroupsTable from '@/app/ui/groups/table';
|
2024-08-18 18:41:44 +02:00
|
|
|
import SkeletonTable from '@/app/ui/guests/skeleton-row';
|
2024-11-17 16:10:01 +01:00
|
|
|
import GuestsTable from '@/app/ui/guests/table';
|
|
|
|
import { TabPanel, TabView } from 'primereact/tabview';
|
|
|
|
import { Suspense, useState } from 'react';
|
2024-11-17 19:18:20 +01:00
|
|
|
|
2024-08-11 13:12:03 +02:00
|
|
|
|
|
|
|
export default function Page() {
|
2024-11-17 16:32:10 +01:00
|
|
|
function refreshGuests() {
|
|
|
|
loadGuests((guests) => {
|
|
|
|
setGuests(guests);
|
|
|
|
setGuestsLoaded(true);
|
|
|
|
});
|
2024-11-17 16:10:01 +01:00
|
|
|
}
|
|
|
|
|
2024-11-17 16:34:58 +01:00
|
|
|
function refreshGroups() {
|
|
|
|
loadGroups((groups) => {
|
|
|
|
setGroups(groups);
|
|
|
|
setGroupsLoaded(true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-11-17 16:10:01 +01:00
|
|
|
const [groupsLoaded, setGroupsLoaded] = useState(false);
|
|
|
|
const [groups, setGroups] = useState<Array<Group>>([]);
|
|
|
|
|
|
|
|
const [guestsLoaded, setGuestsLoaded] = useState(false);
|
|
|
|
const [guests, setGuests] = useState<Array<Guest>>([]);
|
2024-11-17 19:18:20 +01:00
|
|
|
const [guestBeingEdited, setGuestBeingEdited] = useState<Guest | undefined>(undefined);
|
2024-11-17 16:10:01 +01:00
|
|
|
|
2024-11-17 16:34:58 +01:00
|
|
|
!groupsLoaded && refreshGroups();
|
2024-11-17 16:32:10 +01:00
|
|
|
!guestsLoaded && refreshGuests();
|
2024-11-17 16:10:01 +01:00
|
|
|
|
2024-08-11 12:34:16 +02:00
|
|
|
return (
|
|
|
|
<div className="w-full">
|
2024-11-13 08:16:10 +01:00
|
|
|
<TabView>
|
|
|
|
<TabPanel header="Guests" leftIcon="pi pi-users mx-2">
|
2024-11-17 16:10:01 +01:00
|
|
|
<div className="flex flex-col w-full items-center justify-between">
|
2024-11-17 19:18:20 +01:00
|
|
|
<button onClick={() => setGuestBeingEdited({})} className={classNames('primary')}>Add new</button>
|
|
|
|
<GuestFormDialog
|
|
|
|
key={guestBeingEdited?.id}
|
|
|
|
groups={groups}
|
|
|
|
onCreate={() => { refreshGuests(); setGuestBeingEdited(undefined) }}
|
|
|
|
guest={guestBeingEdited}
|
|
|
|
visible={guestBeingEdited !== undefined}
|
|
|
|
onHide={() => { setGuestBeingEdited(undefined) }}
|
|
|
|
/>
|
2024-11-13 08:16:10 +01:00
|
|
|
<Suspense fallback={<SkeletonTable />}>
|
2024-11-17 19:18:20 +01:00
|
|
|
<GuestsTable guests={guests} onUpdate={refreshGuests} onEdit={(guest) => setGuestBeingEdited(guest)} />
|
2024-11-13 08:16:10 +01:00
|
|
|
</Suspense>
|
|
|
|
</div>
|
|
|
|
</ TabPanel>
|
|
|
|
<TabPanel header="Groups" leftIcon="pi pi-sitemap mx-2">
|
|
|
|
<div className="flex w-full items-center justify-between">
|
|
|
|
<Suspense fallback={<SkeletonTable />}>
|
2024-11-17 16:10:01 +01:00
|
|
|
<GroupsTable groups={groups} />
|
2024-11-13 08:16:10 +01:00
|
|
|
</Suspense>
|
|
|
|
</div>
|
|
|
|
</ TabPanel>
|
|
|
|
</ TabView>
|
2024-08-11 12:34:16 +02:00
|
|
|
</div>
|
2024-11-13 08:16:10 +01:00
|
|
|
|
2024-08-11 12:34:16 +02:00
|
|
|
);
|
|
|
|
}
|