Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Chanuka-ChandraYapa committed Sep 12, 2023
2 parents 3d157ce + 4b2b227 commit d667f21
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 22 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;
}
}
58 changes: 36 additions & 22 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,11 +21,27 @@ 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 { Link } from "react-router-dom";
// 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 @@ -54,7 +55,7 @@ function Dashboard() {
color="dark"
icon="newspaper"
title="Total Advertisements"
count={281}
count={counts.ad_count}
percentage={{
color: "success",
amount: "+55%",
Expand All @@ -64,7 +65,6 @@ function Dashboard() {
</AnchorLink>
</MDBox>
</Grid>

<Grid item xs={12} md={6} lg={4}>
<MDBox mb={1.5}>
<Link to="/reports">
Expand All @@ -82,13 +82,12 @@ function Dashboard() {
</Link>
</MDBox>
</Grid>

<Grid item xs={12} md={6} lg={4}>
<MDBox mb={1.5}>
<ComplexStatisticsCard
icon="face"
title="Total Users"
count="2,300"
count={counts.user_count}
percentage={{
color: "success",
amount: "+3%",
Expand All @@ -97,7 +96,22 @@ function Dashboard() {
/>
</MDBox>
</Grid>
{/* <Grid item xs={12} md={6} lg={3}>
<Grid item xs={12} md={6} lg={3}>
<MDBox mb={1.5}>
<ComplexStatisticsCard
color="success"
icon="store"
title="Revenue"
count="34k"
percentage={{
color: "success",
amount: "+1%",
label: "than yesterday",
}}
/>
</MDBox>
</Grid>
<Grid item xs={12} md={6} lg={3}>
<MDBox mb={1.5}>
<ComplexStatisticsCard
color="primary"
Expand All @@ -111,7 +125,7 @@ function Dashboard() {
}}
/>
</MDBox>
</Grid> */}
</Grid>{" "}
</Grid>
{/* <MDBox mt={4.5}>
<Grid container spacing={3}>
Expand Down

0 comments on commit d667f21

Please sign in to comment.