Compare commits

..

1 Commits

Author SHA1 Message Date
Renovate Bot
3a98c78465 Update dependency @heroicons/react to v2.1.5 2024-08-11 16:03:53 +00:00
3 changed files with 9 additions and 33 deletions

View File

@ -20,17 +20,8 @@ export type Guest = {
id: string; id: string;
name: string; name: string;
email: string; email: string;
group_name: string;
} }
export type Group = {
id: string;
name: string;
guest_count: number;
icon: string;
children: Group[];
};
export type Invoice = { export type Invoice = {
id: string; id: string;
customer_id: string; customer_id: string;

View File

@ -1,41 +1,27 @@
'use client' 'use client'
import React, { useState, useEffect, Suspense } from 'react'; import React, { useState, useEffect, Suspense } from 'react';
import { Tree, TreeNode } from 'primereact/tree'; import { Tree } from 'primereact/tree';
import { PrimeIcons } from 'primereact/api'; import { PrimeIcons } from 'primereact/api';
import { debug } from 'console'; import { debug } from 'console';
import { Group } from '@/app/lib/definitions';
export default function AffinityGroupsTree() { export default function AffinityGroupsTree() {
const [nodes, setNodes] = useState([]); const [nodes, setNodes] = useState([]);
const parseNode = (record: any, included: any[]) => {
const groupToNode = (group: Group): TreeNode => {
return({
key: group.id,
label: `${group.name} (${group.guest_count})`,
icon: group.icon,
children: group.children.map((child) => groupToNode(child)),
className: "px-4",
})
}
const parseNode = (record: any, included: any[]): Group => {
if (!record.attributes) { if (!record.attributes) {
record = included.find((a) => a.id === record.id); record = included.find((a) => a.id === record.id);
} }
const children: Group[] = (record?.relationships?.children?.data || []).map((child: any) => { const children = (record?.relationships?.children?.data || []).map((child: any) => {
return (parseNode(child, included)); return (parseNode(child, included));
}); });
const children_guest_count: number = children.reduce((acc: number, child: Group) => acc + child.guest_count, 0);
return ({ return ({
id: record.id, key: record.id,
name: record.attributes.name, label: record.attributes.name,
guest_count: record.attributes.guest_count + children_guest_count,
icon: record.attributes.icon, icon: record.attributes.icon,
children: children, children: children,
className: "px-4",
}) })
} }
@ -48,7 +34,7 @@ export default function AffinityGroupsTree() {
.then((response) => response.json()) .then((response) => response.json())
.then((data) => { .then((data) => {
setNodes(data.data.map((record: any) => { setNodes(data.data.map((record: any) => {
return (groupToNode(parseNode(record, data.included))); return (parseNode(record, data.included));
})) }))
}); });
}); });

View File

@ -19,7 +19,6 @@ export default function guestsTable() {
id: record.id, id: record.id,
name: record.attributes.name, name: record.attributes.name,
email: record.attributes.email, email: record.attributes.email,
group_name: record.attributes.group_name
}); });
})) }))
}); });
@ -38,7 +37,7 @@ export default function guestsTable() {
Email Email
</th> </th>
<th scope="col" className="px-6 py-3"> <th scope="col" className="px-6 py-3">
Group Status
</th> </th>
</tr> </tr>
</thead> </thead>
@ -53,7 +52,7 @@ export default function guestsTable() {
{guest.email} {guest.email}
</td> </td>
<td className="px-6 py-4"> <td className="px-6 py-4">
{guest.group_name} Confirmed
</td> </td>
</tr> </tr>
))} ))}