Skip to content

Commit

Permalink
counts updated
Browse files Browse the repository at this point in the history
  • Loading branch information
NadunSanjeevana committed Sep 12, 2023
1 parent b899032 commit 8c56907
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 21 deletions.
12 changes: 12 additions & 0 deletions src/api/count/counts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import axios from "axios";

// Function to fetch data from the backend
export async function getCounts() {
try {
const response = await axios.get("/getcounts"); // Replace with your API endpoint URL
return response.data;
} catch (error) {
console.error("Error fetching data from the backend:", error);
throw error;
}
}
43 changes: 22 additions & 21 deletions src/layouts/dashboard/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
/**
=========================================================
* Material Dashboard 2 React - v2.2.0
=========================================================
* Product Page: https://www.creative-tim.com/product/material-dashboard-react
* Copyright 2023 Creative Tim (https://www.creative-tim.com)
Coded by www.creative-tim.com
=========================================================
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*/

// @mui material components
import { useEffect } from "react";
import Grid from "@mui/material/Grid";
import AnchorLink from "react-anchor-link-smooth-scroll";

Expand All @@ -36,10 +21,26 @@ import ComplexStatisticsCard from "examples/Cards/StatisticsCards/ComplexStatist
import Projects from "layouts/dashboard/components/Projects";
import SearchBar from "./components/SearchBar/searchBar";
import { AdCard } from "./components/adCard";
import { useState } from "react";
import { getCounts } from "api/count/counts";
// import OrdersOverview from "layouts/dashboard/components/OrdersOverview";

function Dashboard() {
const [counts, setCounts] = useState([]);
// const { sales, tasks } = reportsLineChartData;
useEffect(() => {
// Fetch data from the backend using the imported function
const fetchData = async () => {
try {
const data = await getCounts();
setCounts(data);
} catch (error) {
console.error("Error fetching data from the backend:", error);
}
};

fetchData();
}, []);

return (
<DashboardLayout>
Expand All @@ -53,7 +54,7 @@ function Dashboard() {
color="dark"
icon="newspaper"
title="Total Advertisements"
count={281}
count={counts.ad_count}
percentage={{
color: "success",
amount: "+55%",
Expand All @@ -68,7 +69,7 @@ function Dashboard() {
<ComplexStatisticsCard
icon="face"
title="Total Users"
count="2,300"
count={counts.user_count}
percentage={{
color: "success",
amount: "+3%",
Expand All @@ -81,9 +82,9 @@ function Dashboard() {
<MDBox mb={1.5}>
<ComplexStatisticsCard
color="success"
icon="store"
title="Revenue"
count="34k"
icon="report"
title="Total Reports"
count={counts.report_count}
percentage={{
color: "success",
amount: "+1%",
Expand Down

0 comments on commit 8c56907

Please sign in to comment.