diff --git a/src/_nav.js b/src/_nav.js index ab19495..db9cefb 100644 --- a/src/_nav.js +++ b/src/_nav.js @@ -35,9 +35,9 @@ const _nav = [ }, { component: CNavItem, - name: "Users", + name: "Customers", icon: , - to: "/users-address", + to: "/customers-details", }, // { // component: CNavItem, diff --git a/src/routes.js b/src/routes.js index 78494c5..80a1c1d 100644 --- a/src/routes.js +++ b/src/routes.js @@ -92,10 +92,10 @@ 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"; -import AddUserAddress from "./views/UserAddress/addUserAddress"; -import ViewAddress from "./views/UserAddress/viewAddress"; +import UserTable from "./views/customerDetails/userTable"; +// import EditUserAddress from "./views/customerDetails/editUserAddress"; +// import AddUserAddress from "./views/customerDetails/addUserAddress"; +import viewDetails from "./views/customerDetails/viewDetails"; import Design from "./views/Design/design"; import Banners from "./views/Banner/banner"; import RegisterImage from "./views/Images/RegisterImage"; @@ -119,6 +119,7 @@ import EditTestimonial from "./views/Testimonials/EditTestimonial"; //Blogs import Blogs from "./views/Blog/Blogs"; import CreateBlog from "./views/Blog/CreateBlog"; +import users from "./views/Users/users"; import UpdateBlog from "./views/Blog/EditBlog"; import ViewBlog from "./views/Blog/ViewBlog"; const routes = [ @@ -161,24 +162,24 @@ const routes = [ }, { - path: "/users-address", + path: "/customers-details", name: "User Table", element: UserTable, }, + // { + // path: "/users-address/add", + // name: "User Address", + // element: AddUserAddress, + // }, + // { + // path: "/users-address/edit/:id", + // name: "Edit user address", + // element: EditUserAddress, + // }, { - path: "/users-address/add", - name: "User Address", - element: AddUserAddress, - }, - { - path: "/users-address/edit/:id", - name: "Edit user address", - element: EditUserAddress, - }, - { - path: "/users-address/view/:id", + path: "/users-address/view", name: "view address", - element: ViewAddress, + element: viewDetails, }, // health care providers diff --git a/src/views/Users/users.js b/src/views/Users/users.js index 57c1bd9..e581c77 100644 --- a/src/views/Users/users.js +++ b/src/views/Users/users.js @@ -1,153 +1,142 @@ - import axios from "axios"; import React, { useEffect, useState, useCallback, useMemo } from "react"; import Pagination from "./Pagination"; import { Link } from "react-router-dom"; -import swal from 'sweetalert'; +import swal from "sweetalert"; // import { API } from "../../data"; import { isAutheticated } from "../../auth"; function users() { - const [users, setUsers] = useState([]) + const [users, setUsers] = useState([]); + const [currentPage, setCurrentPage] = useState(1); + const [userPerPage] = useState(10); + const token = isAutheticated(); - const [currentPage, setCurrentPage] = useState(1); - const [userPerPage] = useState(10); - const token = isAutheticated(); + const getAllUsers = useCallback(async () => { + let res = await axios.get(`/api/v1/admin/users`, { + headers: { + Authorization: `Bearer ${token}`, + }, + }); + // console.log(res.data) + setUsers(res.data.users); + }, [token]); - const getAllUsers = useCallback(async () => { - let res = await axios.get( - `/api/v1/admin/users`, - { - headers: { - Authorization: `Bearer ${token}`, - }, - } - ); - // console.log(res.data) - setUsers(res.data.users) + useEffect(() => { + getAllUsers(); + }, [getAllUsers]); + // console.log(cmsRes) - }, [token]); + // Get current posts + //pagination + const indexOfLastUser = currentPage * userPerPage; + const indexOfFirstUser = indexOfLastUser - userPerPage; + const currentUser = users.slice(indexOfFirstUser, indexOfLastUser); - useEffect(() => { - getAllUsers(); - }, [getAllUsers]); + // Change page + const paginate = (pageNumber) => setCurrentPage(pageNumber); + //change time formate + function formatAMPM(date) { + var hours = new Date(date).getHours(); + var minutes = new Date(date).getMinutes(); + var ampm = hours >= 12 ? "PM" : "AM"; + hours = hours % 12; + hours = hours ? hours : 12; // the hour '0' should be '12' + minutes = minutes < 10 ? "0" + minutes : minutes; + var strTime = hours + ":" + minutes + " " + ampm; + return strTime; + } - // console.log(cmsRes) - - // Get current posts - //pagination - const indexOfLastUser = currentPage * userPerPage; - const indexOfFirstUser = indexOfLastUser - userPerPage; - const currentUser = users.slice(indexOfFirstUser, indexOfLastUser); - - // Change page - const paginate = pageNumber => setCurrentPage(pageNumber); - - //change time formate - function formatAMPM(date) { - var hours = new Date(date).getHours(); - var minutes = new Date(date).getMinutes(); - var ampm = hours >= 12 ? 'PM' : 'AM'; - hours = hours % 12; - hours = hours ? hours : 12; // the hour '0' should be '12' - minutes = minutes < 10 ? '0' + minutes : minutes; - var strTime = hours + ':' + minutes + ' ' + ampm; - return strTime; - } - - - - return ( - <> -
-
-
- {/* */} -
-
-
-

CMP - All Users

- -
-
-
- {/* */} - -
-
-
-
-
- -
-
- - - - - - - - - - - - - - {currentUser && currentUser.map((item, index) => - - - - - - - - - - - - - - - )} - -
NameemailProfile ImagePhone No.Register AtAction
{item?.name}{item?.email} - - {item?.phone} - - {new Date(`${item?.createdAt}`).toDateString()} , {`${formatAMPM(item?.createdAt)}`} - - - - - - - - -
-
- {/* */} -
-
-
-
-
- {/* */} + return ( + <> +
+
+
+ {/* */} +
+
+
+

All Customers

+
- - - ); + {/* */} + +
+
+
+
+
+
+ + + + + + {/* */} + + + + + + + + + {currentUser && + currentUser.map((item, index) => ( + + + + {/* */} + + + + + + + + ))} + +
Customer NameUnique Id Profile ImageDate RegisteredLast PurchaseOrdersAction
{item?.name}{item?._id} + + + {new Date( + `${item?.createdAt}` + ).toDateString()} + + {" "} + , {`${formatAMPM(item?.createdAt)}`} + + last Purchaseorder count + + + +
+
+ {/* */} +
+
+
+
+
+ {/* */} +
+
+ + + ); } export default users; diff --git a/src/views/UserAddress/addUserAddress.js b/src/views/customerDetails/addUserAddress.js similarity index 100% rename from src/views/UserAddress/addUserAddress.js rename to src/views/customerDetails/addUserAddress.js diff --git a/src/views/UserAddress/editUserAddress.js b/src/views/customerDetails/editUserAddress.js similarity index 100% rename from src/views/UserAddress/editUserAddress.js rename to src/views/customerDetails/editUserAddress.js diff --git a/src/views/UserAddress/mainAddress.js b/src/views/customerDetails/mainAddress.js similarity index 100% rename from src/views/UserAddress/mainAddress.js rename to src/views/customerDetails/mainAddress.js diff --git a/src/views/customerDetails/orderDetails.js b/src/views/customerDetails/orderDetails.js new file mode 100644 index 0000000..3d7d50d --- /dev/null +++ b/src/views/customerDetails/orderDetails.js @@ -0,0 +1,70 @@ +import axios from "axios"; +import React, { useState, useEffect } from "react"; +import { isAutheticated } from "src/auth"; +import swal from "sweetalert"; + +const OrderDetails = ({ _id, setLoading1 }) => { + const token = isAutheticated(); + const [userOrder, setUserOrder] = useState(); + // const [loading, setLoading] = useState(true); + + const getOrders = async () => { + try { + const response = await axios.get(`/api/v1/admin/users/orders/${_id}`, { + headers: { + Authorization: `Bearer ${token}`, + }, + }); + setUserOrder(response.data.order); + setLoading1(false); + } catch (error) { + console.error("Error fetching orders:", error); + swal({ + title: "Warning", + text: error.message, + icon: "error", + button: "Close", + dangerMode: true, + }); + setLoading1(false); + } + }; + + useEffect(() => { + getOrders(); + }, [_id]); + console.log(userOrder, "userOrder"); + + // if (loading) { + // return
Loading...
; + // } + + return ( + <> + + {userOrder?.length > 0 + ? new Date(userOrder[0]?.createdAt).toLocaleString("en-IN", { + weekday: "short", + month: "short", + day: "numeric", + year: "numeric", + hour: "numeric", + minute: "numeric", + hour12: true, + }) + : userOrder + ? "No Purchase" + : "Error"} + + + {userOrder?.length > 0 + ? userOrder?.length + : userOrder + ? "No Order" + : "Error"} + + + ); +}; + +export default OrderDetails; diff --git a/src/views/UserAddress/userTable.js b/src/views/customerDetails/userTable.js similarity index 75% rename from src/views/UserAddress/userTable.js rename to src/views/customerDetails/userTable.js index 64d5b88..9d44431 100644 --- a/src/views/UserAddress/userTable.js +++ b/src/views/customerDetails/userTable.js @@ -17,32 +17,34 @@ import { import SearchIcon from "@mui/icons-material/Search"; import Fuse from "fuse.js"; import { Typography } from "@material-ui/core"; +import OrderDetails from "./orderDetails"; const UserTable = () => { const token = isAutheticated(); const [query, setQuery] = useState(""); const navigate = useNavigate(); const [loading, setLoading] = useState(true); + const [loading1, setLoading1] = useState(true); const [success, setSuccess] = useState(true); - const [userAddress, setUserAddress] = useState([]); + const [users, setUsers] = useState([]); const [currentPage, setCurrentPage] = useState(1); const [itemPerPage, setItemPerPage] = useState(10); - const [showData, setShowData] = useState(userAddress); + const [showData, setShowData] = useState(users); const handleShowEntries = (e) => { setCurrentPage(1); setItemPerPage(e.target.value); }; - const getUserAddressess = async () => { + const getUsers = async () => { axios - .get(`/api/user-address/getAddressess`, { + .get(`/api/v1/admin/users`, { headers: { Authorization: `Bearer ${token}`, }, }) .then((res) => { - setUserAddress(res.data?.userAddress); + setUsers(res.data.users); setLoading(false); }) .catch((error) => { @@ -58,57 +60,58 @@ const UserTable = () => { }; useEffect(() => { - getUserAddressess(); + getUsers(); }, [success]); - console.log(userAddress); + console.log(users); useEffect(() => { const loadData = () => { const indexOfLastPost = currentPage * itemPerPage; const indexOfFirstPost = indexOfLastPost - itemPerPage; - setShowData(userAddress.slice(indexOfFirstPost, indexOfLastPost)); + setShowData(users.slice(indexOfFirstPost, indexOfLastPost)); }; loadData(); - }, [currentPage, itemPerPage, userAddress]); + }, [currentPage, itemPerPage, users]); + console.log(users); - const handleDelete = (id) => { - swal({ - title: "Are you sure?", - icon: "error", - buttons: { - Yes: { text: "Yes", value: true }, - Cancel: { text: "Cancel", value: "cancel" }, - }, - }).then((value) => { - if (value === true) { - axios - .delete(`/api/user-address/deleteAddress/${id}`, { - headers: { - "Access-Control-Allow-Origin": "*", - Authorization: `Bearer ${token}`, - }, - }) - .then((res) => { - swal({ - title: "Deleted", - text: "Address Deleted successfully!", - icon: "success", - button: "ok", - }); - setSuccess((prev) => !prev); - }) - .catch((err) => { - swal({ - title: "Warning", - text: "Something went wrong!", - icon: "error", - button: "Retry", - dangerMode: true, - }); - }); - } - }); - }; + // const handleDelete = (id) => { + // swal({ + // title: "Are you sure?", + // icon: "error", + // buttons: { + // Yes: { text: "Yes", value: true }, + // Cancel: { text: "Cancel", value: "cancel" }, + // }, + // }).then((value) => { + // if (value === true) { + // axios + // .delete(`/api/user-address/deleteAddress/${id}`, { + // headers: { + // "Access-Control-Allow-Origin": "*", + // Authorization: `Bearer ${token}`, + // }, + // }) + // .then((res) => { + // swal({ + // title: "Deleted", + // text: "Address Deleted successfully!", + // icon: "success", + // button: "ok", + // }); + // setSuccess((prev) => !prev); + // }) + // .catch((err) => { + // swal({ + // title: "Warning", + // text: "Something went wrong!", + // icon: "error", + // button: "Retry", + // dangerMode: true, + // }); + // }); + // } + // }); + // }; return (
@@ -125,10 +128,10 @@ const UserTable = () => { " >
- Users + All Customers
-
+ {/*
-
+
*/}
@@ -188,12 +191,14 @@ const UserTable = () => { style={{ background: "rgb(140, 213, 213)" }} > - Id - User Name - Email + Customer Name + Unique Id + {/* Profile Image */} - Added On - Actions + Date Registered + Last Purchase + Orders + Action @@ -211,32 +216,40 @@ const UserTable = () => { ) : ( - showData.map((userAddress, i) => { + showData.map((user, i) => { return ( - {userAddress._id} - - {userAddress.name} - - - {userAddress.email} - + {user.name} + {user._id} - {new Date( - userAddress.createdAt - ).toLocaleString("en-IN", { - weekday: "short", - month: "short", - day: "numeric", - year: "numeric", - hour: "numeric", - minute: "numeric", - hour12: true, - })} + {new Date(user.createdAt).toLocaleString( + "en-IN", + { + weekday: "short", + month: "short", + day: "numeric", + year: "numeric", + hour: "numeric", + minute: "numeric", + hour12: true, + } + )} + {loading1 && ( + <> + loading... + loading... + + )} + + + - + */} + + @@ -318,11 +339,8 @@ const UserTable = () => { aria-live="polite" > Showing {currentPage * itemPerPage - itemPerPage + 1} to{" "} - {Math.min( - currentPage * itemPerPage, - userAddress.length - )}{" "} - of {userAddress.length} entries + {Math.min(currentPage * itemPerPage, users.length)} of{" "} + {users.length} entries @@ -370,7 +388,7 @@ const UserTable = () => { {!( (currentPage + 1) * itemPerPage - itemPerPage > - userAddress.length - 1 + users.length - 1 ) && (
  • { className={ !( (currentPage + 1) * itemPerPage - itemPerPage > - userAddress.length - 1 + users.length - 1 ) ? "paginate_button page-item next" : "paginate_button page-item next disabled" diff --git a/src/views/UserAddress/viewAddress.js b/src/views/customerDetails/viewDetails.js similarity index 100% rename from src/views/UserAddress/viewAddress.js rename to src/views/customerDetails/viewDetails.js 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;