2025-01-13 21:36:52 +01:00
|
|
|
/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/
|
2024-11-10 21:08:03 +01:00
|
|
|
|
|
|
|
'use client'
|
|
|
|
|
2024-12-09 00:36:42 +01:00
|
|
|
import { AbstractApi } from '@/app/api/abstract-api';
|
|
|
|
import { Expense, ExpenseSerializer } from '@/app/lib/expense';
|
|
|
|
import { PencilIcon, TrashIcon } from '@heroicons/react/24/outline';
|
2024-11-17 16:41:53 +01:00
|
|
|
import TableOfContents from "../components/table-of-contents";
|
2024-11-10 21:08:03 +01:00
|
|
|
|
2024-11-11 08:10:33 +01:00
|
|
|
|
2024-12-09 00:36:42 +01:00
|
|
|
export default function ExpensesTable({ expenses, onUpdate, onEdit }: {
|
|
|
|
expenses: Expense[],
|
|
|
|
onUpdate: () => void,
|
|
|
|
onEdit: (expense: Expense) => void,
|
|
|
|
}) {
|
2024-11-10 21:08:03 +01:00
|
|
|
|
2024-12-09 00:36:42 +01:00
|
|
|
const api = new AbstractApi<Expense>();
|
|
|
|
const serializer = new ExpenseSerializer();
|
2024-11-10 21:08:03 +01:00
|
|
|
|
2024-11-17 16:41:53 +01:00
|
|
|
return (
|
|
|
|
<TableOfContents
|
2024-12-09 00:36:42 +01:00
|
|
|
headers={['Name', 'Amount (€)', 'Pricing Type', 'Actions']}
|
2024-11-17 16:41:53 +01:00
|
|
|
caption='Expenses'
|
|
|
|
elements={expenses}
|
|
|
|
rowRender={(expense) => (
|
|
|
|
<tr key={expense.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">
|
2024-12-09 00:36:42 +01:00
|
|
|
{expense.name}
|
2024-11-17 16:41:53 +01:00
|
|
|
</th>
|
|
|
|
<td className="px-6 py-4">
|
2024-12-09 00:36:42 +01:00
|
|
|
{expense.amount}
|
2024-11-17 16:41:53 +01:00
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
{expense.pricingType}
|
|
|
|
</td>
|
2024-12-09 00:36:42 +01:00
|
|
|
<td>
|
|
|
|
<div className="flex flex-row items-center">
|
|
|
|
<TrashIcon className='size-6 cursor-pointer' onClick={() => { api.destroy(serializer, expense, onUpdate) }} />
|
|
|
|
<PencilIcon className='size-6 cursor-pointer' onClick={() => onEdit(expense)} />
|
|
|
|
</div>
|
|
|
|
</td>
|
2024-11-17 16:41:53 +01:00
|
|
|
</tr>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
);
|
2024-11-10 21:08:03 +01:00
|
|
|
}
|