/* Copyright (C) 2024 Manuel Bustillo*/ 'use client'; import { AbstractApi, } from '@/app/api/abstract-api'; import { Group, GroupSerializer } from '@/app/lib/group'; import { Guest, GuestSerializer } from '@/app/lib/guest'; import AffinitiesFormDialog from '@/app/ui/components/affinities-form-dialog'; import { classNames } from '@/app/ui/components/button'; import GroupFormDialog from '@/app/ui/components/group-form-dialog'; import GuestFormDialog from '@/app/ui/components/guest-form-dialog'; import GroupsTable from '@/app/ui/groups/table'; import SkeletonTable from '@/app/ui/guests/skeleton-row'; import GuestsTable from '@/app/ui/guests/table'; import { TabPanel, TabView } from 'primereact/tabview'; import { Suspense, useState } from 'react'; export default function Page() { function refreshGuests() { new AbstractApi().getAll(new GuestSerializer(), (objects: Guest[]) => { setGuests(objects); setGuestsLoaded(true); }); } function refreshGroups() { new AbstractApi().getAll(new GroupSerializer(), (objects: Group[]) => { setGroups(objects); setGroupsLoaded(true); }); } const [groupsLoaded, setGroupsLoaded] = useState(false); const [groups, setGroups] = useState>([]); const [groupBeingEdited, setGroupBeingEdited] = useState(undefined); const [groupAffinitiesBeingEditted, setGroupAffinitiesBeingEditted] = useState(undefined); const [guestsLoaded, setGuestsLoaded] = useState(false); const [guests, setGuests] = useState>([]); const [guestBeingEdited, setGuestBeingEdited] = useState(undefined); !groupsLoaded && refreshGroups(); !guestsLoaded && refreshGuests(); return (
{ refreshGuests(); setGuestBeingEdited(undefined) }} guest={guestBeingEdited} visible={guestBeingEdited !== undefined} onHide={() => { setGuestBeingEdited(undefined) }} /> }> setGuestBeingEdited(guest)} />
{ refreshGroups(); setGroupBeingEdited(undefined) }} group={groupBeingEdited} visible={groupBeingEdited !== undefined} onHide={() => { setGroupBeingEdited(undefined) }} /> { setGroupAffinitiesBeingEditted(undefined) }} /> }> setGroupBeingEdited(group)} onEditAffinities={(group) => setGroupAffinitiesBeingEditted(group)} />
); }