Include edit and delete buttons in the groups table
All checks were successful
Playwright Tests / test (pull_request) Has been skipped
Add copyright notice / copyright_notice (pull_request) Successful in 19s
Check usage of free licenses / build-static-assets (pull_request) Successful in 29s

This commit is contained in:
Manuel Bustillo 2024-12-08 12:50:33 +01:00
parent ad0b09c3df
commit fba1b81b4c
3 changed files with 39 additions and 5 deletions

View File

@ -56,7 +56,11 @@ 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>
@ -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>

View File

@ -65,3 +65,17 @@ export function createGroup(group: Group, onCreate?: () => void) {
}) })
.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));
}

View File

@ -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>
)} )}
/> />