From cd7c0c8f76296724e2b22eca1df32557a9fb55d1 Mon Sep 17 00:00:00 2001 From: Sibunnayak Date: Tue, 2 Apr 2024 17:21:11 +0530 Subject: [PATCH 1/3] Dashboard Updated --- src/views/dashboard/Dashboard.js | 89 +++++---- src/views/widgets/WidgetsDropdown.js | 281 +++++++++++++++++++++++---- 2 files changed, 288 insertions(+), 82 deletions(-) diff --git a/src/views/dashboard/Dashboard.js b/src/views/dashboard/Dashboard.js index 0d5c690..88a69c8 100644 --- a/src/views/dashboard/Dashboard.js +++ b/src/views/dashboard/Dashboard.js @@ -1,44 +1,57 @@ -import React, { lazy } from 'react' +import React, { lazy } from "react"; import axios from "axios"; import { useEffect, useState, useCallback, useMemo } from "react"; import { isAutheticated } from "../../auth.js"; -const WidgetsDropdown = lazy(() => import('../widgets/WidgetsDropdown.js')) - +const WidgetsDropdown = lazy(() => import("../widgets/WidgetsDropdown.js")); const Dashboard = () => { - //1 st - const [users, setUsers] = useState([]) + //1 st + const [users, setUsers] = useState([]); const token = isAutheticated(); const getAllUsers = async () => { - let res = await axios.get( - `/api/v1/admin/users`, - { - headers: { - Authorization: `Bearer ${token}`, - }, - } - ); + let res = await axios.get(`/api/v1/admin/users`, { + headers: { + Authorization: `Bearer ${token}`, + }, + }); // console.log(res.data) - setUsers(res.data.users) - - + setUsers(res.data.users); + }; + //2nd + const [category, setCategory] = useState([]); + const getAllCategory = async () => { + let res = await axios.get(`/api/category/getCategories`, { + headers: { + Authorization: `Bearer ${token}`, + }, + }); + // console.log(res.data); + setCategory(res?.data?.categories); + }; + //3rd + const [product, setProduct] = useState([]); + const getAllProduct = async () => { + let res = await axios.get(`/api/product/getAll/`, { + headers: { + Authorization: `Bearer ${token}`, + }, + }); + // console.log(res.data); + setProduct(res?.data?.product); + }; + // 3rd + const [Requests, setRequests] = useState([]); + const getAllRequests = async () => { + let res = await axios.get(`/api/contact/request/getAll/`, { + headers: { + Authorization: `Bearer ${token}`, + }, + }); + // console.log(res.data); + setRequests(res.data.contactRequest); } - // //2nd - // const [category, setCategory] = useState([]) - // const getAllCategory = useCallback(async () => { - // let res = await axios.get( - // `/api/category/getAll`, - // { - // headers: { - // Authorization: `Bearer ${token}`, - // }, - // } - // ); - // // console.log(res.data.category[0].image.url) - // setCategory(res.data.category) - // }, [token]); // //3 requiment // const [requirement, setRequirement] = useState([]) @@ -71,7 +84,6 @@ const Dashboard = () => { // setNews(res.data.news) - // }, [token]); // //5 offers // const [offer, setOffer] = useState([]) @@ -88,7 +100,6 @@ const Dashboard = () => { // // console.log(res.data) // setOffer(res.data.offer) - // }, [token]); // //6 event // const [event, setEvent] = useState([]) @@ -104,18 +115,18 @@ const Dashboard = () => { // // console.log(res.data) // setEvent(res.data.Event) - // }, [token]); useEffect(() => { getAllUsers(); - + getAllCategory(); + getAllProduct(); + getAllRequests(); }, [token]); return ( <> - - + - ) -} + ); +}; -export default Dashboard +export default Dashboard; diff --git a/src/views/widgets/WidgetsDropdown.js b/src/views/widgets/WidgetsDropdown.js index 6f9636d..f73656e 100644 --- a/src/views/widgets/WidgetsDropdown.js +++ b/src/views/widgets/WidgetsDropdown.js @@ -1,4 +1,4 @@ -import React from 'react' +import React, { useEffect, useState } from "react"; import { CRow, CCol, @@ -7,45 +7,145 @@ import { CDropdownItem, CDropdownToggle, CWidgetStatsA, -} from '@coreui/react' -import { getStyle } from '@coreui/utils' -import { CChartBar, CChartLine } from '@coreui/react-chartjs' -import CIcon from '@coreui/icons-react' -import { cilArrowBottom, cilArrowTop, cilOptions } from '@coreui/icons' -import { BeatLoader } from 'react-spinners' -{/* */ } +} from "@coreui/react"; +import { getStyle } from "@coreui/utils"; +import { CChartBar, CChartLine } from "@coreui/react-chartjs"; +import CIcon from "@coreui/icons-react"; +import { cilArrowBottom, cilArrowTop, cilOptions } from "@coreui/icons"; +import { BeatLoader } from "react-spinners"; +import { isAutheticated } from "src/auth"; +import axios from "axios"; +{ + /* */ +} -const WidgetsDropdown = ({ users }) => { +const WidgetsDropdown = ({ users, category, product, Requests }) => { + const token = isAutheticated(); + const [orders, setOrders] = useState([]); + const [todayorders, setTodayOrders] = useState([]); + const [monthorders, setMonthOrders] = useState([]); + const [yearorders, setYearOrders] = useState([]); + const [lastyearorders, setLastYearOrders] = useState([]); + const [processingorders, setProcessingOrders] = useState([]); + const [dispatchedorders, setDispatchedOrders] = useState([]); + const [deliveredorders, setDeliveredOrders] = useState([]); + const [cancelledorders, setCancelledOrders] = useState([]); + const getAllOrder = async () => { + let res = await axios.get(`/api/order/getAll/`, { + headers: { + Authorization: `Bearer ${token}`, + }, + }); + // console.log(res.data); + setOrders(res?.data?.order); + setTodayOrders( + res?.data?.order?.filter((order) => { + return ( + new Date(order.createdAt).toDateString() === new Date().toDateString() + ); + }) + ); + setMonthOrders( + res?.data?.order?.filter((order) => { + return new Date(order.createdAt).getMonth() === new Date().getMonth(); + }) + ); + setYearOrders( + res?.data?.order?.filter((order) => { + return ( + new Date(order.createdAt).getFullYear() === new Date().getFullYear() + ); + }) + ); + setLastYearOrders( + res?.data?.order?.filter((order) => { + return ( + new Date(order.createdAt).getFullYear() === + new Date().getFullYear() - 1 + ); + }) + ); + }; + const getProcessingOrder = async () => { + let res = await axios.get(`/api/order/getAll/processing`, { + headers: { + Authorization: `Bearer ${token}`, + }, + }); + // console.log(res.data); + setProcessingOrders(res?.data?.order); + } + const getDispatchedOrder = async () => { + let res = await axios.get(`/api/order/getAll/dispatched`, { + headers: { + Authorization: `Bearer ${token}`, + }, + }); + // console.log(res.data); + setDispatchedOrders(res?.data?.order); + } + const getDeliveredOrder = async () => { + let res = await axios.get(`/api/order/getAll/delivered`, { + headers: { + Authorization: `Bearer ${token}`, + }, + }); + // console.log(res.data); + setDeliveredOrders(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(() => { + getAllOrder(); + getProcessingOrder(); + getDispatchedOrder(); + getDeliveredOrder(); + getCancelledOrder(); + }, [token]); + const date = new Date(); + const day = date.getDate(); + const suffix = + day === 1 || day === 21 || day === 31 + ? "st" + : day === 2 || day === 22 + ? "nd" + : day === 3 || day === 23 + ? "rd" + : "th"; + const month = date.toLocaleDateString("en-US", { month: "long" }); + const formattedDate = `${day}${suffix} ${month}`; + // console.log(formattedDate); +const year =date.toLocaleDateString("en-US", { year: "numeric" }); +const formattedmonth = `${month} ${year}`; return ( - - - - - {users.length} - - } - title="Total Users" - - /> - - {/* - - {category.length} - - } - title="Total Categories" - - /> - - + <> +

Users and Requests

+ + + {users.length}} + title="Total Users" + /> + + + {Requests.length}} + title="Contact Requests" + /> + + {/* { title="Total Events" /> */} - {/* */} - - ) -} + {/*
*/} +
+

Products and Categories

+ + + {category.length}} + title="Total Categories" + /> + + + {product.length}} + title="Total products" + /> + + +

Orders

+ + + {orders.length}} + title="Total orders" + /> + + + {todayorders.length}} + title={`Orders for ${formattedDate}`} + /> + + + {monthorders.length}} + title={`Orders for ${formattedmonth}`} + /> + + + {yearorders.length}} + title={`Orders for ${year}`} + /> + + + {lastyearorders.length}} + title={`Orders for ${year - 1}`} + /> + + + {processingorders.length}} + title="Orders - Processing" + /> + + + {dispatchedorders.length}} + title="Orders - Dispatched" + /> + + + {deliveredorders.length}} + title="Orders - Delivered" + /> + + + {cancelledorders.length}} + title="Orders - Cancelled" + /> + + + + ); +}; -export default WidgetsDropdown +export default WidgetsDropdown; From 2fec235933319b208f046466a58591a71875e708 Mon Sep 17 00:00:00 2001 From: syedmujahidahmed Date: Wed, 3 Apr 2024 17:16:32 +0530 Subject: [PATCH 2/3] added about us page in content --- src/routes.js | 6 + src/views/Content/content.js | 5 + src/views/Content/editAboutUs.js | 162 +++++++++++++++++++++++++ src/views/Content/editPrivacyPolicy.js | 2 +- 4 files changed, 174 insertions(+), 1 deletion(-) create mode 100644 src/views/Content/editAboutUs.js diff --git a/src/routes.js b/src/routes.js index e0d91d1..78494c5 100644 --- a/src/routes.js +++ b/src/routes.js @@ -90,6 +90,7 @@ import EditPrivacyPolicy from "./views/Content/editPrivacyPolicy"; import EditTermsConditions from "./views/Content/editTermsConditions"; import EditShippingPolicy from "./views/Content/editShippingPolicy"; import EditRefundpolicy from "./views/Content/editRefundPolicy"; +import EditAboutUs from "./views/Content/editAboutUs"; import UserTable from "./views/UserAddress/userTable"; import EditUserAddress from "./views/UserAddress/editUserAddress"; @@ -296,6 +297,11 @@ const routes = [ name: "Content", element: EditRefundpolicy, }, + { + path: "/content/about-us", + name: "Content", + element: EditAboutUs, + }, // { path: '/complaint/view/:id', name: 'view Complain', element: ViewComplaint }, //Complaints diff --git a/src/views/Content/content.js b/src/views/Content/content.js index 04be743..8846d23 100644 --- a/src/views/Content/content.js +++ b/src/views/Content/content.js @@ -34,6 +34,11 @@ export default function Content() { action: "Edit", path: "/content/refund-policy", }, + { + name: "About Us", + action: "Edit", + path: "/content/about-us", + } ]; return ( diff --git a/src/views/Content/editAboutUs.js b/src/views/Content/editAboutUs.js new file mode 100644 index 0000000..c402162 --- /dev/null +++ b/src/views/Content/editAboutUs.js @@ -0,0 +1,162 @@ +import { Typography } from "@material-ui/core"; +import { Box, Button } from "@mui/material"; +import React, { useEffect, useState } from "react"; +import ReactQuill from "react-quill"; +import "react-quill/dist/quill.snow.css"; +import axios from "axios"; +import { isAutheticated } from "src/auth"; + +const TOOLBAR_OPTIONS = [ + [{ header: [1, 2, 3, 4, 5, 6, false] }], + [{ font: [] }], + [{ list: "ordered" }, { list: "bullet" }], + ["bold", "italic", "underline", "strike"], + [{ color: [] }, { background: [] }], + [{ align: [] }], + [{ script: "super" }, { script: "sub" }], + ["undo", "redo"], +]; + +export default function EditAboutUs() { + const [title, setTitle] = useState("About Us"); + const [content, setContent] = useState(""); + const [added, setAdded] = useState(false); + const [olderContent, setOlderContent] = useState(""); + const [id, setId] = useState(null); + + const token = isAutheticated(); + const handleContentChange = (content, delta, source, editor) => { + setContent(editor.getHTML()); + }; + const getAboutUs = async () => { + const response = await axios.get("/api/content/about-us", { + headers: { + Authorization: `Bearer ${token}`, + }, + }); + if (response.status === 200) { + + setContent(response?.data?.aboutUs[0]?.aboutUsContent); + setId(response?.data?.aboutUs[0]?._id); + setOlderContent( + response?.data?.aboutUs[0]?.aboutUsContent + ); + } + }; + + const addAboutUs = async () => { + const response = await axios.post( + "/api/content/about-us", + { content }, + { + headers: { + Authorization: `Bearer ${token}`, + }, + } + ); + if (response.status == 201) { + swal({ + title: "Congratulations!!", + text: "About us added successfully!", + icon: "success", + button: "OK", + }); + } + }; + const handleCancelClick = () => { + setContent(olderContent); + }; + const updateContent = async () => { + const response = await axios.patch( + "/api/content/about-us-update", + { content }, + { + params: { id: id }, + headers: { + Authorization: `Bearer ${token}`, + }, + } + + ); + if (response.status === 200) { + swal({ + title: "Congratulations!", + text: "About Us updated successfully!", + icon: "success", + button: "OK", + }); + } else { + swal({ + title: "Sorry, please try again", + text: "Something went wrong!", + icon: "error", + button: "Retry", + dangerMode: true, + }); + } + }; + const handleSaveClick = async () => { + if (olderContent === undefined && olderContent.length===0) { + await addAboutUs(); + setAdded(true); + } else { + setAdded(false); + await updateContent(); + } + // // Reload terms and conditions + // await getAboutUs(); + }; + useEffect(() => { + // addTermsandConditions(); + getAboutUs(); + }, [added]); + return ( +
+
+ + +
+ + + + {" "} + {title} :{" "} + + Body + + +
+ ); + } \ No newline at end of file diff --git a/src/views/Content/editPrivacyPolicy.js b/src/views/Content/editPrivacyPolicy.js index 5f1837b..0bd944b 100644 --- a/src/views/Content/editPrivacyPolicy.js +++ b/src/views/Content/editPrivacyPolicy.js @@ -58,7 +58,7 @@ export default function EditPrivacyPolicy() { if (response.status == 201) { swal({ title: "Congratulations!!", - text: "Terms and condition added successfully!", + text: "privacy and policy added successfully!", icon: "success", button: "OK", }); From 96aa760129be5735106d00ed63a8c8beffca9c9d Mon Sep 17 00:00:00 2001 From: Sibunnayak Date: Fri, 5 Apr 2024 12:02:55 +0530 Subject: [PATCH 3/3] Chart Update --- src/_nav.js | 43 ++++++++++++++++++++++++++++++ src/routes.js | 39 +++++++++++++++++++++++++++ src/views/Charts/CityRevenue.js | 27 +++++++++++++++++++ src/views/Charts/OrderDaywise.js | 27 +++++++++++++++++++ src/views/Charts/ProductRevenue.js | 27 +++++++++++++++++++ src/views/Charts/RevenueCharts.js | 27 +++++++++++++++++++ src/views/Charts/Staterevenue.js | 27 +++++++++++++++++++ src/views/Charts/UserChart.js | 27 +++++++++++++++++++ src/views/dashboard/Dashboard.js | 9 +++++-- 9 files changed, 251 insertions(+), 2 deletions(-) create mode 100644 src/views/Charts/CityRevenue.js create mode 100644 src/views/Charts/OrderDaywise.js create mode 100644 src/views/Charts/ProductRevenue.js create mode 100644 src/views/Charts/RevenueCharts.js create mode 100644 src/views/Charts/Staterevenue.js create mode 100644 src/views/Charts/UserChart.js diff --git a/src/_nav.js b/src/_nav.js index db9cefb..896540c 100644 --- a/src/_nav.js +++ b/src/_nav.js @@ -45,6 +45,49 @@ const _nav = [ // icon: , // to: "/design", // }, + { + component: CNavGroup, + name: "Charts", + icon: , + items: [ + { + component: CNavItem, + name: "new user day wise", + icon: , + to: "/new-user-day-wise", + }, + { + component: CNavItem, + name: "Revenue By Product", + icon: , + to: "/revenue-by-product", + }, + { + component: CNavItem, + name: "Revenue By State", + icon: , + to: "/revenue-by-state", + }, + { + component: CNavItem, + name: "Revenue By City", + icon: , + to: "/revenue-by-city", + }, + { + component: CNavItem, + name: "Orders (Day Wise)", + icon: , + to: "/orders-day-wise", + }, + { + component: CNavItem, + name: "Revenue (Day Wise)", + icon: , + to: "/revenue-day-wise", + }, + ], + }, { component: CNavGroup, diff --git a/src/routes.js b/src/routes.js index c8f5c9c..ce7c7d2 100644 --- a/src/routes.js +++ b/src/routes.js @@ -121,6 +121,14 @@ import CreateBlog from "./views/Blog/CreateBlog"; import users from "./views/Users/users"; import UpdateBlog from "./views/Blog/EditBlog"; import ViewBlog from "./views/Blog/ViewBlog"; +import Charts from "./views/Charts/RevenueCharts"; +import UserCharts from "./views/Charts/UserChart"; +import ProductrevenueCharts from "./views/Charts/ProductRevenue"; +import StateRevenueCharts from "./views/Charts/Staterevenue"; +import CityRevenueCharts from "./views/Charts/CityRevenue"; +import { element } from "prop-types"; +import OrderdayChart from "./views/Charts/OrderDaywise"; +import RevenueCharts from "./views/Charts/RevenueCharts"; const routes = [ { path: "/", exact: true, name: "Home" }, { @@ -505,6 +513,37 @@ const routes = [ name: "Blogs", element: ViewBlog, }, + //Charts + { + path: "/new-user-day-wise", + name: "new user day wise", + element: UserCharts, + }, + { + path: "/revenue-by-product", + name: "Revenue By Product", + element: ProductrevenueCharts, + }, + { + path: "/revenue-by-state", + name: "Revenue By State", + element: StateRevenueCharts, + }, + { + path: "/revenue-by-city", + name: "Revenue By City", + element: CityRevenueCharts, + }, + { + path: "/orders-day-wise", + name: "Orders (Day Wise)", + element: OrderdayChart, + }, + { + path: "/revenue-day-wise", + name: "Revenue (Day Wise)", + element: RevenueCharts, + }, ]; export default routes; diff --git a/src/views/Charts/CityRevenue.js b/src/views/Charts/CityRevenue.js new file mode 100644 index 0000000..6cf4db2 --- /dev/null +++ b/src/views/Charts/CityRevenue.js @@ -0,0 +1,27 @@ +import { isAutheticated } from "../../auth.js"; + +const CityRevenueCharts = () => { + const token = isAutheticated(); + + return ( +
+ {token ? ( + + ) : ( +

No charts available

+ )} +
+ ); +}; + +export default CityRevenueCharts; \ No newline at end of file diff --git a/src/views/Charts/OrderDaywise.js b/src/views/Charts/OrderDaywise.js new file mode 100644 index 0000000..08f4373 --- /dev/null +++ b/src/views/Charts/OrderDaywise.js @@ -0,0 +1,27 @@ +import { isAutheticated } from "../../auth.js"; + +const OrderdayChart = () => { + const token = isAutheticated(); + + return ( +
+ {token ? ( + + ) : ( +

No charts available

+ )} +
+ ); +}; + +export default OrderdayChart; diff --git a/src/views/Charts/ProductRevenue.js b/src/views/Charts/ProductRevenue.js new file mode 100644 index 0000000..d6bb0c5 --- /dev/null +++ b/src/views/Charts/ProductRevenue.js @@ -0,0 +1,27 @@ +import { isAutheticated } from "../../auth.js"; + +const ProductrevenueCharts = () => { + const token = isAutheticated(); + + return ( +
+ {token ? ( + + ) : ( +

No charts available

+ )} +
+ ); +}; + +export default ProductrevenueCharts; diff --git a/src/views/Charts/RevenueCharts.js b/src/views/Charts/RevenueCharts.js new file mode 100644 index 0000000..40a9cf6 --- /dev/null +++ b/src/views/Charts/RevenueCharts.js @@ -0,0 +1,27 @@ +import { isAutheticated } from "../../auth.js"; + +const RevenueCharts = () => { + const token = isAutheticated(); + + return ( +
+ {token ? ( + + ) : ( +

No charts available

+ )} +
+ ); +}; + +export default RevenueCharts; diff --git a/src/views/Charts/Staterevenue.js b/src/views/Charts/Staterevenue.js new file mode 100644 index 0000000..c584d5b --- /dev/null +++ b/src/views/Charts/Staterevenue.js @@ -0,0 +1,27 @@ +import { isAutheticated } from "../../auth.js"; + +const StateRevenueCharts = () => { + const token = isAutheticated(); + + return ( +
+ {token ? ( + + ) : ( +

No charts available

+ )} +
+ ); +}; + +export default StateRevenueCharts; \ No newline at end of file diff --git a/src/views/Charts/UserChart.js b/src/views/Charts/UserChart.js new file mode 100644 index 0000000..e99dcfc --- /dev/null +++ b/src/views/Charts/UserChart.js @@ -0,0 +1,27 @@ +import { isAutheticated } from "../../auth.js"; + +const UserCharts = () => { + const token = isAutheticated(); + + return ( +
+ {token ? ( + + ) : ( +

No charts available

+ )} +
+ ); +}; + +export default UserCharts; diff --git a/src/views/dashboard/Dashboard.js b/src/views/dashboard/Dashboard.js index 88a69c8..805fa64 100644 --- a/src/views/dashboard/Dashboard.js +++ b/src/views/dashboard/Dashboard.js @@ -51,7 +51,7 @@ const Dashboard = () => { }); // console.log(res.data); setRequests(res.data.contactRequest); - } + }; // //3 requiment // const [requirement, setRequirement] = useState([]) @@ -124,7 +124,12 @@ const Dashboard = () => { }, [token]); return ( <> - + ); };