2024-10-27 21:11:45 +00:00
|
|
|
/* Copyright (C) 2024 Manuel Bustillo*/
|
|
|
|
|
2024-11-17 16:10:01 +01:00
|
|
|
'use client';
|
|
|
|
|
|
|
|
import { Group, Guest } from '@/app/lib/definitions';
|
|
|
|
import CreationDialog from '@/app/ui/components/creation-dialog';
|
|
|
|
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 16:59:16 +01:00
|
|
|
import { loadGuests } from '@/app/api/guests';
|
2024-11-17 16:34:58 +01:00
|
|
|
import { loadGroups } from '@/app/api/groups';
|
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 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 16:32:10 +01:00
|
|
|
<CreationDialog groups={groups} onCreate={refreshGuests} />
|
2024-11-13 08:16:10 +01:00
|
|
|
<Suspense fallback={<SkeletonTable />}>
|
2024-11-17 17:50:06 +01:00
|
|
|
<GuestsTable guests={guests} onUpdate={refreshGuests} />
|
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
|
|
|
);
|
|
|
|
}
|