Merge branch 'master' of http://128.199.30.231/possibillion/smellika-admin
This commit is contained in:
commit
dfa6067a19
@ -35,9 +35,9 @@ const _nav = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
component: CNavItem,
|
component: CNavItem,
|
||||||
name: "Users",
|
name: "Customers",
|
||||||
icon: <CIcon icon={cilTennisBall} customClassName="nav-icon" />,
|
icon: <CIcon icon={cilTennisBall} customClassName="nav-icon" />,
|
||||||
to: "/users-address",
|
to: "/customers-details",
|
||||||
},
|
},
|
||||||
// {
|
// {
|
||||||
// component: CNavItem,
|
// component: CNavItem,
|
||||||
|
@ -92,10 +92,10 @@ import EditShippingPolicy from "./views/Content/editShippingPolicy";
|
|||||||
import EditRefundpolicy from "./views/Content/editRefundPolicy";
|
import EditRefundpolicy from "./views/Content/editRefundPolicy";
|
||||||
import EditAboutUs from "./views/Content/editAboutUs";
|
import EditAboutUs from "./views/Content/editAboutUs";
|
||||||
|
|
||||||
import UserTable from "./views/UserAddress/userTable";
|
import UserTable from "./views/customerDetails/userTable";
|
||||||
import EditUserAddress from "./views/UserAddress/editUserAddress";
|
// import EditUserAddress from "./views/customerDetails/editUserAddress";
|
||||||
import AddUserAddress from "./views/UserAddress/addUserAddress";
|
// import AddUserAddress from "./views/customerDetails/addUserAddress";
|
||||||
import ViewAddress from "./views/UserAddress/viewAddress";
|
import viewDetails from "./views/customerDetails/viewDetails";
|
||||||
import Design from "./views/Design/design";
|
import Design from "./views/Design/design";
|
||||||
import Banners from "./views/Banner/banner";
|
import Banners from "./views/Banner/banner";
|
||||||
import RegisterImage from "./views/Images/RegisterImage";
|
import RegisterImage from "./views/Images/RegisterImage";
|
||||||
@ -119,6 +119,7 @@ import EditTestimonial from "./views/Testimonials/EditTestimonial";
|
|||||||
//Blogs
|
//Blogs
|
||||||
import Blogs from "./views/Blog/Blogs";
|
import Blogs from "./views/Blog/Blogs";
|
||||||
import CreateBlog from "./views/Blog/CreateBlog";
|
import CreateBlog from "./views/Blog/CreateBlog";
|
||||||
|
import users from "./views/Users/users";
|
||||||
import UpdateBlog from "./views/Blog/EditBlog";
|
import UpdateBlog from "./views/Blog/EditBlog";
|
||||||
import ViewBlog from "./views/Blog/ViewBlog";
|
import ViewBlog from "./views/Blog/ViewBlog";
|
||||||
const routes = [
|
const routes = [
|
||||||
@ -161,24 +162,24 @@ const routes = [
|
|||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
path: "/users-address",
|
path: "/customers-details",
|
||||||
name: "User Table",
|
name: "User Table",
|
||||||
element: UserTable,
|
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",
|
path: "/users-address/view",
|
||||||
name: "User Address",
|
|
||||||
element: AddUserAddress,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: "/users-address/edit/:id",
|
|
||||||
name: "Edit user address",
|
|
||||||
element: EditUserAddress,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: "/users-address/view/:id",
|
|
||||||
name: "view address",
|
name: "view address",
|
||||||
element: ViewAddress,
|
element: viewDetails,
|
||||||
},
|
},
|
||||||
|
|
||||||
// health care providers
|
// health care providers
|
||||||
|
@ -1,40 +1,32 @@
|
|||||||
|
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import React, { useEffect, useState, useCallback, useMemo } from "react";
|
import React, { useEffect, useState, useCallback, useMemo } from "react";
|
||||||
import Pagination from "./Pagination";
|
import Pagination from "./Pagination";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
import swal from 'sweetalert';
|
import swal from "sweetalert";
|
||||||
// import { API } from "../../data";
|
// import { API } from "../../data";
|
||||||
import { isAutheticated } from "../../auth";
|
import { isAutheticated } from "../../auth";
|
||||||
|
|
||||||
function users() {
|
function users() {
|
||||||
const [users, setUsers] = useState([])
|
const [users, setUsers] = useState([]);
|
||||||
|
|
||||||
|
|
||||||
const [currentPage, setCurrentPage] = useState(1);
|
const [currentPage, setCurrentPage] = useState(1);
|
||||||
const [userPerPage] = useState(10);
|
const [userPerPage] = useState(10);
|
||||||
const token = isAutheticated();
|
const token = isAutheticated();
|
||||||
|
|
||||||
const getAllUsers = useCallback(async () => {
|
const getAllUsers = useCallback(async () => {
|
||||||
let res = await axios.get(
|
let res = await axios.get(`/api/v1/admin/users`, {
|
||||||
`/api/v1/admin/users`,
|
|
||||||
{
|
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
},
|
},
|
||||||
}
|
});
|
||||||
);
|
|
||||||
// console.log(res.data)
|
// console.log(res.data)
|
||||||
setUsers(res.data.users)
|
setUsers(res.data.users);
|
||||||
|
|
||||||
|
|
||||||
}, [token]);
|
}, [token]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getAllUsers();
|
getAllUsers();
|
||||||
}, [getAllUsers]);
|
}, [getAllUsers]);
|
||||||
|
|
||||||
|
|
||||||
// console.log(cmsRes)
|
// console.log(cmsRes)
|
||||||
|
|
||||||
// Get current posts
|
// Get current posts
|
||||||
@ -44,22 +36,20 @@ function users() {
|
|||||||
const currentUser = users.slice(indexOfFirstUser, indexOfLastUser);
|
const currentUser = users.slice(indexOfFirstUser, indexOfLastUser);
|
||||||
|
|
||||||
// Change page
|
// Change page
|
||||||
const paginate = pageNumber => setCurrentPage(pageNumber);
|
const paginate = (pageNumber) => setCurrentPage(pageNumber);
|
||||||
|
|
||||||
//change time formate
|
//change time formate
|
||||||
function formatAMPM(date) {
|
function formatAMPM(date) {
|
||||||
var hours = new Date(date).getHours();
|
var hours = new Date(date).getHours();
|
||||||
var minutes = new Date(date).getMinutes();
|
var minutes = new Date(date).getMinutes();
|
||||||
var ampm = hours >= 12 ? 'PM' : 'AM';
|
var ampm = hours >= 12 ? "PM" : "AM";
|
||||||
hours = hours % 12;
|
hours = hours % 12;
|
||||||
hours = hours ? hours : 12; // the hour '0' should be '12'
|
hours = hours ? hours : 12; // the hour '0' should be '12'
|
||||||
minutes = minutes < 10 ? '0' + minutes : minutes;
|
minutes = minutes < 10 ? "0" + minutes : minutes;
|
||||||
var strTime = hours + ':' + minutes + ' ' + ampm;
|
var strTime = hours + ":" + minutes + " " + ampm;
|
||||||
return strTime;
|
return strTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className=" main-content">
|
<div className=" main-content">
|
||||||
@ -69,8 +59,7 @@ function users() {
|
|||||||
<div className="row">
|
<div className="row">
|
||||||
<div className="col-12">
|
<div className="col-12">
|
||||||
<div className="page-title-box d-flex align-items-center justify-content-between">
|
<div className="page-title-box d-flex align-items-center justify-content-between">
|
||||||
<h4 className="mb-3">CMP - All Users</h4>
|
<h4 className="mb-3"> All Customers</h4>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -80,45 +69,45 @@ function users() {
|
|||||||
<div className="col-lg-12">
|
<div className="col-lg-12">
|
||||||
<div className="card">
|
<div className="card">
|
||||||
<div className="card-body">
|
<div className="card-body">
|
||||||
<div className="row ml-0 mr-0 mb-10">
|
<div className="row ml-0 mr-0 mb-10"></div>
|
||||||
|
|
||||||
</div>
|
|
||||||
<div className="table-responsive table-shoot">
|
<div className="table-responsive table-shoot">
|
||||||
<table className="table table-centered table-nowrap mb-0">
|
<table className="table table-centered table-nowrap mb-0">
|
||||||
<thead className="thead-light">
|
<thead className="thead-light">
|
||||||
<tr>
|
<tr>
|
||||||
|
<th>Customer Name</th>
|
||||||
|
<th>Unique Id </th>
|
||||||
|
{/* <th>Profile Image</th> */}
|
||||||
|
|
||||||
<th>Name</th>
|
<th>Date Registered</th>
|
||||||
<th>email</th>
|
<th>Last Purchase</th>
|
||||||
<th>Profile Image</th>
|
<th>Orders</th>
|
||||||
<th>Phone No.</th>
|
|
||||||
<th>Register At</th>
|
|
||||||
<th>Action</th>
|
<th>Action</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{currentUser && currentUser.map((item, index) =>
|
{currentUser &&
|
||||||
|
currentUser.map((item, index) => (
|
||||||
<tr>
|
<tr>
|
||||||
|
|
||||||
<td>{item?.name}</td>
|
<td>{item?.name}</td>
|
||||||
<td>{item?.email}</td>
|
<td>{item?._id}</td>
|
||||||
<td>
|
{/* <td>
|
||||||
<img src={`${item.avatar?.url}`} width="50" alt="" />
|
<img src={`${item.avatar?.url}`} width="50" alt="" />
|
||||||
</td>
|
</td> */}
|
||||||
<td>{item?.phone}</td>
|
|
||||||
|
|
||||||
|
|
||||||
<td>
|
<td>
|
||||||
|
{new Date(
|
||||||
{new Date(`${item?.createdAt}`).toDateString()}<span> , {`${formatAMPM(item?.createdAt)}`}</span>
|
`${item?.createdAt}`
|
||||||
|
).toDateString()}
|
||||||
|
<span>
|
||||||
|
{" "}
|
||||||
|
, {`${formatAMPM(item?.createdAt)}`}
|
||||||
|
</span>
|
||||||
</td>
|
</td>
|
||||||
|
<td>last Purchase</td>
|
||||||
|
<td>order count </td>
|
||||||
|
|
||||||
<td>
|
<td>
|
||||||
<Link to={`/users/view/${item._id}`}>
|
<Link to={`/users/view/${item._id}`}>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className="mt-1 btn btn-info btn-sm waves-effect waves-light btn-table ml-2"
|
className="mt-1 btn btn-info btn-sm waves-effect waves-light btn-table ml-2"
|
||||||
@ -126,11 +115,9 @@ function users() {
|
|||||||
View
|
View
|
||||||
</button>
|
</button>
|
||||||
</Link>
|
</Link>
|
||||||
|
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
)}
|
))}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
@ -143,9 +130,11 @@ function users() {
|
|||||||
{/* <!-- container-fluid --> */}
|
{/* <!-- container-fluid --> */}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Pagination userPerPage={userPerPage}
|
<Pagination
|
||||||
|
userPerPage={userPerPage}
|
||||||
totalUsers={users.length}
|
totalUsers={users.length}
|
||||||
paginate={paginate} />
|
paginate={paginate}
|
||||||
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
70
src/views/customerDetails/orderDetails.js
Normal file
70
src/views/customerDetails/orderDetails.js
Normal file
@ -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 <div>Loading...</div>;
|
||||||
|
// }
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<td className="text-start">
|
||||||
|
{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"}
|
||||||
|
</td>
|
||||||
|
<td className="text-start">
|
||||||
|
{userOrder?.length > 0
|
||||||
|
? userOrder?.length
|
||||||
|
: userOrder
|
||||||
|
? "No Order"
|
||||||
|
: "Error"}
|
||||||
|
</td>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default OrderDetails;
|
@ -17,32 +17,34 @@ import {
|
|||||||
import SearchIcon from "@mui/icons-material/Search";
|
import SearchIcon from "@mui/icons-material/Search";
|
||||||
import Fuse from "fuse.js";
|
import Fuse from "fuse.js";
|
||||||
import { Typography } from "@material-ui/core";
|
import { Typography } from "@material-ui/core";
|
||||||
|
import OrderDetails from "./orderDetails";
|
||||||
const UserTable = () => {
|
const UserTable = () => {
|
||||||
const token = isAutheticated();
|
const token = isAutheticated();
|
||||||
const [query, setQuery] = useState("");
|
const [query, setQuery] = useState("");
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [loading1, setLoading1] = useState(true);
|
||||||
const [success, setSuccess] = useState(true);
|
const [success, setSuccess] = useState(true);
|
||||||
const [userAddress, setUserAddress] = useState([]);
|
const [users, setUsers] = useState([]);
|
||||||
|
|
||||||
const [currentPage, setCurrentPage] = useState(1);
|
const [currentPage, setCurrentPage] = useState(1);
|
||||||
const [itemPerPage, setItemPerPage] = useState(10);
|
const [itemPerPage, setItemPerPage] = useState(10);
|
||||||
const [showData, setShowData] = useState(userAddress);
|
const [showData, setShowData] = useState(users);
|
||||||
|
|
||||||
const handleShowEntries = (e) => {
|
const handleShowEntries = (e) => {
|
||||||
setCurrentPage(1);
|
setCurrentPage(1);
|
||||||
setItemPerPage(e.target.value);
|
setItemPerPage(e.target.value);
|
||||||
};
|
};
|
||||||
|
|
||||||
const getUserAddressess = async () => {
|
const getUsers = async () => {
|
||||||
axios
|
axios
|
||||||
.get(`/api/user-address/getAddressess`, {
|
.get(`/api/v1/admin/users`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
setUserAddress(res.data?.userAddress);
|
setUsers(res.data.users);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
@ -58,57 +60,58 @@ const UserTable = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getUserAddressess();
|
getUsers();
|
||||||
}, [success]);
|
}, [success]);
|
||||||
console.log(userAddress);
|
console.log(users);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const loadData = () => {
|
const loadData = () => {
|
||||||
const indexOfLastPost = currentPage * itemPerPage;
|
const indexOfLastPost = currentPage * itemPerPage;
|
||||||
const indexOfFirstPost = indexOfLastPost - itemPerPage;
|
const indexOfFirstPost = indexOfLastPost - itemPerPage;
|
||||||
setShowData(userAddress.slice(indexOfFirstPost, indexOfLastPost));
|
setShowData(users.slice(indexOfFirstPost, indexOfLastPost));
|
||||||
};
|
};
|
||||||
loadData();
|
loadData();
|
||||||
}, [currentPage, itemPerPage, userAddress]);
|
}, [currentPage, itemPerPage, users]);
|
||||||
|
console.log(users);
|
||||||
|
|
||||||
const handleDelete = (id) => {
|
// const handleDelete = (id) => {
|
||||||
swal({
|
// swal({
|
||||||
title: "Are you sure?",
|
// title: "Are you sure?",
|
||||||
icon: "error",
|
// icon: "error",
|
||||||
buttons: {
|
// buttons: {
|
||||||
Yes: { text: "Yes", value: true },
|
// Yes: { text: "Yes", value: true },
|
||||||
Cancel: { text: "Cancel", value: "cancel" },
|
// Cancel: { text: "Cancel", value: "cancel" },
|
||||||
},
|
// },
|
||||||
}).then((value) => {
|
// }).then((value) => {
|
||||||
if (value === true) {
|
// if (value === true) {
|
||||||
axios
|
// axios
|
||||||
.delete(`/api/user-address/deleteAddress/${id}`, {
|
// .delete(`/api/user-address/deleteAddress/${id}`, {
|
||||||
headers: {
|
// headers: {
|
||||||
"Access-Control-Allow-Origin": "*",
|
// "Access-Control-Allow-Origin": "*",
|
||||||
Authorization: `Bearer ${token}`,
|
// Authorization: `Bearer ${token}`,
|
||||||
},
|
// },
|
||||||
})
|
// })
|
||||||
.then((res) => {
|
// .then((res) => {
|
||||||
swal({
|
// swal({
|
||||||
title: "Deleted",
|
// title: "Deleted",
|
||||||
text: "Address Deleted successfully!",
|
// text: "Address Deleted successfully!",
|
||||||
icon: "success",
|
// icon: "success",
|
||||||
button: "ok",
|
// button: "ok",
|
||||||
});
|
// });
|
||||||
setSuccess((prev) => !prev);
|
// setSuccess((prev) => !prev);
|
||||||
})
|
// })
|
||||||
.catch((err) => {
|
// .catch((err) => {
|
||||||
swal({
|
// swal({
|
||||||
title: "Warning",
|
// title: "Warning",
|
||||||
text: "Something went wrong!",
|
// text: "Something went wrong!",
|
||||||
icon: "error",
|
// icon: "error",
|
||||||
button: "Retry",
|
// button: "Retry",
|
||||||
dangerMode: true,
|
// dangerMode: true,
|
||||||
});
|
// });
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
};
|
// };
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="main-content">
|
<div className="main-content">
|
||||||
@ -125,10 +128,10 @@ const UserTable = () => {
|
|||||||
"
|
"
|
||||||
>
|
>
|
||||||
<div style={{ fontSize: "22px" }} className="fw-bold">
|
<div style={{ fontSize: "22px" }} className="fw-bold">
|
||||||
Users
|
All Customers
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="page-title-right">
|
{/* <div className="page-title-right">
|
||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
color="primary"
|
color="primary"
|
||||||
@ -143,7 +146,7 @@ const UserTable = () => {
|
|||||||
>
|
>
|
||||||
Add User
|
Add User
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div> */}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -188,12 +191,14 @@ const UserTable = () => {
|
|||||||
style={{ background: "rgb(140, 213, 213)" }}
|
style={{ background: "rgb(140, 213, 213)" }}
|
||||||
>
|
>
|
||||||
<tr>
|
<tr>
|
||||||
<th className="text-start">Id</th>
|
<th>Customer Name</th>
|
||||||
<th className="text-start">User Name</th>
|
<th>Unique Id </th>
|
||||||
<th className="text-start">Email</th>
|
{/* <th>Profile Image</th> */}
|
||||||
|
|
||||||
<th className="text-start">Added On</th>
|
<th>Date Registered</th>
|
||||||
<th className="text-start">Actions</th>
|
<th>Last Purchase</th>
|
||||||
|
<th>Orders</th>
|
||||||
|
<th>Action</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@ -211,21 +216,16 @@ const UserTable = () => {
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
) : (
|
) : (
|
||||||
showData.map((userAddress, i) => {
|
showData.map((user, i) => {
|
||||||
return (
|
return (
|
||||||
<tr key={i}>
|
<tr key={i}>
|
||||||
<td>{userAddress._id}</td>
|
<td className="text-start">{user.name}</td>
|
||||||
<td className="text-start">
|
<td>{user._id}</td>
|
||||||
{userAddress.name}
|
|
||||||
</td>
|
|
||||||
<td className="text-start">
|
|
||||||
{userAddress.email}
|
|
||||||
</td>
|
|
||||||
|
|
||||||
<td className="text-start">
|
<td className="text-start">
|
||||||
{new Date(
|
{new Date(user.createdAt).toLocaleString(
|
||||||
userAddress.createdAt
|
"en-IN",
|
||||||
).toLocaleString("en-IN", {
|
{
|
||||||
weekday: "short",
|
weekday: "short",
|
||||||
month: "short",
|
month: "short",
|
||||||
day: "numeric",
|
day: "numeric",
|
||||||
@ -233,10 +233,23 @@ const UserTable = () => {
|
|||||||
hour: "numeric",
|
hour: "numeric",
|
||||||
minute: "numeric",
|
minute: "numeric",
|
||||||
hour12: true,
|
hour12: true,
|
||||||
})}
|
}
|
||||||
|
)}
|
||||||
</td>
|
</td>
|
||||||
|
{loading1 && (
|
||||||
|
<>
|
||||||
|
<td className="text-start">loading...</td>
|
||||||
|
<td className="text-start">loading...</td>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<OrderDetails
|
||||||
|
_id={user?._id}
|
||||||
|
setLoading1={setLoading1}
|
||||||
|
/>
|
||||||
|
|
||||||
<td className="text-start">
|
<td className="text-start">
|
||||||
<Link
|
{/* <Link
|
||||||
to={`/users-address/view/${userAddress._id}`}
|
to={`/users-address/view/${userAddress._id}`}
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
@ -299,6 +312,14 @@ const UserTable = () => {
|
|||||||
>
|
>
|
||||||
Delete
|
Delete
|
||||||
</button>
|
</button>
|
||||||
|
</Link> */}
|
||||||
|
<Link to={`/users/view/${user._id}`}>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="mt-1 btn btn-info btn-sm waves-effect waves-light btn-table ml-2"
|
||||||
|
>
|
||||||
|
View
|
||||||
|
</button>
|
||||||
</Link>
|
</Link>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@ -318,11 +339,8 @@ const UserTable = () => {
|
|||||||
aria-live="polite"
|
aria-live="polite"
|
||||||
>
|
>
|
||||||
Showing {currentPage * itemPerPage - itemPerPage + 1} to{" "}
|
Showing {currentPage * itemPerPage - itemPerPage + 1} to{" "}
|
||||||
{Math.min(
|
{Math.min(currentPage * itemPerPage, users.length)} of{" "}
|
||||||
currentPage * itemPerPage,
|
{users.length} entries
|
||||||
userAddress.length
|
|
||||||
)}{" "}
|
|
||||||
of {userAddress.length} entries
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -370,7 +388,7 @@ const UserTable = () => {
|
|||||||
|
|
||||||
{!(
|
{!(
|
||||||
(currentPage + 1) * itemPerPage - itemPerPage >
|
(currentPage + 1) * itemPerPage - itemPerPage >
|
||||||
userAddress.length - 1
|
users.length - 1
|
||||||
) && (
|
) && (
|
||||||
<li className="paginate_button page-item ">
|
<li className="paginate_button page-item ">
|
||||||
<span
|
<span
|
||||||
@ -389,7 +407,7 @@ const UserTable = () => {
|
|||||||
className={
|
className={
|
||||||
!(
|
!(
|
||||||
(currentPage + 1) * itemPerPage - itemPerPage >
|
(currentPage + 1) * itemPerPage - itemPerPage >
|
||||||
userAddress.length - 1
|
users.length - 1
|
||||||
)
|
)
|
||||||
? "paginate_button page-item next"
|
? "paginate_button page-item next"
|
||||||
: "paginate_button page-item next disabled"
|
: "paginate_button page-item next disabled"
|
@ -1,44 +1,57 @@
|
|||||||
import React, { lazy } from 'react'
|
import React, { lazy } from "react";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { useEffect, useState, useCallback, useMemo } from "react";
|
import { useEffect, useState, useCallback, useMemo } from "react";
|
||||||
import { isAutheticated } from "../../auth.js";
|
import { isAutheticated } from "../../auth.js";
|
||||||
|
|
||||||
const WidgetsDropdown = lazy(() => import('../widgets/WidgetsDropdown.js'))
|
const WidgetsDropdown = lazy(() => import("../widgets/WidgetsDropdown.js"));
|
||||||
|
|
||||||
|
|
||||||
const Dashboard = () => {
|
const Dashboard = () => {
|
||||||
//1 st
|
//1 st
|
||||||
const [users, setUsers] = useState([])
|
const [users, setUsers] = useState([]);
|
||||||
const token = isAutheticated();
|
const token = isAutheticated();
|
||||||
|
|
||||||
const getAllUsers = async () => {
|
const getAllUsers = async () => {
|
||||||
let res = await axios.get(
|
let res = await axios.get(`/api/v1/admin/users`, {
|
||||||
`/api/v1/admin/users`,
|
|
||||||
{
|
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
},
|
},
|
||||||
}
|
});
|
||||||
);
|
|
||||||
// console.log(res.data)
|
// 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
|
// //3 requiment
|
||||||
// const [requirement, setRequirement] = useState([])
|
// const [requirement, setRequirement] = useState([])
|
||||||
@ -71,7 +84,6 @@ const Dashboard = () => {
|
|||||||
|
|
||||||
// setNews(res.data.news)
|
// setNews(res.data.news)
|
||||||
|
|
||||||
|
|
||||||
// }, [token]);
|
// }, [token]);
|
||||||
// //5 offers
|
// //5 offers
|
||||||
// const [offer, setOffer] = useState([])
|
// const [offer, setOffer] = useState([])
|
||||||
@ -88,7 +100,6 @@ const Dashboard = () => {
|
|||||||
// // console.log(res.data)
|
// // console.log(res.data)
|
||||||
// setOffer(res.data.offer)
|
// setOffer(res.data.offer)
|
||||||
|
|
||||||
|
|
||||||
// }, [token]);
|
// }, [token]);
|
||||||
// //6 event
|
// //6 event
|
||||||
// const [event, setEvent] = useState([])
|
// const [event, setEvent] = useState([])
|
||||||
@ -104,18 +115,18 @@ const Dashboard = () => {
|
|||||||
// // console.log(res.data)
|
// // console.log(res.data)
|
||||||
// setEvent(res.data.Event)
|
// setEvent(res.data.Event)
|
||||||
|
|
||||||
|
|
||||||
// }, [token]);
|
// }, [token]);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getAllUsers();
|
getAllUsers();
|
||||||
|
getAllCategory();
|
||||||
|
getAllProduct();
|
||||||
|
getAllRequests();
|
||||||
}, [token]);
|
}, [token]);
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<WidgetsDropdown users={users} />
|
<WidgetsDropdown users={users} category={category} product={product} Requests={Requests}/>
|
||||||
|
|
||||||
</>
|
</>
|
||||||
)
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
export default Dashboard
|
export default Dashboard;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import React from 'react'
|
import React, { useEffect, useState } from "react";
|
||||||
import {
|
import {
|
||||||
CRow,
|
CRow,
|
||||||
CCol,
|
CCol,
|
||||||
@ -7,45 +7,145 @@ import {
|
|||||||
CDropdownItem,
|
CDropdownItem,
|
||||||
CDropdownToggle,
|
CDropdownToggle,
|
||||||
CWidgetStatsA,
|
CWidgetStatsA,
|
||||||
} from '@coreui/react'
|
} from "@coreui/react";
|
||||||
import { getStyle } from '@coreui/utils'
|
import { getStyle } from "@coreui/utils";
|
||||||
import { CChartBar, CChartLine } from '@coreui/react-chartjs'
|
import { CChartBar, CChartLine } from "@coreui/react-chartjs";
|
||||||
import CIcon from '@coreui/icons-react'
|
import CIcon from "@coreui/icons-react";
|
||||||
import { cilArrowBottom, cilArrowTop, cilOptions } from '@coreui/icons'
|
import { cilArrowBottom, cilArrowTop, cilOptions } from "@coreui/icons";
|
||||||
import { BeatLoader } from 'react-spinners'
|
import { BeatLoader } from "react-spinners";
|
||||||
{/* <BeatLoader color="#36d7b7" /> */ }
|
import { isAutheticated } from "src/auth";
|
||||||
|
import axios from "axios";
|
||||||
|
{
|
||||||
|
/* <BeatLoader color="#36d7b7" /> */
|
||||||
|
}
|
||||||
|
|
||||||
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 (
|
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 (
|
||||||
|
<>
|
||||||
|
<h4>Users and Requests</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={
|
value={<>{users.length}</>}
|
||||||
<>
|
|
||||||
|
|
||||||
{users.length}
|
|
||||||
</>
|
|
||||||
}
|
|
||||||
title="Total Users"
|
title="Total Users"
|
||||||
|
|
||||||
/>
|
|
||||||
</CCol>
|
|
||||||
{/* <CCol sm={6} lg={3}>
|
|
||||||
<CWidgetStatsA
|
|
||||||
className="mb-4"
|
|
||||||
color="info"
|
|
||||||
value={
|
|
||||||
<>
|
|
||||||
{category.length}
|
|
||||||
</>
|
|
||||||
}
|
|
||||||
title="Total Categories"
|
|
||||||
|
|
||||||
/>
|
/>
|
||||||
</CCol>
|
</CCol>
|
||||||
<CCol sm={6} lg={3}>
|
<CCol sm={6} lg={3}>
|
||||||
|
<CWidgetStatsA
|
||||||
|
className="mb-4"
|
||||||
|
color="primary"
|
||||||
|
value={<>{Requests.length}</>}
|
||||||
|
title="Contact Requests"
|
||||||
|
/>
|
||||||
|
</CCol>
|
||||||
|
{/* <CCol sm={6} lg={3}>
|
||||||
<CWidgetStatsA
|
<CWidgetStatsA
|
||||||
className="mb-4"
|
className="mb-4"
|
||||||
color="warning"
|
color="warning"
|
||||||
@ -102,7 +202,102 @@ const WidgetsDropdown = ({ users }) => {
|
|||||||
/> */}
|
/> */}
|
||||||
{/* </CCol> */}
|
{/* </CCol> */}
|
||||||
</CRow>
|
</CRow>
|
||||||
)
|
<h4>Products and Categories</h4>
|
||||||
}
|
<CRow>
|
||||||
|
<CCol sm={6} lg={3}>
|
||||||
|
<CWidgetStatsA
|
||||||
|
className="mb-4"
|
||||||
|
color="primary"
|
||||||
|
value={<>{category.length}</>}
|
||||||
|
title="Total Categories"
|
||||||
|
/>
|
||||||
|
</CCol>
|
||||||
|
<CCol sm={6} lg={3}>
|
||||||
|
<CWidgetStatsA
|
||||||
|
className="mb-4"
|
||||||
|
color="primary"
|
||||||
|
value={<>{product.length}</>}
|
||||||
|
title="Total products"
|
||||||
|
/>
|
||||||
|
</CCol>
|
||||||
|
</CRow>
|
||||||
|
<h4>Orders</h4>
|
||||||
|
<CRow>
|
||||||
|
<CCol sm={6} lg={3}>
|
||||||
|
<CWidgetStatsA
|
||||||
|
className="mb-4"
|
||||||
|
color="primary"
|
||||||
|
value={<>{orders.length}</>}
|
||||||
|
title="Total orders"
|
||||||
|
/>
|
||||||
|
</CCol>
|
||||||
|
<CCol sm={6} lg={3}>
|
||||||
|
<CWidgetStatsA
|
||||||
|
className="mb-4"
|
||||||
|
color="primary"
|
||||||
|
value={<>{todayorders.length}</>}
|
||||||
|
title={`Orders for ${formattedDate}`}
|
||||||
|
/>
|
||||||
|
</CCol>
|
||||||
|
<CCol sm={6} lg={3}>
|
||||||
|
<CWidgetStatsA
|
||||||
|
className="mb-4"
|
||||||
|
color="primary"
|
||||||
|
value={<>{monthorders.length}</>}
|
||||||
|
title={`Orders for ${formattedmonth}`}
|
||||||
|
/>
|
||||||
|
</CCol>
|
||||||
|
<CCol sm={6} lg={3}>
|
||||||
|
<CWidgetStatsA
|
||||||
|
className="mb-4"
|
||||||
|
color="primary"
|
||||||
|
value={<>{yearorders.length}</>}
|
||||||
|
title={`Orders for ${year}`}
|
||||||
|
/>
|
||||||
|
</CCol>
|
||||||
|
<CCol sm={6} lg={3}>
|
||||||
|
<CWidgetStatsA
|
||||||
|
className="mb-4"
|
||||||
|
color="primary"
|
||||||
|
value={<>{lastyearorders.length}</>}
|
||||||
|
title={`Orders for ${year - 1}`}
|
||||||
|
/>
|
||||||
|
</CCol>
|
||||||
|
<CCol sm={6} lg={3}>
|
||||||
|
<CWidgetStatsA
|
||||||
|
className="mb-4"
|
||||||
|
color="dark"
|
||||||
|
value={<>{processingorders.length}</>}
|
||||||
|
title="Orders - Processing"
|
||||||
|
/>
|
||||||
|
</CCol>
|
||||||
|
<CCol sm={6} lg={3}>
|
||||||
|
<CWidgetStatsA
|
||||||
|
className="mb-4"
|
||||||
|
color="warning"
|
||||||
|
value={<>{dispatchedorders.length}</>}
|
||||||
|
title="Orders - Dispatched"
|
||||||
|
/>
|
||||||
|
</CCol>
|
||||||
|
<CCol sm={6} lg={3}>
|
||||||
|
<CWidgetStatsA
|
||||||
|
className="mb-4"
|
||||||
|
color="success"
|
||||||
|
value={<>{deliveredorders.length}</>}
|
||||||
|
title="Orders - Delivered"
|
||||||
|
/>
|
||||||
|
</CCol>
|
||||||
|
<CCol sm={6} lg={3}>
|
||||||
|
<CWidgetStatsA
|
||||||
|
className="mb-4"
|
||||||
|
color="danger"
|
||||||
|
value={<>{cancelledorders.length}</>}
|
||||||
|
title="Orders - Cancelled"
|
||||||
|
/>
|
||||||
|
</CCol>
|
||||||
|
</CRow>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export default WidgetsDropdown
|
export default WidgetsDropdown;
|
||||||
|
Loading…
Reference in New Issue
Block a user