Compare commits
3 Commits
3a98c78465
...
0b1d65a9bf
Author | SHA1 | Date | |
---|---|---|---|
![]() |
0b1d65a9bf | ||
e62cd65709 | |||
5d6aa68f63 |
@ -20,8 +20,17 @@ 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;
|
||||||
|
@ -1,27 +1,41 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import React, { useState, useEffect, Suspense } from 'react';
|
import React, { useState, useEffect, Suspense } from 'react';
|
||||||
import { Tree } from 'primereact/tree';
|
import { Tree, TreeNode } 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 = (record?.relationships?.children?.data || []).map((child: any) => {
|
const children: Group[] = (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 ({
|
||||||
key: record.id,
|
id: record.id,
|
||||||
label: record.attributes.name,
|
name: 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",
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,7 +48,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 (parseNode(record, data.included));
|
return (groupToNode(parseNode(record, data.included)));
|
||||||
}))
|
}))
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -19,6 +19,7 @@ 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
|
||||||
});
|
});
|
||||||
}))
|
}))
|
||||||
});
|
});
|
||||||
@ -37,7 +38,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">
|
||||||
Status
|
Group
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@ -52,7 +53,7 @@ export default function guestsTable() {
|
|||||||
{guest.email}
|
{guest.email}
|
||||||
</td>
|
</td>
|
||||||
<td className="px-6 py-4">
|
<td className="px-6 py-4">
|
||||||
Confirmed
|
{guest.group_name}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
))}
|
))}
|
||||||
|
8
pnpm-lock.yaml
generated
8
pnpm-lock.yaml
generated
@ -10,7 +10,7 @@ importers:
|
|||||||
dependencies:
|
dependencies:
|
||||||
'@heroicons/react':
|
'@heroicons/react':
|
||||||
specifier: ^2.1.4
|
specifier: ^2.1.4
|
||||||
version: 2.1.4(react@19.0.0-rc-f38c22b244-20240704)
|
version: 2.1.5(react@19.0.0-rc-f38c22b244-20240704)
|
||||||
'@tailwindcss/forms':
|
'@tailwindcss/forms':
|
||||||
specifier: ^0.5.7
|
specifier: ^0.5.7
|
||||||
version: 0.5.7(tailwindcss@3.4.4)
|
version: 0.5.7(tailwindcss@3.4.4)
|
||||||
@ -100,8 +100,8 @@ packages:
|
|||||||
'@emnapi/runtime@1.2.0':
|
'@emnapi/runtime@1.2.0':
|
||||||
resolution: {integrity: sha512-bV21/9LQmcQeCPEg3BDFtvwL6cwiTMksYNWQQ4KOxCZikEGalWtenoZ0wCiukJINlGCIi2KXx01g4FoH/LxpzQ==}
|
resolution: {integrity: sha512-bV21/9LQmcQeCPEg3BDFtvwL6cwiTMksYNWQQ4KOxCZikEGalWtenoZ0wCiukJINlGCIi2KXx01g4FoH/LxpzQ==}
|
||||||
|
|
||||||
'@heroicons/react@2.1.4':
|
'@heroicons/react@2.1.5':
|
||||||
resolution: {integrity: sha512-ju0wj0wwrUTMQ2Yceyrma7TKuI3BpSjp+qKqV81K9KGcUHdvTMdiwfRc2cwXBp3uXtKuDZkh0v03nWOQnJFv2Q==}
|
resolution: {integrity: sha512-FuzFN+BsHa+7OxbvAERtgBTNeZpUjgM/MIizfVkSCL2/edriN0Hx/DWRCR//aPYwO5QX/YlgLGXk+E3PcfZwjA==}
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
react: '>= 16'
|
react: '>= 16'
|
||||||
|
|
||||||
@ -1229,7 +1229,7 @@ snapshots:
|
|||||||
tslib: 2.6.3
|
tslib: 2.6.3
|
||||||
optional: true
|
optional: true
|
||||||
|
|
||||||
'@heroicons/react@2.1.4(react@19.0.0-rc-f38c22b244-20240704)':
|
'@heroicons/react@2.1.5(react@19.0.0-rc-f38c22b244-20240704)':
|
||||||
dependencies:
|
dependencies:
|
||||||
react: 19.0.0-rc-f38c22b244-20240704
|
react: 19.0.0-rc-f38c22b244-20240704
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user