feat:Add individual crop page

This commit is contained in:
2025-03-26 00:25:09 +05:30
parent 0dbb68d518
commit aba9651c43
3 changed files with 223 additions and 36 deletions
+25 -1
View File
@@ -1,4 +1,28 @@
import { useEffect, useState } from "react";
import { useGetFarmsQuery } from "../store/api/farmApi";
const calculateSpend = (farmList) => {
let totalSpend = 0;
for (let i = 0; i < farmList.length; i++) {
if (!farmList[i]) continue;
if (!farmList[i]?.finances) continue;
if (!farmList[i]?.finances?.totalExpenses) continue;
totalSpend += farmList[i]?.finances?.totalExpenses;
}
return totalSpend;
};
const TotalSpent = () => {
const [totalSpend, setTotalSpend] = useState(0);
const { data: farmList, isLoading, error } = useGetFarmsQuery();
useEffect(() => {
if (!isLoading && !error && farmList) {
setTotalSpend(calculateSpend(farmList));
}
}, [farmList]);
console.log("My farm list is : ", farmList);
return (
<div className="h-full">
<a
@@ -6,7 +30,7 @@ const TotalSpent = () => {
className="h-full block max-w-sm p-6 bg-no-repeat bg-center bg-cover border border-gray-200 rounded-lg shadow-sm hover:bg-gray-100 dark:bg-gray-800 dark:border-gray-700 dark:hover:bg-gray-700"
>
<h5 className="mb-2 text-4xl font-bold tracking-tight text-gray-900 dark:text-white">
10,000
{totalSpend && totalSpend}
</h5>
<p className="font-normal text-gray-700 dark:text-gray-400">
This is the total cost which you spent on this farm