Include edit and delete buttons in the groups table
This commit is contained in:
parent
ad0b09c3df
commit
fba1b81b4c
@ -56,14 +56,18 @@ export default function Page() {
|
|||||||
onHide={() => { setGuestBeingEdited(undefined) }}
|
onHide={() => { setGuestBeingEdited(undefined) }}
|
||||||
/>
|
/>
|
||||||
<Suspense fallback={<SkeletonTable />}>
|
<Suspense fallback={<SkeletonTable />}>
|
||||||
<GuestsTable guests={guests} onUpdate={refreshGuests} onEdit={(guest) => setGuestBeingEdited(guest)} />
|
<GuestsTable
|
||||||
|
guests={guests}
|
||||||
|
onUpdate={refreshGuests}
|
||||||
|
onEdit={(guest) => setGuestBeingEdited(guest)}
|
||||||
|
/>
|
||||||
</Suspense>
|
</Suspense>
|
||||||
</div>
|
</div>
|
||||||
</ TabPanel>
|
</ TabPanel>
|
||||||
<TabPanel header="Groups" leftIcon="pi pi-sitemap mx-2">
|
<TabPanel header="Groups" leftIcon="pi pi-sitemap mx-2">
|
||||||
<div className="flex flex-col w-full items-center justify-between">
|
<div className="flex flex-col w-full items-center justify-between">
|
||||||
|
|
||||||
<button onClick={() => setGroupBeingEdited({})} className={classNames('primary')}>Add new</button>
|
<button onClick={() => setGroupBeingEdited({})} className={classNames('primary')}>Add new</button>
|
||||||
<GroupFormDialog
|
<GroupFormDialog
|
||||||
key={groupBeingEdited?.id}
|
key={groupBeingEdited?.id}
|
||||||
groups={groups}
|
groups={groups}
|
||||||
@ -74,7 +78,11 @@ export default function Page() {
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<Suspense fallback={<SkeletonTable />}>
|
<Suspense fallback={<SkeletonTable />}>
|
||||||
<GroupsTable groups={groups} />
|
<GroupsTable
|
||||||
|
groups={groups}
|
||||||
|
onUpdate={refreshGroups}
|
||||||
|
onEdit={(group) => setGroupBeingEdited(group)}
|
||||||
|
/>
|
||||||
</Suspense>
|
</Suspense>
|
||||||
</div>
|
</div>
|
||||||
</ TabPanel>
|
</ TabPanel>
|
||||||
|
@ -64,4 +64,18 @@ export function createGroup(group: Group, onCreate?: () => void) {
|
|||||||
onCreate && onCreate();
|
onCreate && onCreate();
|
||||||
})
|
})
|
||||||
.catch((error) => console.error(error));
|
.catch((error) => console.error(error));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function destroyGroup(group: Group, onDestroy?: () => void) {
|
||||||
|
fetch(`/api/${getSlug()}/groups/${group.id}`, {
|
||||||
|
method: 'DELETE',
|
||||||
|
headers: {
|
||||||
|
'X-CSRF-TOKEN': getCsrfToken(),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then((response) => response.json())
|
||||||
|
.then((data) => {
|
||||||
|
onDestroy && onDestroy();
|
||||||
|
})
|
||||||
|
.catch((error) => console.error(error));
|
||||||
}
|
}
|
@ -4,12 +4,18 @@
|
|||||||
|
|
||||||
import { Group } from '@/app/lib/definitions';
|
import { Group } from '@/app/lib/definitions';
|
||||||
import TableOfContents from '../components/table-of-contents';
|
import TableOfContents from '../components/table-of-contents';
|
||||||
|
import { PencilIcon, TrashIcon } from '@heroicons/react/24/outline';
|
||||||
|
import { destroyGroup } from '@/app/api/groups';
|
||||||
|
|
||||||
export default function GroupsTable({ groups }: { groups: Group[] }) {
|
export default function GroupsTable({ groups, onUpdate, onEdit }: {
|
||||||
|
groups: Group[],
|
||||||
|
onUpdate: () => void,
|
||||||
|
onEdit: (group: Group) => void,
|
||||||
|
}) {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TableOfContents
|
<TableOfContents
|
||||||
headers={['Name', 'Color', 'Confirmed', 'Tentative', 'Pending', 'Declined', 'Considered', 'Total']}
|
headers={['Name', 'Color', 'Confirmed', 'Tentative', 'Pending', 'Declined', 'Considered', 'Total', 'Actions']}
|
||||||
caption='Groups'
|
caption='Groups'
|
||||||
elements={groups}
|
elements={groups}
|
||||||
rowRender={(group) => (
|
rowRender={(group) => (
|
||||||
@ -38,6 +44,12 @@ export default function GroupsTable({ groups }: { groups: Group[] }) {
|
|||||||
<td className="px-6 text-sm">
|
<td className="px-6 text-sm">
|
||||||
{group.attendance?.total}
|
{group.attendance?.total}
|
||||||
</td>
|
</td>
|
||||||
|
<td>
|
||||||
|
<div className="flex flex-row items-center">
|
||||||
|
<TrashIcon className='size-6 cursor-pointer' onClick={() => { destroyGroup(group, () => onUpdate()) }} />
|
||||||
|
<PencilIcon className='size-6 cursor-pointer' onClick={() => onEdit(group)} />
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user