diff --git a/Frontend/src/components/TotalSpent.jsx b/Frontend/src/components/TotalSpent.jsx index a267b71..eb8828c 100644 --- a/Frontend/src/components/TotalSpent.jsx +++ b/Frontend/src/components/TotalSpent.jsx @@ -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 (
{ 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" >
- ₹10,000 + {totalSpend && totalSpend} ₹

This is the total cost which you spent on this farm diff --git a/Frontend/src/pages/UserPanel/Farm/CropPage.jsx b/Frontend/src/pages/UserPanel/Farm/CropPage.jsx index 713c50d..5a25454 100644 --- a/Frontend/src/pages/UserPanel/Farm/CropPage.jsx +++ b/Frontend/src/pages/UserPanel/Farm/CropPage.jsx @@ -10,7 +10,25 @@ import FinanceSummary from "./FinanceSummary"; import CreateTask from "./CreateTask"; import DisplayTast from "./DisplayTask"; import { useGetFarmByIdQuery } from "../../../store/api/farmApi"; -import { useGetCropByIdQuery } from "../../../store/api/cropApi"; +import { + useCropHarvestQuery, + useGetCropByIdQuery, + useSuggestFertilizersQuery, + useSuggestNextCropQuery, + useSuggestPesticidesQuery, +} from "../../../store/api/cropApi"; +import { PiPottedPlantFill } from "react-icons/pi"; +import { GiGrimReaper } from "react-icons/gi"; +import { GiProgression } from "react-icons/gi"; + +function formatDate(isoString) { + const date = new Date(isoString); + return date.toLocaleDateString("en-US", { + year: "numeric", + month: "long", + day: "numeric", + }); +} export default function CropPage() { const { cropId } = useParams(); @@ -37,6 +55,31 @@ export default function CropPage() { }, [farm]); console.log("djoejwrru9", crop); + const { + data: harvest, + isLoading: harvestLoading, + error: harvestError, + } = useCropHarvestQuery(cropId); + + console.log("Haraufugfudg : ", harvest); + + const { + data: pesticides, + isLoading: pesticideLoading, + error: pesticideError, + } = useSuggestPesticidesQuery(cropId); + + const { + data: fertilizers, + isLoading: fertilizerLoading, + error: fertilizerError, + } = useSuggestFertilizersQuery(cropId); + + const { + data: nextCrop, + isLoading: nextCropLoading, + error: nextCropError, + } = useSuggestNextCropQuery(cropId); return (

@@ -57,48 +100,160 @@ export default function CropPage() { {/* Crop Table Section */} -
- +
+
- {/* Create Transactions Section */} -
-
- +
+
+
+ + +
+ +
+ + +
+ +
+ + +
- {/* Transactions Table Section */} -
- -
+
+

+ Automated Mentoring For Crop Health And Groth +

- {/* Add Transaction Modal Section */} -
-
- -
-
+
+ + + + + + + - {/* Finance Summary Section */} -
-
- -
-
+ + + + + - {/* Create Task Section */} -
-
- -
-
+ + + + - {/* Display Task Section */} -
-
- +
+ + + + + + + + + +
+ Expected Doubts + + Approximate Solution +
+ Approximate Harvest Date + + {harvest?.message} +
+ Suitable Pesticides For Crop + + {pesticides?.message} +
+ Suitable fertilizers For Crop + + {fertilizers?.message} +
+ Best Crop To Grow + + {nextCrop?.message} +
+ + {/*
+
+ Approximate Harvest Date: +
+ +

+
+ +
+
+ Suitable Pesticides For Crop: +
+

{pesticides?.message}

+
+ +
+
+ Suitable fertilizers For Crop: +
+

{fertilizers?.message}

+
+ +
+
+ Best Crop To Grow: +
+

{nextCrop?.message}

+
*/}
); diff --git a/Frontend/src/pages/UserPanel/Farm/CropTable.jsx b/Frontend/src/pages/UserPanel/Farm/CropTable.jsx index 9a50bb9..919a296 100644 --- a/Frontend/src/pages/UserPanel/Farm/CropTable.jsx +++ b/Frontend/src/pages/UserPanel/Farm/CropTable.jsx @@ -1,6 +1,6 @@ import React, { useState, useEffect } from "react"; import Loader from "../../../components/Loader"; -import { Link } from "react-router-dom"; +import { Link, useNavigate } from "react-router-dom"; import { useGetCropsByFarmQuery } from "../../../store/api/cropApi"; const CropTable = ({ farmId }) => { @@ -8,6 +8,8 @@ const CropTable = ({ farmId }) => { const [loading, setLoading] = useState(true); const [error, setError] = useState(null); + const navigate = useNavigate(); + const { data: cropsData, error: cropsError, @@ -91,7 +93,13 @@ const CropTable = ({ farmId }) => { {crops.map((crop) => ( - + { + navigate(`/user/dashboard/croppage/${crop._id}`); + }} + >
{crop.image ? (