48 lines
1.8 KiB
TypeScript
Raw Permalink Normal View History

/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
2024-11-02 11:53:56 +00:00
'use client'
import React, { useState } from "react"
import { TableArrangement } from '@/app/lib/definitions';
import { classNames } from "../components/button";
import TableOfContents from "../components/table-of-contents";
2024-11-17 16:45:42 +01:00
import { loadTableSimulations } from "@/app/api/tableSimulations";
export default function ArrangementsTable ({onArrangementSelected}: {onArrangementSelected: (arrangementId: string) => void}) {
const [arrangements, setArrangements] = useState<Array<TableArrangement>>([]);
2024-11-17 16:45:42 +01:00
const [arrangementsLoaded, setArrangementsLoaded] = useState(false);
2024-11-17 16:45:42 +01:00
function refreshSimulations() {
loadTableSimulations((arrangements) => {
setArrangements(arrangements);
setArrangementsLoaded(true);
});
}
function arrangementClicked(e: React.MouseEvent<HTMLElement>) {
onArrangementSelected(e.currentTarget.getAttribute('data-arrangement-id') || '');
}
2024-11-17 16:45:42 +01:00
!arrangementsLoaded && refreshSimulations();
return(
<TableOfContents
headers={['Name', 'Discomfort', 'Actions']}
caption='Simulations'
elements={arrangements}
rowRender={(arrangement) => (
<tr key={arrangement.id} className="bg-white border-b odd:bg-white odd:dark:bg-gray-900 even:bg-gray-50 even:dark:bg-gray-800">
<th scope="row" className="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white">
{arrangement.name}
</th>
<td className="px-6 py-4">
{arrangement.discomfort}
</td>
<td>
<button data-arrangement-id={arrangement.id} onClick={arrangementClicked} className={classNames('primary')}>Load</button>
</td>
</tr>
)}
/>
);
}