Fix the dashboard

This commit is contained in:
Sibunnayak 2024-09-13 13:02:37 +05:30
parent 20e661d599
commit 5bf50ab372
3 changed files with 179 additions and 152 deletions

View File

@ -28,7 +28,6 @@ const [userType, setUserType] = useState("");
show: itemPerPage, show: itemPerPage,
}, },
}); });
console.log(res.data);
setuser(res.data?.user); setuser(res.data?.user);
setleaveData(res.data?.leave); setleaveData(res.data?.leave);
setUserType(res.data?.userType); setUserType(res.data?.userType);

View File

@ -50,28 +50,38 @@ const Dashboard = () => {
// console.log(res.data) // console.log(res.data)
setRetaildistributor(res.data.total_data); setRetaildistributor(res.data.total_data);
}; };
// //2nd //2nd
// const [category, setCategory] = useState([]); const [category, setCategory] = useState(null);
// const getAllCategory = async () => { const getAllCategory = async () => {
// let res = await axios.get(`/api/category/getCategories`, { let res = await axios.get(`/api/category/getCategories`, {
// headers: { headers: {
// Authorization: `Bearer ${token}`, Authorization: `Bearer ${token}`,
// }, },
// }); });
// // console.log(res.data); // console.log(res.data);
// setCategory(res?.data?.categories); setCategory(res?.data?.total_data);
// }; };
// //3rd // //3rd
// const [product, setProduct] = useState([]); const [product, setProduct] = useState(null);
// const getAllProduct = async () => { const getAllProduct = async () => {
// let res = await axios.get(`/api/product/getAll/user/`, { let res = await axios.get(`/api/product/getAll/user/`, {
// headers: { headers: {
// Authorization: `Bearer ${token}`, Authorization: `Bearer ${token}`,
// }, },
// }); });
// // console.log(res.data); // console.log(res.data);
// setProduct(res?.data?.product); setProduct(res?.data?.total_data);
// }; };
const [Brand, setBrand] = useState(null);
const getAllBrands = async () => {
let res = await axios.get(`/api/brand/getBrands`, {
headers: {
Authorization: `Bearer ${token}`,
},
});
// console.log(res.data);
setBrand(res?.data?.total_data);
};
// // 3rd // // 3rd
// const [Requests, setRequests] = useState([]); // const [Requests, setRequests] = useState([]);
// const getAllRequests = async () => { // const getAllRequests = async () => {
@ -152,8 +162,9 @@ const Dashboard = () => {
getAllsalescoordinator(); getAllsalescoordinator();
getAllterritorymanager(); getAllterritorymanager();
getAllretaildistributor(); getAllretaildistributor();
// getAllCategory(); getAllCategory();
// getAllProduct(); getAllProduct();
getAllBrands();
// getAllRequests(); // getAllRequests();
}, [token]); }, [token]);
return ( return (
@ -163,9 +174,9 @@ const Dashboard = () => {
salescoordinator={salescoordinator} salescoordinator={salescoordinator}
territorymanager={territorymanager} territorymanager={territorymanager}
retaildistributor={retaildistributor} retaildistributor={retaildistributor}
// category={category} category={category}
// product={product} product={product}
// Requests={Requests} Brand={Brand}
/> />
</> </>
); );

View File

@ -18,116 +18,125 @@ import axios from "axios";
{ {
/* <BeatLoader color="#36d7b7" /> */ /* <BeatLoader color="#36d7b7" /> */
} }
const WidgetsDropdown = ({ users,salescoordinator,territorymanager,retaildistributor }) => { const WidgetsDropdown = ({
// const WidgetsDropdown = ({ users, category, product, Requests }) => { users,
// const token = isAutheticated(); salescoordinator,
// const [orders, setOrders] = useState([]); territorymanager,
// const [todayorders, setTodayOrders] = useState([]); retaildistributor,
// const [monthorders, setMonthOrders] = useState([]); Brand,
// const [yearorders, setYearOrders] = useState([]); product,
// const [lastyearorders, setLastYearOrders] = useState([]); category,
// const [processingorders, setProcessingOrders] = useState([]); }) => {
// const [dispatchedorders, setDispatchedOrders] = useState([]); // const WidgetsDropdown = ({ users, category, product, Requests }) => {
// const [deliveredorders, setDeliveredOrders] = useState([]); // const token = isAutheticated();
// const [cancelledorders, setCancelledOrders] = useState([]); // const [orders, setOrders] = useState([]);
// const getAllOrder = async () => { // const [todayorders, setTodayOrders] = useState([]);
// let res = await axios.get(`/api/order/getAll/`, { // const [monthorders, setMonthOrders] = useState([]);
// headers: { // const [yearorders, setYearOrders] = useState([]);
// Authorization: `Bearer ${token}`, // const [lastyearorders, setLastYearOrders] = useState([]);
// }, // const [processingorders, setProcessingOrders] = useState([]);
// }); // const [dispatchedorders, setDispatchedOrders] = useState([]);
// // console.log(res.data); // const [deliveredorders, setDeliveredOrders] = useState([]);
// setOrders(res?.data?.order); // const [cancelledorders, setCancelledOrders] = useState([]);
// setTodayOrders( // const getAllOrder = async () => {
// res?.data?.order?.filter((order) => { // let res = await axios.get(`/api/order/getAll/`, {
// return ( // headers: {
// new Date(order.createdAt).toDateString() === new Date().toDateString() // Authorization: `Bearer ${token}`,
// ); // },
// }) // });
// ); // // console.log(res.data);
// setMonthOrders( // setOrders(res?.data?.order);
// res?.data?.order?.filter((order) => { // setTodayOrders(
// return new Date(order.createdAt).getMonth() === new Date().getMonth(); // res?.data?.order?.filter((order) => {
// }) // return (
// ); // new Date(order.createdAt).toDateString() === new Date().toDateString()
// setYearOrders( // );
// res?.data?.order?.filter((order) => { // })
// return ( // );
// new Date(order.createdAt).getFullYear() === new Date().getFullYear() // setMonthOrders(
// ); // res?.data?.order?.filter((order) => {
// }) // return new Date(order.createdAt).getMonth() === new Date().getMonth();
// ); // })
// setLastYearOrders( // );
// res?.data?.order?.filter((order) => { // setYearOrders(
// return ( // res?.data?.order?.filter((order) => {
// new Date(order.createdAt).getFullYear() === // return (
// new Date().getFullYear() - 1 // new Date(order.createdAt).getFullYear() === new Date().getFullYear()
// ); // );
// }) // })
// ); // );
// }; // setLastYearOrders(
// const getProcessingOrder = async () => { // res?.data?.order?.filter((order) => {
// let res = await axios.get(`/api/order/getAll/processing`, { // return (
// headers: { // new Date(order.createdAt).getFullYear() ===
// Authorization: `Bearer ${token}`, // new Date().getFullYear() - 1
// }, // );
// }); // })
// // console.log(res.data); // );
// setProcessingOrders(res?.data?.order); // };
// }; // const getProcessingOrder = async () => {
// const getDispatchedOrder = async () => { // let res = await axios.get(`/api/order/getAll/processing`, {
// let res = await axios.get(`/api/order/getAll/dispatched`, { // headers: {
// headers: { // Authorization: `Bearer ${token}`,
// Authorization: `Bearer ${token}`, // },
// }, // });
// }); // // console.log(res.data);
// // console.log(res.data); // setProcessingOrders(res?.data?.order);
// setDispatchedOrders(res?.data?.order); // };
// }; // const getDispatchedOrder = async () => {
// const getDeliveredOrder = async () => { // let res = await axios.get(`/api/order/getAll/dispatched`, {
// let res = await axios.get(`/api/order/getAll/delivered`, { // headers: {
// headers: { // Authorization: `Bearer ${token}`,
// Authorization: `Bearer ${token}`, // },
// }, // });
// }); // // console.log(res.data);
// // console.log(res.data); // setDispatchedOrders(res?.data?.order);
// setDeliveredOrders(res?.data?.order); // };
// }; // const getDeliveredOrder = async () => {
// const getCancelledOrder = async () => { // let res = await axios.get(`/api/order/getAll/delivered`, {
// let res = await axios.get(`/api/order/getAll/cancelled`, { // headers: {
// headers: { // Authorization: `Bearer ${token}`,
// Authorization: `Bearer ${token}`, // },
// }, // });
// }); // // console.log(res.data);
// // console.log(res.data); // setDeliveredOrders(res?.data?.order);
// setCancelledOrders(res?.data?.order); // };
// }; // const getCancelledOrder = async () => {
// let res = await axios.get(`/api/order/getAll/cancelled`, {
// headers: {
// Authorization: `Bearer ${token}`,
// },
// });
// // console.log(res.data);
// setCancelledOrders(res?.data?.order);
// };
// useEffect(() => { // useEffect(() => {
// getAllOrder(); // getAllOrder();
// getProcessingOrder(); // getProcessingOrder();
// getDispatchedOrder(); // getDispatchedOrder();
// getDeliveredOrder(); // getDeliveredOrder();
// getCancelledOrder(); // getCancelledOrder();
// }, [token]); // }, [token]);
// const date = new Date(); // const date = new Date();
// const day = date.getDate(); // const day = date.getDate();
// const suffix = // const suffix =
// day === 1 || day === 21 || day === 31 // day === 1 || day === 21 || day === 31
// ? "st" // ? "st"
// : day === 2 || day === 22 // : day === 2 || day === 22
// ? "nd" // ? "nd"
// : day === 3 || day === 23 // : day === 3 || day === 23
// ? "rd" // ? "rd"
// : "th"; // : "th";
// const month = date.toLocaleDateString("en-US", { month: "long" }); // const month = date.toLocaleDateString("en-US", { month: "long" });
// const formattedDate = `${day}${suffix} ${month}`; // const formattedDate = `${day}${suffix} ${month}`;
// // console.log(formattedDate); // // console.log(formattedDate);
// const year = date.toLocaleDateString("en-US", { year: "numeric" }); // const year = date.toLocaleDateString("en-US", { year: "numeric" });
// const formattedmonth = `${month} ${year}`; // const formattedmonth = `${month} ${year}`;
return ( return (
<> <>
<h4>Principal Distributor</h4> <h4>Users</h4>
{/* <h4>Principal Distributor</h4> */}
<CRow> <CRow>
<CCol sm={6} lg={3}> <CCol sm={6} lg={3}>
<CWidgetStatsA <CWidgetStatsA
@ -137,9 +146,9 @@ const WidgetsDropdown = ({ users,salescoordinator,territorymanager,retaildistrib
title="Total Principal Distributor" title="Total Principal Distributor"
/> />
</CCol> </CCol>
</CRow> {/* </CRow> */}
<h4>Retail Distributor</h4> {/* <h4>Retail Distributor</h4> */}
<CRow> {/* <CRow> */}
<CCol sm={6} lg={3}> <CCol sm={6} lg={3}>
<CWidgetStatsA <CWidgetStatsA
className="mb-4" className="mb-4"
@ -148,9 +157,9 @@ const WidgetsDropdown = ({ users,salescoordinator,territorymanager,retaildistrib
title="Total Reatil Distributor" title="Total Reatil Distributor"
/> />
</CCol> </CCol>
</CRow> {/* </CRow> */}
<h4>Sales Coordinator</h4> {/* <h4>Sales Coordinator</h4> */}
<CRow> {/* <CRow> */}
<CCol sm={6} lg={3}> <CCol sm={6} lg={3}>
<CWidgetStatsA <CWidgetStatsA
className="mb-4" className="mb-4"
@ -159,9 +168,9 @@ const WidgetsDropdown = ({ users,salescoordinator,territorymanager,retaildistrib
title="Total Sales Coordinator" title="Total Sales Coordinator"
/> />
</CCol> </CCol>
</CRow> {/* </CRow> */}
<h4>Territory Manager</h4> {/* <h4>Territory Manager</h4> */}
<CRow> {/* <CRow> */}
<CCol sm={6} lg={3}> <CCol sm={6} lg={3}>
<CWidgetStatsA <CWidgetStatsA
className="mb-4" className="mb-4"
@ -170,8 +179,8 @@ const WidgetsDropdown = ({ users,salescoordinator,territorymanager,retaildistrib
title="Total Territory Manager" title="Total Territory Manager"
/> />
</CCol> </CCol>
</CRow> </CRow>
{/* <CCol sm={6} lg={3}> {/* <CCol sm={6} lg={3}>
<CWidgetStatsA <CWidgetStatsA
className="mb-4" className="mb-4"
color="primary" color="primary"
@ -235,14 +244,22 @@ const WidgetsDropdown = ({ users,salescoordinator,territorymanager,retaildistrib
/> */} /> */}
{/* </CCol> */} {/* </CCol> */}
{/* </CRow> {/* </CRow> */}
<h4>Products and Categories</h4> <h4>Products, Categories and Brands</h4>
<CRow> <CRow>
<CCol sm={6} lg={3}> <CCol sm={6} lg={3}>
<CWidgetStatsA <CWidgetStatsA
className="mb-4" className="mb-4"
color="primary" color="primary"
value={<>{category.length}</>} value={<>{product}</>}
title="Total products"
/>
</CCol>
<CCol sm={6} lg={3}>
<CWidgetStatsA
className="mb-4"
color="primary"
value={<>{category}</>}
title="Total Categories" title="Total Categories"
/> />
</CCol> </CCol>
@ -250,12 +267,12 @@ const WidgetsDropdown = ({ users,salescoordinator,territorymanager,retaildistrib
<CWidgetStatsA <CWidgetStatsA
className="mb-4" className="mb-4"
color="primary" color="primary"
value={<>{product.length}</>} value={<>{Brand}</>}
title="Total products" title="Total Brands"
/> />
</CCol> </CCol>
</CRow> </CRow>
<h4>Orders</h4> {/* <h4>Orders</h4>
<CRow> <CRow>
<CCol sm={6} lg={3}> <CCol sm={6} lg={3}>
<CWidgetStatsA <CWidgetStatsA
@ -329,7 +346,7 @@ const WidgetsDropdown = ({ users,salescoordinator,territorymanager,retaildistrib
title="Orders - Cancelled" title="Orders - Cancelled"
/> />
</CCol> </CCol>
</CRow>*/} </CRow> */}
</> </>
); );
}; };