feat:Fixed all the UI Pages
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// PerformanceChart.jsx
|
||||
import React from "react";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { Line } from "react-chartjs-2";
|
||||
import {
|
||||
Chart as ChartJS,
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
Tooltip,
|
||||
Legend,
|
||||
} from "chart.js";
|
||||
import { useGetFarmsQuery } from "../../store/api/farmApi";
|
||||
|
||||
ChartJS.register(
|
||||
CategoryScale,
|
||||
@@ -22,7 +23,35 @@ ChartJS.register(
|
||||
Legend
|
||||
);
|
||||
|
||||
const calculateSpend = (farmList) => {
|
||||
let totalSpend = [];
|
||||
for (let i = 0; i < farmList.length; i++) {
|
||||
if (!farmList[i]) continue;
|
||||
if (!farmList[i]?.finances) continue;
|
||||
if (!farmList[i]?.finances?.transactions) continue;
|
||||
|
||||
for (let j = 0; j < farmList[i]?.finances?.transactions.length; j++) {
|
||||
if (!farmList[i]?.finances?.transactions[j]) continue;
|
||||
if (!farmList[i]?.finances?.transactions[j]?.amount) continue;
|
||||
if (farmList[i]?.finances?.transactions[j]?.type == "Revenue") continue;
|
||||
totalSpend.push(farmList[i]?.finances?.transactions[j]?.amount);
|
||||
}
|
||||
}
|
||||
return totalSpend;
|
||||
};
|
||||
|
||||
const PerformanceChart = () => {
|
||||
const [totalSpend, setTotalSpend] = useState(0);
|
||||
const [spentList, setSpentList] = useState([]);
|
||||
const { data: farmList, isLoading, error } = useGetFarmsQuery();
|
||||
|
||||
useEffect(() => {
|
||||
if (!isLoading && !error && farmList) {
|
||||
setTotalSpend(calculateSpend(farmList));
|
||||
setSpentList(calculateSpend(farmList));
|
||||
}
|
||||
}, [farmList]);
|
||||
|
||||
const data = {
|
||||
labels: [
|
||||
"Jan",
|
||||
@@ -40,8 +69,8 @@ const PerformanceChart = () => {
|
||||
],
|
||||
datasets: [
|
||||
{
|
||||
label: "Yield",
|
||||
data: [75, 68, 85, 88, 60, 62, 78, 90, 95, 92, 88, 80], // slightly improved values
|
||||
label: "Expences",
|
||||
data: spentList, // slightly improved values
|
||||
fill: false,
|
||||
backgroundColor: "rgb(75, 192, 192)",
|
||||
borderColor: "rgba(75, 192, 192, 0.2)",
|
||||
@@ -53,7 +82,7 @@ const PerformanceChart = () => {
|
||||
responsive: true,
|
||||
plugins: {
|
||||
legend: { position: "top" },
|
||||
title: { display: true, text: "Performance Trend" },
|
||||
title: { display: true, text: "Expences Tracking " },
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user