Skip to content

Commit 93ba728

Browse files
committed
Fix(homepage):fixed the redirect issue of expanse page
1 parent 38eaffc commit 93ba728

6 files changed

Lines changed: 58 additions & 26 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export default function ExpenseDetailsPage() {
6161
const data = {
6262
...formData,
6363
amount: parseFloat(formData.amount),
64-
date: formData.date ? formData.date : today, // always a string
64+
date: formData.date || today, // <-- ensures date is always a string
6565
};
6666
if (editId !== null) {
6767
await updateExpense(editId, data);

src/components/bottomNavbar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const BottomNavBar = () => {
2222
href: "/attendance",
2323
label: "Attendance",
2424
},
25-
{ name: "finance", icon: Money, href: "/finance", label: "Finance" },
25+
{ name: "finance", icon: Money, href: "/expense", label: "Finance" },
2626
];
2727

2828

src/components/expense/DateSelector.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function getDatesAroundToday(range = 15): DateItem[] {
2424
const d = new Date(today.getTime());
2525
d.setDate(d.getDate() + i);
2626

27-
const iso = d.toISOString().split('T')[0];
27+
const iso = d.toISOString().split('T')[0] || '';
2828

2929
dates.push({
3030
date: d.getDate(),

src/components/expense/expenseForm.tsx

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,37 @@
1-
'use client';
1+
"use client";
22
type ExpenseFormProps = {
3-
onClose: () => void;
4-
onChange: (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
5-
onSubmit: (e: React.FormEvent<HTMLFormElement>) => void;
63
formData: {
74
title: string;
85
category: string;
96
description: string;
107
amount: string | number;
11-
date: string;
8+
date: string; // must be string, not string | undefined
129
};
10+
onChange: (
11+
e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>
12+
) => void;
13+
onSubmit: (e: React.FormEvent) => void;
14+
onClose: () => void;
1315
};
1416

15-
export default function ExpenseForm({ onClose, onChange, onSubmit, formData }: ExpenseFormProps) {
17+
export default function ExpenseForm({
18+
onClose,
19+
onChange,
20+
onSubmit,
21+
formData,
22+
}: ExpenseFormProps) {
1623
return (
1724
<div className="antialiased flex flex-col items-center">
1825
<div className="bg-white p-6 rounded-lg shadow-xl w-full max-w-3xl relative mx-auto">
19-
<h2 className="text-xl font-bold text-left mb-6 text-black">Add Your Expenses</h2>
26+
<h2 className="text-xl font-bold text-left mb-6 text-black">
27+
Add Your Expenses
28+
</h2>
2029
<form onSubmit={onSubmit} className="space-y-4">
21-
2230
{/* Title */}
2331
<div>
24-
<label className="block mb-1 text-sm font-medium text-black">Title</label>
32+
<label className="block mb-1 text-sm font-medium text-black">
33+
Title
34+
</label>
2535
<input
2636
type="text"
2737
name="title"
@@ -35,7 +45,9 @@ export default function ExpenseForm({ onClose, onChange, onSubmit, formData }: E
3545

3646
{/* Category */}
3747
<div>
38-
<label className="block mb-1 text-sm font-medium text-black">Category</label>
48+
<label className="block mb-1 text-sm font-medium text-black">
49+
Category
50+
</label>
3951
<input
4052
type="text"
4153
name="category"
@@ -49,7 +61,9 @@ export default function ExpenseForm({ onClose, onChange, onSubmit, formData }: E
4961

5062
{/* Description */}
5163
<div>
52-
<label className="block mb-1 text-sm font-medium text-black">Description</label>
64+
<label className="block mb-1 text-sm font-medium text-black">
65+
Description
66+
</label>
5367
<textarea
5468
name="description"
5569
placeholder="Description"
@@ -61,7 +75,9 @@ export default function ExpenseForm({ onClose, onChange, onSubmit, formData }: E
6175

6276
{/* Amount */}
6377
<div>
64-
<label className="block mb-1 text-sm font-medium text-black">Amount</label>
78+
<label className="block mb-1 text-sm font-medium text-black">
79+
Amount
80+
</label>
6581
<input
6682
type="number"
6783
name="amount"
@@ -75,7 +91,9 @@ export default function ExpenseForm({ onClose, onChange, onSubmit, formData }: E
7591

7692
{/* Date Picker */}
7793
<div>
78-
<label className="block mb-1 text-sm font-medium text-black">Date</label>
94+
<label className="block mb-1 text-sm font-medium text-black">
95+
Date
96+
</label>
7997
<input
8098
type="date"
8199
name="date"

src/lib/expense/idb.ts

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
import { openDB } from 'idb';
2-
import { Expense } from './types';
1+
import { openDB } from "idb";
32

4-
const DB_NAME = 'ExpenseDB';
5-
const STORE_NAME = 'expenses';
3+
const DB_NAME = "ExpenseDB";
4+
const STORE_NAME = "expenses";
65

76
export async function getDB() {
87
return openDB(DB_NAME, 1, {
98
upgrade(db) {
109
if (!db.objectStoreNames.contains(STORE_NAME)) {
11-
db.createObjectStore(STORE_NAME, { keyPath: 'id', autoIncrement: true });
10+
db.createObjectStore(STORE_NAME, {
11+
keyPath: "id",
12+
autoIncrement: true,
13+
});
1214
}
13-
}
15+
},
1416
});
1517
}
1618

@@ -23,9 +25,12 @@ export async function addExpense(expense: Expense): Promise<void> {
2325
const db = await getDB();
2426
await db.add(STORE_NAME, expense);
2527
}
26-
export async function updateExpense(id: number, updatedData: Partial<Expense>): Promise<void> {
28+
export async function updateExpense(
29+
id: number,
30+
updatedData: Partial<Expense>
31+
): Promise<void> {
2732
const db = await getDB();
28-
const tx = db.transaction(STORE_NAME, 'readwrite');
33+
const tx = db.transaction(STORE_NAME, "readwrite");
2934
const store = tx.objectStore(STORE_NAME);
3035
const existing = await store.get(id);
3136

@@ -37,7 +42,16 @@ export async function addExpense(expense: Expense): Promise<void> {
3742

3843
export async function deleteExpense(id: number): Promise<void> {
3944
const db = await getDB();
40-
const tx = db.transaction(STORE_NAME, 'readwrite');
45+
const tx = db.transaction(STORE_NAME, "readwrite");
4146
await tx.objectStore(STORE_NAME).delete(id);
4247
await tx.done;
43-
}
48+
}
49+
50+
export type Expense = {
51+
id?: number;
52+
title: string;
53+
category: string;
54+
description: string;
55+
amount: number;
56+
date: string; // must be string
57+
};

0 commit comments

Comments
 (0)