Open MuskanNazim opened 2 weeks ago
The plan to solve the bug involves correcting the import path for the CardInfo
component in the app/(routes)/dashboard/page.jsx
file. The error message indicates that the module ./CardInfo
cannot be resolved, which suggests that the file does not exist at the specified path. By updating the import statement to the correct path, we can resolve the issue.
The bug is caused by an incorrect import path for the CardInfo
component. The import statement in the app/(routes)/dashboard/page.jsx
file is:
import CardInfo from "./CardInfo";
However, the CardInfo
component is actually located in the _components
directory. Therefore, the correct import path should be:
import CardInfo from "./_components/CardInfo";
Here is the updated code with the correct import path:
"use client";
import React, { useEffect, useState } from "react";
import { UserButton, useUser } from "@clerk/nextjs";
import CardInfo from "./_components/CardInfo";
import { db } from "@/utils/dbConfig";
import { desc, eq, getTableColumns, sql } from "drizzle-orm";
import { Budgets, Expenses, Incomes } from "@/utils/schema";
import BarChartDashboard from "./_components/BarChartDashboard";
import BudgetItem from "./budgets/_components/BudgetItem";
import ExpenseListTable from "./expenses/_components/ExpenseListTable";
function Dashboard() {
const { user } = useUser();
const [budgetList, setBudgetList] = useState([]);
const [incomeList, setIncomeList] = useState([]);
const [expensesList, setExpensesList] = useState([]);
useEffect(() => {
user && getBudgetList();
}, [user]);
/**
* used to get budget List
*/
const getBudgetList = async () => {
const result = await db
.select({
...getTableColumns(Budgets),
totalSpend: sql`sum(${Expenses.amount})`.mapWith(Number),
totalItem: sql`count(${Expenses.id})`.mapWith(Number),
})
.from(Budgets)
.leftJoin(Expenses, eq(Budgets.id, Expenses.budgetId))
.where(eq(Budgets.createdBy, user?.primaryEmailAddress?.emailAddress))
.groupBy(Budgets.id)
.orderBy(desc(Budgets.id));
setBudgetList(result);
getAllExpenses();
getIncomeList();
};
/**
* Get Income stream list
*/
const getIncomeList = async () => {
try {
const result = await db
.select({
...getTableColumns(Incomes),
totalAmount: sql`SUM(CAST(${Incomes.amount} AS NUMERIC))`.mapWith(
Number
),
})
.from(Incomes)
.groupBy(Incomes.id); // Assuming you want to group by ID or any other relevant column
setIncomeList(result);
} catch (error) {
console.error("Error fetching income list:", error);
}
};
/**
* Used to get All expenses belong to users
*/
const getAllExpenses = async () => {
const result = await db
.select({
id: Expenses.id,
name: Expenses.name,
amount: Expenses.amount,
createdAt: Expenses.createdAt,
})
.from(Budgets)
.rightJoin(Expenses, eq(Budgets.id, Expenses.budgetId))
.where(eq(Budgets.createdBy, user?.primaryEmailAddress.emailAddress))
.orderBy(desc(Expenses.id));
setExpensesList(result);
};
return (
<div className="p-8 bg-">
<h2 className="font-bold text-4xl">Hi, {user?.fullName} 👋</h2>
<p className="text-gray-500">
Here's what happenning with your money, Lets Manage your expense
</p>
<CardInfo budgetList={budgetList} incomeList={incomeList} />
<div className="grid grid-cols-1 lg:grid-cols-3 mt-6 gap-5">
<div className="lg:col-span-2">
<BarChartDashboard budgetList={budgetList} />
<ExpenseListTable
expensesList={expensesList}
refreshData={() => getBudgetList()}
/>
</div>
<div className="grid gap-5">
<h2 className="font-bold text-lg">Latest Budgets</h2>
{budgetList?.length > 0
? budgetList.map((budget, index) => (
<BudgetItem budget={budget} key={index} />
))
: [1, 2, 3, 4].map((item, index) => (
<div
className="h-[180xp] w-full
bg-slate-200 rounded-lg animate-pulse"
></div>
))}
</div>
</div>
</div>
);
}
export default Dashboard;
To replicate the bug, follow these steps:
CardInfo
component is located in the _components
directory.app/(routes)/dashboard/page.jsx
file, use the incorrect import path for CardInfo
:
import CardInfo from "./CardInfo";
By following these steps, you should be able to replicate the bug and verify that the solution resolves the issue.
Click here to create a Pull Request with the proposed solution
Files used for this task:
Here's what happenning with your money, Lets Manage your expense
./app/(routes)/dashboard/page.jsx:7:1 Module not found: Can't resolve './CardInfo' 5 | import { Budgets, Expenses, Incomes } from '@/utils/schema'; 6 | import { useUser } from '@clerk/nextjs';
https://nextjs.org/docs/messages/module-not-found