Open MuskanNazim opened 2 months ago
The plan to solve the bug involves correctly implementing PropTypes validation in the ExpenseListTable.jsx
file. The error message indicates a syntax error related to PropTypes validation, which was attempted but incorrectly placed within the function body. By moving the PropTypes validation outside the function body, we can resolve the syntax error and ensure the code compiles successfully.
The bug is caused by an incorrect placement of PropTypes validation within the ExpenseListTable
function. The error message "Expected ';', '}' or
Here is the corrected version of the code with PropTypes validation added correctly:
import { db } from "@/utils/dbConfig";
import { Expenses } from "@/utils/schema";
import { eq } from "drizzle-orm";
import { Trash } from "lucide-react";
import React from "react";
import PropTypes from "prop-types";
import { toast } from "sonner";
function ExpenseListTable({ expensesList, refreshData }) {
const deleteExpense = async (expense) => {
const result = await db
.delete(Expenses)
.where(eq(Expenses.id, expense.id))
.returning();
if (result) {
toast("Expense Deleted!");
refreshData();
}
};
return (
<div className="mt-3">
<h2 className="font-bold text-lg">Latest Expenses</h2>
<div className="grid grid-cols-4 rounded-tl-xl rounded-tr-xl bg-slate-200 p-2 mt-3">
<h2 className="font-bold">Name</h2>
<h2 className="font-bold">Amount</h2>
<h2 className="font-bold">Date</h2>
<h2 className="font-bold">Action</h2>
</div>
{expensesList.map((expenses, index) => (
<div key={index} className="grid grid-cols-4 bg-slate-50 rounded-bl-xl rounded-br-xl p-2">
<h2>{expenses.name}</h2>
<h2>{expenses.amount}</h2>
<h2>{expenses.createdAt}</h2>
<h2
onClick={() => deleteExpense(expenses)}
className="text-red-500 cursor-pointer"
>
Delete
</h2>
{/* <h2>
<Trash
className="text-red-500 cursor-pointer"
onClick={() => deleteExpense(expenses)}
/>
</h2> */}
</div>
))}
</div>
);
}
ExpenseListTable.propTypes = {
expensesList: PropTypes.array.isRequired,
refreshData: PropTypes.func.isRequired,
};
export default ExpenseListTable;
To replicate the bug, follow these steps:
app/(routes)/dashboard/expenses/_components/ExpenseListTable.jsx
file.By following these steps, you should encounter the same build error, confirming the presence of the bug.
Click here to create a Pull Request with the proposed solution
Files used for this task:
Build Error Failed to compile
Next.js (14.2.2) out of date (learn more) ./app/(routes)/dashboard/expenses/_components/ExpenseListTable.jsx Error: × Expected ';', '}' or
╭─[C:\Users\Walid\Downloads\ai-finance-tracking-main (2)\ai-finance-tracking-main\app(routes)\dashboard\expenses_components\ExpenseListTable.jsx:2:1]
2 │ import PropTypes from "prop-types";
3 │
4 │ function ExpenseListTable({ expenses }) { 5 │ ╭─▶ expensesList: PropTypes.array.isRequired, 6 │ ├─▶ refreshData: PropTypes.func.isRequired, · ╰─── ─ · ╰──── This is the expression part of an expression statement 7 │ }; 8 │
9 │ function ExpenseListTable({ expensesList, refreshData }) { ╰────
Caused by: Syntax Error
Import trace for requested module: ./app/(routes)/dashboard/expenses/_components/ExpenseListTable.jsx ./app/(routes)/dashboard/page.jsx This error occurred during the build process and can only be dismissed by fixing the error.