2024-11-13 08:16:10 +01:00
|
|
|
/* Copyright (C) 2024 Manuel Bustillo*/
|
|
|
|
|
|
|
|
'use client';
|
|
|
|
|
2024-12-09 00:36:42 +01:00
|
|
|
import { Group, GroupSerializer } from '@/app/lib/group';
|
2024-11-17 16:10:01 +01:00
|
|
|
import TableOfContents from '../components/table-of-contents';
|
2024-12-08 12:50:33 +01:00
|
|
|
import { PencilIcon, TrashIcon } from '@heroicons/react/24/outline';
|
2024-12-09 00:36:42 +01:00
|
|
|
import { AbstractApi } from '@/app/api/abstract-api';
|
2024-12-09 20:10:10 +01:00
|
|
|
import { TreeTable } from 'primereact/treetable';
|
|
|
|
import { Column } from 'primereact/column';
|
|
|
|
import { TreeNode } from 'primereact/treenode';
|
2024-11-13 08:16:10 +01:00
|
|
|
|
2024-12-08 12:50:33 +01:00
|
|
|
export default function GroupsTable({ groups, onUpdate, onEdit }: {
|
|
|
|
groups: Group[],
|
|
|
|
onUpdate: () => void,
|
|
|
|
onEdit: (group: Group) => void,
|
|
|
|
}) {
|
2024-11-13 08:16:10 +01:00
|
|
|
|
2024-12-09 00:36:42 +01:00
|
|
|
const api = new AbstractApi<Group>();
|
|
|
|
const serializer = new GroupSerializer();
|
|
|
|
|
2024-12-09 20:10:10 +01:00
|
|
|
const nodes:TreeNode[] = [];
|
|
|
|
|
|
|
|
const headers = ['Name', 'Color', 'Confirmed', 'Tentative', 'Pending', 'Declined', 'Considered', 'Total', 'Actions'];
|
|
|
|
|
2024-11-13 08:16:10 +01:00
|
|
|
return (
|
2024-12-09 20:10:10 +01:00
|
|
|
<>
|
|
|
|
<TreeTable value={nodes} tableStyle={{ minWidth: '50rem' }}>
|
|
|
|
{ headers.map((header, index) => <Column key={index} field={header} header={header}></Column>)}
|
|
|
|
|
|
|
|
</TreeTable>
|
|
|
|
|
|
|
|
<TableOfContents
|
|
|
|
headers={headers}
|
|
|
|
caption='Groups'
|
|
|
|
elements={groups}
|
|
|
|
rowRender={(group) => (
|
|
|
|
<tr key={group.id} className="bg-white border-b odd:bg-white odd:dark:bg-gray-900 even:bg-gray-50 even:dark:bg-gray-800">
|
|
|
|
<td scope="row" className="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white">
|
|
|
|
{group.name}
|
|
|
|
</td>
|
|
|
|
<td className="px-6">
|
|
|
|
<div className="w-8 h-8 rounded-full" style={{ backgroundColor: group.color }}></div>
|
|
|
|
</td>
|
|
|
|
<td className="px-6 text-lg">
|
|
|
|
{group.attendance?.confirmed}
|
|
|
|
</td>
|
|
|
|
<td className="px-6 text-sm">
|
|
|
|
{group.attendance?.tentative}
|
|
|
|
</td>
|
|
|
|
<td className="px-6 text-sm">
|
|
|
|
{group.attendance?.invited}
|
|
|
|
</td>
|
|
|
|
<td className="px-6 text-sm">
|
|
|
|
{group.attendance?.declined}
|
|
|
|
</td>
|
|
|
|
<td className="px-6 text-sm">
|
|
|
|
{group.attendance?.considered}
|
|
|
|
</td>
|
|
|
|
<td className="px-6 text-sm">
|
|
|
|
{group.attendance?.total}
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<div className="flex flex-row items-center">
|
|
|
|
<TrashIcon className='size-6 cursor-pointer' onClick={() => { api.destroy(serializer, group, onUpdate) }} />
|
|
|
|
<PencilIcon className='size-6 cursor-pointer' onClick={() => onEdit(group)} />
|
|
|
|
</div>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</>
|
2024-11-13 08:16:10 +01:00
|
|
|
)
|
|
|
|
}
|