Skip to content

Commit

Permalink
update for built
Browse files Browse the repository at this point in the history
  • Loading branch information
bvaibhav23 committed May 30, 2023
1 parent d8d60be commit 58a20ff
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 104 deletions.
4 changes: 3 additions & 1 deletion src/Dynamic Data/dataContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ const DataContext = ({ children }) => {
});
fetchCart()
.then(res => setCarts(res))
}, [])
},
// eslint-disable-next-line
[])

return (<>
<productContext.Provider value={[products, setProducts, carts, setCarts, filteredProducts, setFilteredProducts]}>
Expand Down
7 changes: 0 additions & 7 deletions src/Pages/Dashboard/DashboardTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,12 @@ import Paper from '@mui/material/Paper';

const DashboardTable = ({ orders }) => {
const [row, setRow] = useState(null);
const [randomIndex, setRandomIndex] = useState(0);

//Math.floor(Math.random() * arr.length)
useEffect(() => {
if (orders) {
// setRandomIndex(Math.floor(Math.random() * orders.carts.length));
// setRow(orders.carts[randomIndex].products)
setRow(orders.slice(0, 5));
}
}, [orders])



function BasicTable() {
return (<>
<TableContainer sx={{ boxShadow: 5, height: 20 + "rem" }} component={Paper}>
Expand Down
49 changes: 10 additions & 39 deletions src/Pages/Dashboard/DiscountChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const PriceVsDiscount = ({ chartsData }) => {
const [loader, setLoader] = useState(true);
useEffect(() => {
if (chartsData) {

// console.log("chartsData", chartsData)
const labels = chartsData.map((product) => {
return `User-${product.id}`;
Expand All @@ -22,7 +21,6 @@ const PriceVsDiscount = ({ chartsData }) => {
const PriceData = chartsData.map((product) => {
return product.price;
});

const dataSource = {
labels,
datasets: [
Expand All @@ -44,7 +42,6 @@ const PriceVsDiscount = ({ chartsData }) => {
},
],
};

setRevenueData(dataSource);
setLoader(false);
}
Expand All @@ -66,44 +63,18 @@ const PriceVsDiscount = ({ chartsData }) => {
},
}

// const options = {
// responsive: true,
// interaction: {
// intersect: false,
// },
// scales: {
// x: {
// stacked: true,
// },
// y: {
// stacked: true,
// beginAtZero: true
return (<>
{loader ? <Skeleton variant="rectangular" width="100%" animation="pulse">
< div style={{ paddingTop: '57%' }
} />
</Skeleton > :
<Box display="flex"
justifyContent="center"
alignItems="center" sx={{ boxShadow: 5, height: 20 + "rem", padding: 1 + "rem", backgroundColor: "white" }}>

// }
// },
// plugins: {
// legend: {
// position: "top",
// },
// title: {
// display: false,
// text: "Order Revenue",
// },
// },
// };

return (<> {loader ? <Skeleton variant="rectangular" width="100%" animation="pulse">
< div style={{ paddingTop: '57%' }
} />
</Skeleton > :
<Box display="flex"
justifyContent="center"
alignItems="center" sx={{ boxShadow: 5, height: 20 + "rem", padding: 1 + "rem", backgroundColor: "white" }}>

<Bar options={options} data={revenueData} />
</Box>}
<Bar options={options} data={revenueData} />
</Box>}
</>

)
}

Expand Down
9 changes: 1 addition & 8 deletions src/Pages/Dashboard/RatingChart.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState, useEffect } from 'react'
import { Pie, Scatter } from 'react-chartjs-2';
import { Pie } from 'react-chartjs-2';
import { Skeleton, Box } from '@mui/material';

const RatingChart = ({ chartsData }) => {
Expand All @@ -11,8 +11,6 @@ const RatingChart = ({ chartsData }) => {

useEffect(() => {
if (chartsData) {
// console.log("Rating", chartsData.products[0].rating)

// const counts = {};
// for (const num of arr) {
// counts[num] = counts[num] ? counts[num] + 1 : 1; //occurrence counter
Expand All @@ -33,13 +31,9 @@ const RatingChart = ({ chartsData }) => {
// counts[num.rating] = counts[num.rating] ? counts[num.rating] + 1 : 1;
}

// const data = chartsData.products.map((ele) => {
// return { x: ele.rating, y: ele.rating }; //Scatter
// });
const data = Object.values(counts);
const ratingLabels = Object.keys(counts);
// console.log("Rating", counts)

const dataSource = {
labels: ratingLabels,
datasets: [
Expand Down Expand Up @@ -73,7 +67,6 @@ const RatingChart = ({ chartsData }) => {
<Box display="flex"
justifyContent="center"
alignItems="center" sx={{ boxShadow: 5, height: 20 + "rem", padding: 1 + "rem", backgroundColor: "white" }}>
{/* <Scatter data={ratingData} options={options} /> */}
<Pie data={ratingData} options={options} />
</Box>}
</>
Expand Down
4 changes: 2 additions & 2 deletions src/Pages/Dashboard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ ChartJS.register(
const Dashboard = () => {
useEffect(() => { document.title = "Admin | Dashboard" }, []);
//destructure according to index[products, setProducts, carts, setCarts, filteredProducts, setFilteredProducts]
const [products, , , , filteredProducts, setFilteredProducts] = useContext(productContext);
const [products, , , , filteredProducts] = useContext(productContext);

// const [carts, setCarts] = useState();
// const [products, setProducts] = useState();
Expand All @@ -55,7 +55,7 @@ const Dashboard = () => {
},
// eslint-disable-next-line
[filteredProducts]);
console.log(products);
// console.log(products);

return (<>
<Grid container gap={5} spacing={1} justifyContent="space-evenly" alignItems="center">
Expand Down
14 changes: 8 additions & 6 deletions src/Pages/Inventory/InventoryFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ import MenuItem from '@mui/material/MenuItem';
import FormControl from '@mui/material/FormControl';
import Select from '@mui/material/Select';
import { productContext } from '../../Dynamic Data/dataContext';
import { useNavigate } from 'react-router-dom';

const InventoryFilter = () => {
const [data, setData] = useState('');
//destructure according to index[products, setProducts, carts, setCarts, filteredProducts, setFilteredProducts]
const [products, , , , filteredProducts, setFilteredProducts] = useContext(productContext);
const [products, , , , , setFilteredProducts] = useContext(productContext);
const [category, setCategory] = useState([]);
const navigate = useNavigate();
useEffect(() => {
//let unique = [...new Set(myArray)]; // unique Elements
setCategory([...new Set(products.map((ele) => ele.category))]);
}, [])
},
// eslint-disable-next-line
[])

useEffect(() => {
if (data === "") {
Expand All @@ -24,8 +24,10 @@ const InventoryFilter = () => {
else {
setFilteredProducts(products.filter((ele) => ele.category === data));
}
console.log(filteredProducts);
}, [data])
// console.log(filteredProducts);
},
// eslint-disable-next-line
[data])

return (
<FormControl sx={{ m: 1, minWidth: 120 }} size="small" >
Expand Down
1 change: 0 additions & 1 deletion src/Pages/Inventory/InventoryTable.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useContext, useEffect, useState } from 'react'
import { Box } from '@mui/material';
import Table from '@mui/material/Table';
import TableBody from '@mui/material/TableBody';
import TableCell from '@mui/material/TableCell';
Expand Down
6 changes: 3 additions & 3 deletions src/Pages/Inventory/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ const Inventory = () => {
const [products] = useContext(productContext);
const navigate = useNavigate();



useEffect(() => {
document.title = "Admin | Inventory";
if (!products) {
navigate('/');
}
}, []);
},
// eslint-disable-next-line
[]);

return (<Container >
{products &&
Expand Down
37 changes: 1 addition & 36 deletions src/Pages/Orders/index.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,10 @@
import { Container } from '@mui/material';
import React, { useState, useEffect } from 'react'
import { fetchCart, fetchProducts } from '../../Dynamic Data/DynamicData';

// import { productContext } from '../../Dynamic Data/dataContext';
import React, { useEffect } from 'react'

const Orders = () => {
// const [products, setProducts, carts, setCarts] = useContext(productContext)
useEffect(() => {
document.title = "Admin | Orders";
console.log(products, carts);

}, []);
const [carts, setCarts] = useState();
const [products, setProducts] = useState();
const [orders, setOrders] = useState(0);
const [revenue, setRevenue] = useState(0);
const [loader, setLoader] = useState(true);

useEffect(() => {
setTimeout(() => {// setTimeout used to test loader
fetchCart().then((res) => {
setCarts(res);
let orders = res.carts.reduce((accumulator, object) => {
// console.log(accumulator)
return accumulator + object.totalQuantity;
}, 0);
setOrders(orders);

let revenue = res.carts.reduce((accumulator, object) => {
return accumulator + object.discountedTotal;
}, 0);;
setRevenue(revenue);
});
fetchProducts().then((res) => {
setProducts(res);
// console.log("products", res,products);
});
setLoader(false);
}, 500);
},
// console.log("cart", carts, "products", products, "orders: ", orders, " inventory: ", products.total, " customers: ", carts.total, " revenue: ", revenue);
// eslint-disable-next-line
[]);

Expand Down
1 change: 0 additions & 1 deletion src/components/SideBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import AccountCircleIcon from '@mui/icons-material/AccountCircle';

import { Link, useLocation } from "react-router-dom";
import { Stack } from '@mui/material';
import Dashboard from '../Pages/Dashboard';

const drawerWidth = 180;

Expand Down

0 comments on commit 58a20ff

Please sign in to comment.