/
page.js
116 lines (108 loc) · 4.17 KB
/
page.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
"use client";
import {useEffect, useState} from "react";
import {useRouter} from "next/navigation";
export default function Page() {
const router = useRouter();
const [expenses, setExpenses] = useState([]);
const [statistics, setStatistics] = useState({
totalExpenses: 0,
totalSpent: 0,
totalBudget: 0,
spentPercentage: 0,
});
const fetchExpenses = () => {
console.log("TODO: fetchExpenses()");
}
const fetchStatistics = () => {
console.log("TODO: fetchStatistics()");
}
useEffect(() => {
fetchExpenses();
fetchStatistics();
}, []);
return (
<div className="flex flex-col md:flex-row space-y-4 md:space-y-0 md:space-x-4">
<div className="w-full basis-3/4">
<div className="bg-gray-50 p-6 rounded-lg shadow-md space-y-4">
<div className="text-lg font-semibold">Expenses</div>
<div className="relative overflow-x-auto">
<table className="w-full text-left rtl:text-right text-gray-500 dark:text-gray-400">
<thead className="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400">
<tr>
<th scope="col" className="px-6 py-3">
#
</th>
<th scope="col" className="px-6 py-3">
Expense name
</th>
<th scope="col" className="px-6 py-3">
Expense description
</th>
<th scope="col" className="px-6 py-3">
Price
</th>
<th scope="col" className="px-6 py-3">
Date added
</th>
<th scope="col" className="px-6 py-3">
Actions
</th>
</tr>
</thead>
<tbody>
{expenses.map((expense, index) => (
<tr key={index} className="bg-white border-b dark:bg-gray-800 dark:border-gray-700">
<th scope="row" className="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white">
{expense.objectId}
</th>
<td className="px-6 py-4">
{expense.name}
</td>
<td className="px-6 py-4">
{expense.description}
</td>
<td className="px-6 py-4">
${expense.price}
</td>
<td className="px-6 py-4">
{expense.createdAt.toString()}
</td>
<td className="px-6 py-4 space-x-2">
<button
className="bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-4 rounded"
onClick={() => router.push("/delete/" + expense.objectId)}
>
Delete
</button>
</td>
</tr>
))}
</tbody>
</table>
</div>
<button
className="bg-indigo-500 hover:bg-indigo-700 text-white font-bold py-2 px-4 rounded"
onClick={() => router.push("/add/")}
>
Add expense
</button>
</div>
</div>
<div className="w-full basis-1/4">
<div className="bg-gray-50 p-6 rounded-lg shadow-md space-y-4">
<div className="text-lg font-semibold">
Statistics
</div>
<ul className="mr-2 list-disc list-inside">
<li>Total expenses: <span className="text-gray-500">{statistics.totalExpenses}</span></li>
<li>Total spent: <span className="text-gray-500">${statistics.totalSpent}</span></li>
<li>Total budget: <span className="text-gray-500">${statistics.totalBudget}</span></li>
</ul>
<div className="w-full bg-gray-200 rounded-full h-2.5 dark:bg-gray-700">
<div className="bg-indigo-600 h-2.5 rounded-full" style={{width: statistics.spentPercentage + "%"}}></div>
</div>
</div>
</div>
</div>
);
}