added employee section
This commit is contained in:
parent
a5aa3ce47b
commit
0581cf77fe
@ -50,6 +50,7 @@
|
|||||||
"draft-js": "^0.11.7",
|
"draft-js": "^0.11.7",
|
||||||
"draft-js-export-html": "^1.4.1",
|
"draft-js-export-html": "^1.4.1",
|
||||||
"draft-js-import-html": "^1.4.1",
|
"draft-js-import-html": "^1.4.1",
|
||||||
|
"file-saver": "^2.0.5",
|
||||||
"md5": "^2.3.0",
|
"md5": "^2.3.0",
|
||||||
"moment": "^2.30.1",
|
"moment": "^2.30.1",
|
||||||
"prop-types": "^15.7.2",
|
"prop-types": "^15.7.2",
|
||||||
@ -76,7 +77,8 @@
|
|||||||
"styled-components": "^6.0.8",
|
"styled-components": "^6.0.8",
|
||||||
"sweetalert": "^2.1.2",
|
"sweetalert": "^2.1.2",
|
||||||
"sweetalert2": "^11.4.0",
|
"sweetalert2": "^11.4.0",
|
||||||
"uuid": "^9.0.1"
|
"uuid": "^9.0.1",
|
||||||
|
"xlsx": "^0.18.5"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"auto-changelog": "~2.3.0",
|
"auto-changelog": "~2.3.0",
|
||||||
|
16
src/_nav.js
16
src/_nav.js
@ -323,17 +323,17 @@ const _nav = [
|
|||||||
// Employee
|
// Employee
|
||||||
{
|
{
|
||||||
component: CNavItem,
|
component: CNavItem,
|
||||||
name: "Employee",
|
name: " Employees & Access",
|
||||||
icon: <CIcon icon={cilImage} customClassName="nav-icon" />,
|
icon: <CIcon icon={cilImage} customClassName="nav-icon" />,
|
||||||
to: "/employee",
|
to: "/employee",
|
||||||
},
|
},
|
||||||
//Point of Sale start
|
//Point of Sale start
|
||||||
{
|
{
|
||||||
component: CNavItem,
|
component: CNavItem,
|
||||||
name: "Point of Sale",
|
name: "Point of Sale",
|
||||||
icon: <CIcon icon={cilNotes} customClassName="nav-icon" />,
|
icon: <CIcon icon={cilNotes} customClassName="nav-icon" />,
|
||||||
to: "/pos",
|
to: "/pos",
|
||||||
},
|
},
|
||||||
// {
|
// {
|
||||||
// component: CNavGroup,
|
// component: CNavGroup,
|
||||||
// name: "Blog",
|
// name: "Blog",
|
||||||
|
@ -1,16 +1,17 @@
|
|||||||
import React, { Suspense } from 'react'
|
import React, { Suspense, useState } from "react";
|
||||||
import { Navigate, Route, Routes } from 'react-router-dom'
|
import { Navigate, Route, Routes } from "react-router-dom";
|
||||||
import { CContainer, CSpinner } from '@coreui/react'
|
import { CContainer, CSpinner } from "@coreui/react";
|
||||||
|
|
||||||
// routes config
|
// routes config
|
||||||
import routes from '../routes'
|
import routes from "../routes";
|
||||||
|
|
||||||
const AppContent = () => {
|
const AppContent = () => {
|
||||||
|
const [appRoutes, setAppRoutes] = useState(routes);
|
||||||
return (
|
return (
|
||||||
<CContainer lg>
|
<CContainer lg>
|
||||||
<Suspense fallback={<CSpinner color="primary" />}>
|
<Suspense fallback={<CSpinner color="primary" />}>
|
||||||
<Routes>
|
<Routes>
|
||||||
{routes.map((route, idx) => {
|
{appRoutes.map((route, idx) => {
|
||||||
return (
|
return (
|
||||||
route.element && (
|
route.element && (
|
||||||
<Route
|
<Route
|
||||||
@ -21,15 +22,13 @@ const AppContent = () => {
|
|||||||
element={<route.element />}
|
element={<route.element />}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
)
|
);
|
||||||
})}
|
})}
|
||||||
<Route path="/" element={<Navigate to="dashboard" replace />} />
|
<Route path="/" element={<Navigate to="dashboard" replace />} />
|
||||||
</Routes>
|
</Routes>
|
||||||
</Suspense>
|
</Suspense>
|
||||||
</CContainer>
|
</CContainer>
|
||||||
)
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export default React.memo(AppContent);
|
||||||
|
|
||||||
export default React.memo(AppContent)
|
|
||||||
|
@ -27,12 +27,61 @@ const AppSidebar = () => {
|
|||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const unfoldable = useSelector((state) => state.sidebarUnfoldable);
|
const unfoldable = useSelector((state) => state.sidebarUnfoldable);
|
||||||
const sidebarShow = useSelector((state) => state.sidebarShow);
|
const sidebarShow = useSelector((state) => state.sidebarShow);
|
||||||
|
const [navigationItem, setNavigationItem] = useState(navigation);
|
||||||
|
|
||||||
|
const [userdata, setUserData] = useState(null);
|
||||||
|
const token = isAutheticated();
|
||||||
|
console.log("userDatt", userdata);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const getUser = async () => {
|
||||||
|
let existanceData = localStorage.getItem("authToken");
|
||||||
|
if (!existanceData) {
|
||||||
|
// console.log(existanceData.userData)
|
||||||
|
setUserData(false);
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
// console.log('requesting user data from server')
|
||||||
|
let response = await axios.get(`/api/v1/user/details`, {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
// console.log(response.data)
|
||||||
|
const data = response.data;
|
||||||
|
if (
|
||||||
|
(data.success && data.user.role === "admin") ||
|
||||||
|
data.user.role === "Employee"
|
||||||
|
) {
|
||||||
|
setUserData(data.user);
|
||||||
|
} else {
|
||||||
|
setUserData(false);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
setUserData(false);
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
getUser();
|
||||||
|
}, []);
|
||||||
|
useEffect(() => {
|
||||||
|
if (userdata && userdata.accessTo) {
|
||||||
|
const filteredNavigation = navigation.filter((item) => {
|
||||||
|
if (userdata.accessTo[item.name]) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
setNavigationItem(filteredNavigation);
|
||||||
|
} else {
|
||||||
|
setNavigationItem(navigation);
|
||||||
|
}
|
||||||
|
}, [userdata]);
|
||||||
|
|
||||||
///----------------------//
|
///----------------------//
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
const token = isAutheticated();
|
|
||||||
|
|
||||||
// urlcreated images
|
// urlcreated images
|
||||||
const [AppName, setAppName] = useState("");
|
const [AppName, setAppName] = useState("");
|
||||||
const [HeaderlogoUrl, setHeaderlogoUrl] = useState("");
|
const [HeaderlogoUrl, setHeaderlogoUrl] = useState("");
|
||||||
@ -87,7 +136,7 @@ const AppSidebar = () => {
|
|||||||
</CSidebarBrand>
|
</CSidebarBrand>
|
||||||
<CSidebarNav>
|
<CSidebarNav>
|
||||||
<SimpleBar>
|
<SimpleBar>
|
||||||
<AppSidebarNav items={navigation} />
|
<AppSidebarNav items={navigationItem} />
|
||||||
</SimpleBar>
|
</SimpleBar>
|
||||||
</CSidebarNav>
|
</CSidebarNav>
|
||||||
<CSidebarToggler
|
<CSidebarToggler
|
||||||
|
@ -14,8 +14,8 @@ import { cibGmail } from "@coreui/icons";
|
|||||||
import { createRoot } from "react-dom/client";
|
import { createRoot } from "react-dom/client";
|
||||||
|
|
||||||
const setupAxios = () => {
|
const setupAxios = () => {
|
||||||
// axios.defaults.baseURL = "http://localhost:5000";
|
axios.defaults.baseURL = "http://localhost:5000";
|
||||||
axios.defaults.baseURL = "https://api.smellika.com";
|
// axios.defaults.baseURL = "https://api.smellika.com";
|
||||||
|
|
||||||
axios.defaults.headers = {
|
axios.defaults.headers = {
|
||||||
"Cache-Control": "no-cache,no-store",
|
"Cache-Control": "no-cache,no-store",
|
||||||
|
@ -146,6 +146,7 @@ import RegistrationEmail from "./views/CustomerSupport/EmailCMS/RegistrationEmai
|
|||||||
import Employee from "./views/EmployeeAccess/Employee";
|
import Employee from "./views/EmployeeAccess/Employee";
|
||||||
import AddEmployee from "./views/EmployeeAccess/addEmployee";
|
import AddEmployee from "./views/EmployeeAccess/addEmployee";
|
||||||
import EditEmployee from "./views/EmployeeAccess/editEmployee";
|
import EditEmployee from "./views/EmployeeAccess/editEmployee";
|
||||||
|
import ExportToExcel from "./views/exportExcel";
|
||||||
const routes = [
|
const routes = [
|
||||||
{ path: "/", exact: true, name: "Home" },
|
{ path: "/", exact: true, name: "Home" },
|
||||||
{
|
{
|
||||||
@ -187,17 +188,17 @@ const routes = [
|
|||||||
|
|
||||||
{
|
{
|
||||||
path: "/customers-details",
|
path: "/customers-details",
|
||||||
name: "User Table",
|
name: "Customers",
|
||||||
element: CustomerTable,
|
element: CustomerTable,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "/customers-details/:_id",
|
path: "/customers-details/:_id",
|
||||||
name: "User Table",
|
name: "Customers",
|
||||||
element: SingleUserAllDetails,
|
element: SingleUserAllDetails,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "/add-customer",
|
path: "/add-customer",
|
||||||
name: "User Table",
|
name: "Customers",
|
||||||
element: AddCustomer,
|
element: AddCustomer,
|
||||||
},
|
},
|
||||||
// {
|
// {
|
||||||
@ -212,7 +213,7 @@ const routes = [
|
|||||||
// },
|
// },
|
||||||
{
|
{
|
||||||
path: "/users-address/view",
|
path: "/users-address/view",
|
||||||
name: "view address",
|
name: "Customers",
|
||||||
element: viewDetails,
|
element: viewDetails,
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -275,12 +276,12 @@ const routes = [
|
|||||||
|
|
||||||
{
|
{
|
||||||
path: "/contact/request",
|
path: "/contact/request",
|
||||||
name: "Contact Requests",
|
name: "Customer Service",
|
||||||
element: ContactRequests,
|
element: ContactRequests,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "/contact/request/new",
|
path: "/contact/request/new",
|
||||||
name: "AddContact Request",
|
name: "Customer Service",
|
||||||
element: AddContactRequest,
|
element: AddContactRequest,
|
||||||
},
|
},
|
||||||
//Support Requests
|
//Support Requests
|
||||||
@ -297,54 +298,54 @@ const routes = [
|
|||||||
|
|
||||||
{
|
{
|
||||||
path: "/support/request",
|
path: "/support/request",
|
||||||
name: "CustomerSupport Requests",
|
name: "Customer Service",
|
||||||
element: SupportRequest,
|
element: SupportRequest,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "/support/request/closed",
|
path: "/support/request/closed",
|
||||||
name: "Closed CustomerSupport Requests",
|
name: "Customer Service",
|
||||||
element: SupportRequestClosed,
|
element: SupportRequestClosed,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "/support/request/closed/:ticketID",
|
path: "/support/request/closed/:ticketID",
|
||||||
name: "Closed CustomerSupport Request view",
|
name: "Customer Service",
|
||||||
element: CloseRequestView,
|
element: CloseRequestView,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "/support/request/reply/:ticketID",
|
path: "/support/request/reply/:ticketID",
|
||||||
name: "CustomerSupport Reply",
|
name: "Customer Service",
|
||||||
element: SupportReply,
|
element: SupportReply,
|
||||||
},
|
},
|
||||||
// Content ---- >
|
// Content ---- >
|
||||||
|
|
||||||
{
|
{
|
||||||
path: "/content",
|
path: "/content",
|
||||||
name: "Content",
|
name: "Website Relatedt",
|
||||||
element: Content,
|
element: Content,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "/content/terms-and-conditions",
|
path: "/content/terms-and-conditions",
|
||||||
name: "Content",
|
name: "Website Related",
|
||||||
element: EditTermsConditions,
|
element: EditTermsConditions,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "/content/privacy-policy",
|
path: "/content/privacy-policy",
|
||||||
name: "Content",
|
name: "Website Related",
|
||||||
element: EditPrivacyPolicy,
|
element: EditPrivacyPolicy,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "/content/shipping-policy",
|
path: "/content/shipping-policy",
|
||||||
name: "Content",
|
name: "Website Related",
|
||||||
element: EditShippingPolicy,
|
element: EditShippingPolicy,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "/content/refund-policy",
|
path: "/content/refund-policy",
|
||||||
name: "Content",
|
name: "Website Related",
|
||||||
element: EditRefundpolicy,
|
element: EditRefundpolicy,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "/content/about-us",
|
path: "/content/about-us",
|
||||||
name: "Content",
|
name: "Website Related",
|
||||||
element: EditAboutUs,
|
element: EditAboutUs,
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -459,9 +460,21 @@ const routes = [
|
|||||||
element: ReturnedOrders,
|
element: ReturnedOrders,
|
||||||
},
|
},
|
||||||
//Point of sale orders
|
//Point of sale orders
|
||||||
{ path: "/inStoreCashOrders/new", name: "In Store Cash Orders", element:InStoreCashOrders },
|
{
|
||||||
{ path: "/InStoreQRCodeOrders/new", name: "In Store QR Code Orders", element:InStoreQRCodeOrders },
|
path: "/inStoreCashOrders/new",
|
||||||
{ path: "/inStoreOrders/:status/:id", name: "View In Store Cash Orders", element: POSViewOrders },
|
name: "In Store Cash Orders",
|
||||||
|
element: InStoreCashOrders,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/InStoreQRCodeOrders/new",
|
||||||
|
name: "In Store QR Code Orders",
|
||||||
|
element: InStoreQRCodeOrders,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/inStoreOrders/:status/:id",
|
||||||
|
name: "View In Store Cash Orders",
|
||||||
|
element: POSViewOrders,
|
||||||
|
},
|
||||||
// { path: "/order/:status/:id", name: "View Order", element: ViewOdr },
|
// { path: "/order/:status/:id", name: "View Order", element: ViewOdr },
|
||||||
|
|
||||||
//dashboard
|
//dashboard
|
||||||
@ -639,6 +652,13 @@ const routes = [
|
|||||||
name: "Point of Sale",
|
name: "Point of Sale",
|
||||||
element: Pos,
|
element: Pos,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Export to excel
|
||||||
|
{
|
||||||
|
path: "/exp",
|
||||||
|
name: "Point of Sale",
|
||||||
|
element: ExportToExcel,
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
export default routes;
|
export default routes;
|
||||||
|
@ -25,26 +25,35 @@ const Employee = () => {
|
|||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [loading1, setLoading1] = useState(true);
|
const [loading1, setLoading1] = useState(true);
|
||||||
const [success, setSuccess] = useState(true);
|
const [success, setSuccess] = useState(true);
|
||||||
const [users, setUsers] = useState([]);
|
const [employee, setemployee] = 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(users);
|
const [showData, setShowData] = useState(employee);
|
||||||
|
|
||||||
const handleShowEntries = (e) => {
|
const handleShowEntries = (e) => {
|
||||||
setCurrentPage(1);
|
setCurrentPage(1);
|
||||||
setItemPerPage(e.target.value);
|
setItemPerPage(e.target.value);
|
||||||
};
|
};
|
||||||
|
useEffect(() => {
|
||||||
|
const loadData = () => {
|
||||||
|
const indexOfLastPost = currentPage * itemPerPage;
|
||||||
|
const indexOfFirstPost = indexOfLastPost - itemPerPage;
|
||||||
|
setShowData(employee.slice(indexOfFirstPost, indexOfLastPost));
|
||||||
|
};
|
||||||
|
loadData();
|
||||||
|
}, [currentPage, itemPerPage, employee]);
|
||||||
|
console.log(employee);
|
||||||
|
|
||||||
// const getUsers = async () => {
|
// const getemployee = async () => {
|
||||||
// axios
|
// axios
|
||||||
// .get(`/api/v1/admin/users`, {
|
// .get(`/api/v1/admin/employee`, {
|
||||||
// headers: {
|
// headers: {
|
||||||
// Authorization: `Bearer ${token}`,
|
// Authorization: `Bearer ${token}`,
|
||||||
// },
|
// },
|
||||||
// })
|
// })
|
||||||
// .then((res) => {
|
// .then((res) => {
|
||||||
// setUsers(res.data.users);
|
// setemployee(res.data.employee);
|
||||||
// setLoading(false);
|
// setLoading(false);
|
||||||
// })
|
// })
|
||||||
// .catch((error) => {
|
// .catch((error) => {
|
||||||
@ -60,19 +69,19 @@ const Employee = () => {
|
|||||||
// };
|
// };
|
||||||
|
|
||||||
// useEffect(() => {
|
// useEffect(() => {
|
||||||
// getUsers();
|
// getemployee();
|
||||||
// }, [success]);
|
// }, [success]);
|
||||||
// console.log(users);
|
// console.log(employee);
|
||||||
|
|
||||||
// useEffect(() => {
|
// useEffect(() => {
|
||||||
// const loadData = () => {
|
// const loadData = () => {
|
||||||
// const indexOfLastPost = currentPage * itemPerPage;
|
// const indexOfLastPost = currentPage * itemPerPage;
|
||||||
// const indexOfFirstPost = indexOfLastPost - itemPerPage;
|
// const indexOfFirstPost = indexOfLastPost - itemPerPage;
|
||||||
// setShowData(users.slice(indexOfFirstPost, indexOfLastPost));
|
// setShowData(employee.slice(indexOfFirstPost, indexOfLastPost));
|
||||||
// };
|
// };
|
||||||
// loadData();
|
// loadData();
|
||||||
// }, [currentPage, itemPerPage, users]);
|
// }, [currentPage, itemPerPage, employee]);
|
||||||
// console.log(users);
|
// console.log(employee);
|
||||||
|
|
||||||
// const handleDelete = (id) => {
|
// const handleDelete = (id) => {
|
||||||
// swal({
|
// swal({
|
||||||
@ -113,6 +122,70 @@ const Employee = () => {
|
|||||||
// });
|
// });
|
||||||
// };
|
// };
|
||||||
|
|
||||||
|
// get All employee
|
||||||
|
const getemployee = async () => {
|
||||||
|
axios
|
||||||
|
.get(`/api/v1/admin/employee`, {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.then((res) => {
|
||||||
|
setemployee(res.data.employee);
|
||||||
|
setLoading(false);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
swal({
|
||||||
|
title: error,
|
||||||
|
text: "please login to access the resource or refresh the page ",
|
||||||
|
icon: "error",
|
||||||
|
button: "Retry",
|
||||||
|
dangerMode: true,
|
||||||
|
});
|
||||||
|
setLoading(false);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
useEffect(() => {
|
||||||
|
getemployee();
|
||||||
|
}, [success]);
|
||||||
|
console.log(employee);
|
||||||
|
console.log("showdata", showData);
|
||||||
|
// const trueEntries = Object.entries(showData.).filter(
|
||||||
|
// ([key, value]) => value === true
|
||||||
|
// );
|
||||||
|
const renderAccessTo = (accessTo) => {
|
||||||
|
return Object.entries(accessTo)
|
||||||
|
.filter(([key, value]) => value === true)
|
||||||
|
.map(([key, value]) => key)
|
||||||
|
.join(", ");
|
||||||
|
};
|
||||||
|
const handleDelete = async (id) => {
|
||||||
|
try {
|
||||||
|
// Send a DELETE request to your API to delete the employee by ID
|
||||||
|
const res = await axios.delete(`/api/v1/admin/delete-employee/${id}`, {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
// If deletion is successful, update the employee list
|
||||||
|
swal({
|
||||||
|
title: "Congratulations!!",
|
||||||
|
text: res?.data?.message,
|
||||||
|
icon: "success",
|
||||||
|
buttons: "OK",
|
||||||
|
});
|
||||||
|
setemployee(employee.filter((employee) => employee._id !== id));
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error deleting employee:", error);
|
||||||
|
swal({
|
||||||
|
title: "",
|
||||||
|
text: "Something went wrong!",
|
||||||
|
icon: "error",
|
||||||
|
button: "Retry",
|
||||||
|
dangerMode: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
return (
|
return (
|
||||||
<div className="main-content">
|
<div className="main-content">
|
||||||
<div className="page-content">
|
<div className="page-content">
|
||||||
@ -207,168 +280,67 @@ const Employee = () => {
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
)}
|
)}
|
||||||
{!loading ? (
|
{loading ? (
|
||||||
<tr>
|
<tr>
|
||||||
<td className="text-center" colSpan="6">
|
<td className="text-center" colSpan="6">
|
||||||
Loading...
|
Loading...
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
) : (
|
) : (
|
||||||
// showData.map((user, i) => {
|
showData.map((employee, i) => {
|
||||||
// return (
|
return (
|
||||||
// <tr key={i}>
|
<tr key={i}>
|
||||||
// <td className="text-start">{user.name}</td>
|
<td className="text-start">{employee.name}</td>
|
||||||
// <td>{user._id}</td>
|
<td>{employee.email}</td>
|
||||||
|
|
||||||
// <td className="text-start">
|
<td
|
||||||
// {new Date(user.createdAt).toLocaleString(
|
style={{ maxWidth: "200px" }}
|
||||||
// "en-IN",
|
className="text-start"
|
||||||
// {
|
>
|
||||||
// weekday: "short",
|
{renderAccessTo(employee.accessTo)}
|
||||||
// month: "short",
|
</td>
|
||||||
// day: "numeric",
|
|
||||||
// year: "numeric",
|
|
||||||
// hour: "numeric",
|
|
||||||
// minute: "numeric",
|
|
||||||
// hour12: true,
|
|
||||||
// }
|
|
||||||
// )}
|
|
||||||
// </td>
|
|
||||||
// {loading1 && (
|
|
||||||
// <>
|
|
||||||
// <td className="text-start">loading...</td>
|
|
||||||
// <td className="text-start">loading...</td>
|
|
||||||
// </>
|
|
||||||
// )}
|
|
||||||
|
|
||||||
// <OrderDetails
|
<th>
|
||||||
// _id={user?._id}
|
<button
|
||||||
// setLoading1={setLoading1}
|
onClick={() =>
|
||||||
// />
|
navigate(`/edit-employee/${employee._id}`)
|
||||||
|
}
|
||||||
// <td className="text-start">
|
style={{
|
||||||
// {/* <Link
|
color: "white",
|
||||||
// to={`/users-address/view/${userAddress._id}`}
|
marginRight: "1rem",
|
||||||
// >
|
}}
|
||||||
// <button
|
type="button"
|
||||||
// style={{
|
className="
|
||||||
// color: "white",
|
|
||||||
// marginRight: "1rem",
|
|
||||||
// }}
|
|
||||||
// type="button"
|
|
||||||
// className="
|
|
||||||
// btn btn-primary btn-sm
|
|
||||||
// waves-effect waves-light
|
|
||||||
// btn-table
|
|
||||||
// mx-1
|
|
||||||
// mt-1
|
|
||||||
// "
|
|
||||||
// >
|
|
||||||
// View
|
|
||||||
// </button>
|
|
||||||
// </Link>
|
|
||||||
// <Link
|
|
||||||
// to={`/users-address/edit/${userAddress._id}`}
|
|
||||||
// >
|
|
||||||
// <button
|
|
||||||
// style={{
|
|
||||||
// color: "white",
|
|
||||||
// marginRight: "1rem",
|
|
||||||
// }}
|
|
||||||
// type="button"
|
|
||||||
// className="
|
|
||||||
// btn btn-info btn-sm
|
|
||||||
// waves-effect waves-light
|
|
||||||
// btn-table
|
|
||||||
// mt-1
|
|
||||||
// mx-1
|
|
||||||
// "
|
|
||||||
// >
|
|
||||||
// Edit
|
|
||||||
// </button>
|
|
||||||
// </Link>
|
|
||||||
// <Link
|
|
||||||
// to={"#"}
|
|
||||||
// style={{
|
|
||||||
// marginRight: "1rem",
|
|
||||||
// }}
|
|
||||||
// >
|
|
||||||
// <button
|
|
||||||
// style={{ color: "white" }}
|
|
||||||
// type="button"
|
|
||||||
// className="
|
|
||||||
// btn btn-danger btn-sm
|
|
||||||
// waves-effect waves-light
|
|
||||||
// btn-table
|
|
||||||
// mt-1
|
|
||||||
// mx-1
|
|
||||||
|
|
||||||
// "
|
|
||||||
// onClick={() => {
|
|
||||||
// handleDelete(userAddress._id);
|
|
||||||
// }}
|
|
||||||
// >
|
|
||||||
// Delete
|
|
||||||
// </button>
|
|
||||||
// </Link> */}
|
|
||||||
// <Link to={`/customers-details/${user?._id}`}>
|
|
||||||
// <button
|
|
||||||
// type="button"
|
|
||||||
// className="mt-1 btn btn-info btn-sm waves-effect waves-light btn-table ml-2"
|
|
||||||
// >
|
|
||||||
// View
|
|
||||||
// </button>
|
|
||||||
// </Link>
|
|
||||||
// </td>
|
|
||||||
// </tr>
|
|
||||||
// );
|
|
||||||
// })
|
|
||||||
<tr>
|
|
||||||
<th>Roshan Garg</th>
|
|
||||||
<th>roshan@gmail.com</th>
|
|
||||||
{/* <th>Profile Image</th> */}
|
|
||||||
<th>dashboard</th>
|
|
||||||
|
|
||||||
{/* <th>Last Purchase</th>
|
|
||||||
<th>Orders</th> */}
|
|
||||||
<th>
|
|
||||||
<button
|
|
||||||
onClick={() =>
|
|
||||||
navigate("/edit-employee/44234234")
|
|
||||||
}
|
|
||||||
style={{
|
|
||||||
color: "white",
|
|
||||||
marginRight: "1rem",
|
|
||||||
}}
|
|
||||||
type="button"
|
|
||||||
className="
|
|
||||||
btn btn-primary btn-sm
|
btn btn-primary btn-sm
|
||||||
waves-effect waves-light
|
waves-effect waves-light
|
||||||
btn-table
|
btn-table
|
||||||
mx-1
|
mx-1
|
||||||
mt-1
|
mt-1
|
||||||
"
|
"
|
||||||
>
|
>
|
||||||
Edit
|
Edit
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
style={{
|
style={{
|
||||||
color: "white",
|
color: "white",
|
||||||
marginRight: "1rem",
|
marginRight: "1rem",
|
||||||
}}
|
}}
|
||||||
type="button"
|
onClick={() => handleDelete(employee._id)}
|
||||||
className="
|
type="button"
|
||||||
|
className="
|
||||||
btn btn-primary btn-sm
|
btn btn-primary btn-sm
|
||||||
waves-effect waves-light
|
waves-effect waves-light
|
||||||
btn-table
|
btn-table
|
||||||
mx-1
|
mx-1
|
||||||
mt-1
|
mt-1
|
||||||
"
|
"
|
||||||
>
|
>
|
||||||
Delete
|
Delete
|
||||||
</button>
|
</button>
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
|
);
|
||||||
|
})
|
||||||
)}
|
)}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
@ -383,8 +355,8 @@ const Employee = () => {
|
|||||||
aria-live="polite"
|
aria-live="polite"
|
||||||
>
|
>
|
||||||
Showing {currentPage * itemPerPage - itemPerPage + 1} to{" "}
|
Showing {currentPage * itemPerPage - itemPerPage + 1} to{" "}
|
||||||
{Math.min(currentPage * itemPerPage, users.length)} of{" "}
|
{Math.min(currentPage * itemPerPage, employee.length)}{" "}
|
||||||
{users.length} entries
|
of {employee.length} entries
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -432,7 +404,7 @@ const Employee = () => {
|
|||||||
|
|
||||||
{!(
|
{!(
|
||||||
(currentPage + 1) * itemPerPage - itemPerPage >
|
(currentPage + 1) * itemPerPage - itemPerPage >
|
||||||
users.length - 1
|
employee.length - 1
|
||||||
) && (
|
) && (
|
||||||
<li className="paginate_button page-item ">
|
<li className="paginate_button page-item ">
|
||||||
<span
|
<span
|
||||||
@ -451,7 +423,7 @@ const Employee = () => {
|
|||||||
className={
|
className={
|
||||||
!(
|
!(
|
||||||
(currentPage + 1) * itemPerPage - itemPerPage >
|
(currentPage + 1) * itemPerPage - itemPerPage >
|
||||||
users.length - 1
|
employee.length - 1
|
||||||
)
|
)
|
||||||
? "paginate_button page-item next"
|
? "paginate_button page-item next"
|
||||||
: "paginate_button page-item next disabled"
|
: "paginate_button page-item next disabled"
|
||||||
|
@ -5,32 +5,109 @@ import FormControlLabel from "@mui/material/FormControlLabel";
|
|||||||
import Checkbox from "@mui/material/Checkbox";
|
import Checkbox from "@mui/material/Checkbox";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import _nav from "src/_nav";
|
import _nav from "src/_nav";
|
||||||
|
import toast from "react-hot-toast";
|
||||||
|
import axios from "axios";
|
||||||
|
|
||||||
const AddEmployee = () => {
|
const AddEmployee = () => {
|
||||||
const [employeeName, setEmployeeName] = useState("");
|
const [employeeName, setEmployeeName] = useState("");
|
||||||
|
const [phone, setPhone] = useState("");
|
||||||
const [email, setEmail] = useState("");
|
const [email, setEmail] = useState("");
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [checkedItems, setCheckedItems] = useState({});
|
|
||||||
const filteredNav = _nav.filter((item) => item.name !== "Employee");
|
const filteredNav = _nav.filter((item) => item.name !== "Employee");
|
||||||
|
const [checkedItems, setCheckedItems] = useState(
|
||||||
|
filteredNav.reduce((acc, item) => {
|
||||||
|
acc[item.name] = false;
|
||||||
|
return acc;
|
||||||
|
}, {})
|
||||||
|
);
|
||||||
|
|
||||||
|
// const filteredEntries = Object.fromEntries(
|
||||||
|
// Object.entries(checkedItems).filter(([key, value]) => value === true)
|
||||||
|
// );
|
||||||
|
// console.log(filteredEntries);
|
||||||
const handleCheckboxChange = (name) => (event) => {
|
const handleCheckboxChange = (name) => (event) => {
|
||||||
setCheckedItems({
|
setCheckedItems({
|
||||||
...checkedItems,
|
...checkedItems,
|
||||||
[name]: event.target.checked,
|
[name]: event.target.checked,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log(checkedItems);
|
console.log(checkedItems);
|
||||||
|
const generatePassword = (name, email) => {
|
||||||
|
const combinedStr = (name + email).toLowerCase(); // Convert to lowercase for consistency
|
||||||
|
const specialChars = "@#*!$%^&"; // Define the set of special characters
|
||||||
|
const alphaChars = combinedStr.match(/[a-zA-Z]/g); // Filter out alphabetic characters
|
||||||
|
const digitChars = combinedStr.match(/\d/g); // Filter out digits
|
||||||
|
const filteredChars = combinedStr.match(/[^\W_]/g); // Filter out non-alphanumeric characters
|
||||||
|
let passwordChars = alphaChars.concat(filteredChars); // Combine alphabetic and filtered characters
|
||||||
|
|
||||||
|
// Ensure at least one uppercase letter
|
||||||
|
if (!passwordChars.some((char) => char === char.toUpperCase())) {
|
||||||
|
const uppercaseChar = String.fromCharCode(
|
||||||
|
65 + Math.floor(Math.random() * 26)
|
||||||
|
);
|
||||||
|
passwordChars.push(uppercaseChar);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure at least one digit
|
||||||
|
if (!digitChars || digitChars.length === 0) {
|
||||||
|
const digitChar = Math.floor(Math.random() * 10).toString();
|
||||||
|
passwordChars.push(digitChar);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Insert a random special character at a random position in the password characters array
|
||||||
|
const specialChar = specialChars.charAt(
|
||||||
|
Math.floor(Math.random() * specialChars.length)
|
||||||
|
);
|
||||||
|
const randomIndex = Math.floor(Math.random() * (passwordChars.length + 1));
|
||||||
|
passwordChars.splice(randomIndex, 0, specialChar);
|
||||||
|
|
||||||
|
passwordChars = passwordChars.sort(() => Math.random() - 0.5); // Shuffle the characters
|
||||||
|
// passwordString.charAt(0).toUpperCase() + passwordString.slice(1) + "@";
|
||||||
|
const normalpassword = passwordChars.join("").slice(0, 8); // Take the first 8 characters
|
||||||
|
const passwordWithspecialChar =
|
||||||
|
normalpassword.charAt(0).toUpperCase() + normalpassword.slice(1) + "1@2";
|
||||||
|
return passwordWithspecialChar;
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleFormSubmit = async (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
console.log("request made");
|
||||||
|
try {
|
||||||
|
if (!employeeName || !email || !phone) {
|
||||||
|
throw new Error("Fill all fields!");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate password based on name and email
|
||||||
|
const generatedPassword = generatePassword(employeeName, email);
|
||||||
|
console.log(generatedPassword); // Use generatedPassword instead of generatePassword
|
||||||
|
// Set generated password to user state
|
||||||
|
|
||||||
|
const response = await axios.post("/api/v1/user/register", {
|
||||||
|
// Send user details
|
||||||
|
name: employeeName,
|
||||||
|
email: email,
|
||||||
|
phone: phone,
|
||||||
|
role: "Employee",
|
||||||
|
accessTo: checkedItems,
|
||||||
|
password: generatedPassword, // Send generated password to the backend
|
||||||
|
});
|
||||||
|
console.log(response);
|
||||||
|
if (response.status === 201) {
|
||||||
|
toast.success("Employee Added Successful");
|
||||||
|
// setUserId(response.data.userId);
|
||||||
|
navigate("/employee");
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error?.response);
|
||||||
|
// toast.error(error?.response);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Box style={{ background: "#FFFFFF", color: "black", padding: "1rem" }}>
|
<Box style={{ background: "#FFFFFF", color: "black", padding: "1rem" }}>
|
||||||
{/* <TextField
|
|
||||||
type="text"
|
|
||||||
value={title}
|
|
||||||
onChange={(e) => setTitle(e.target.value)}
|
|
||||||
variant="outlined"
|
|
||||||
size="small"
|
|
||||||
fullWidth
|
|
||||||
/> */}
|
|
||||||
<Typography
|
<Typography
|
||||||
style={{ margin: "0.5rem 0rem", fontWeight: "bold" }}
|
style={{ margin: "0.5rem 0rem", fontWeight: "bold" }}
|
||||||
variant="h6"
|
variant="h6"
|
||||||
@ -53,6 +130,20 @@ const AddEmployee = () => {
|
|||||||
onChange={(e) => setEmployeeName(e.target.value)}
|
onChange={(e) => setEmployeeName(e.target.value)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<div className="mb-3">
|
||||||
|
<label htmlFor="title" className="form-label">
|
||||||
|
Phone Number
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
className="form-control"
|
||||||
|
id="title"
|
||||||
|
placeholder="Eg: 8516913819"
|
||||||
|
value={phone}
|
||||||
|
onChange={(e) => setPhone(e.target.value)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="mb-3">
|
<div className="mb-3">
|
||||||
<label htmlFor="welcomeMsgforDes" className="form-label">
|
<label htmlFor="welcomeMsgforDes" className="form-label">
|
||||||
@ -62,9 +153,8 @@ const AddEmployee = () => {
|
|||||||
<input
|
<input
|
||||||
type="email"
|
type="email"
|
||||||
className="form-control"
|
className="form-control"
|
||||||
// style={{ width: "300px" }}
|
|
||||||
id="welcomeMsgforDes"
|
id="welcomeMsgforDes"
|
||||||
placeholder="Eg: rosham@gmailcom "
|
placeholder="Eg: roshan@gmailcom "
|
||||||
value={email}
|
value={email}
|
||||||
onChange={(e) => setEmail(e.target.value)}
|
onChange={(e) => setEmail(e.target.value)}
|
||||||
/>
|
/>
|
||||||
@ -90,7 +180,7 @@ const AddEmployee = () => {
|
|||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
color="primary"
|
color="primary"
|
||||||
// onClick={handleSaveClick}
|
onClick={handleFormSubmit}
|
||||||
style={{
|
style={{
|
||||||
fontWeight: "bold",
|
fontWeight: "bold",
|
||||||
marginBottom: "1rem",
|
marginBottom: "1rem",
|
||||||
@ -103,7 +193,6 @@ const AddEmployee = () => {
|
|||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
color="primary"
|
color="primary"
|
||||||
// onClick={handleCancelClick}
|
|
||||||
onClick={() => navigate("/employee")}
|
onClick={() => navigate("/employee")}
|
||||||
style={{
|
style={{
|
||||||
fontWeight: "bold",
|
fontWeight: "bold",
|
||||||
|
@ -1,76 +1,107 @@
|
|||||||
|
import React, { useState, useEffect } from "react";
|
||||||
|
import axios from "axios";
|
||||||
|
import { useNavigate, useParams } from "react-router-dom";
|
||||||
import { Box, Button, Typography } from "@mui/material";
|
import { Box, Button, Typography } from "@mui/material";
|
||||||
import React, { useState } from "react";
|
|
||||||
import FormGroup from "@mui/material/FormGroup";
|
|
||||||
import FormControlLabel from "@mui/material/FormControlLabel";
|
|
||||||
import Checkbox from "@mui/material/Checkbox";
|
import Checkbox from "@mui/material/Checkbox";
|
||||||
import { useNavigate } from "react-router-dom";
|
|
||||||
import _nav from "src/_nav";
|
import _nav from "src/_nav";
|
||||||
|
import { isAutheticated } from "src/auth";
|
||||||
|
|
||||||
const EditEmployee = () => {
|
const EditEmployee = () => {
|
||||||
const [employeeName, setEmployeeName] = useState("");
|
const { id } = useParams();
|
||||||
// const [email, setEmail] = useState("");
|
const token = isAutheticated();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
const [employeeName, setEmployeeName] = useState("");
|
||||||
|
const [phone, setPhone] = useState("");
|
||||||
const [checkedItems, setCheckedItems] = useState({});
|
const [checkedItems, setCheckedItems] = useState({});
|
||||||
const filteredNav = _nav.filter((item) => item.name !== "Employee");
|
const filteredNav = _nav.filter((item) => item.name !== "Employee");
|
||||||
|
|
||||||
const handleCheckboxChange = (name) => (event) => {
|
const handleCheckboxChange = (name) => (event) => {
|
||||||
setCheckedItems({
|
setCheckedItems({
|
||||||
...checkedItems,
|
...checkedItems,
|
||||||
[name]: event.target.checked,
|
[name]: event.target.checked,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
console.log(checkedItems);
|
|
||||||
|
useEffect(() => {
|
||||||
|
const getSingleEmployee = async () => {
|
||||||
|
try {
|
||||||
|
const response = await axios.get(`/api/v1/admin/user/${id}`, {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const { name, phone, accessTo } = response.data.user;
|
||||||
|
setEmployeeName(name);
|
||||||
|
setPhone(phone);
|
||||||
|
setCheckedItems(accessTo);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching employee:", error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
getSingleEmployee();
|
||||||
|
}, [id, token]);
|
||||||
|
|
||||||
|
const handleUpdateEmployee = async () => {
|
||||||
|
try {
|
||||||
|
await axios.put(
|
||||||
|
`/api/v1/admin/update-employee/${id}`,
|
||||||
|
{
|
||||||
|
name: employeeName,
|
||||||
|
phone: phone,
|
||||||
|
accessTo: checkedItems,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
navigate("/employee");
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error updating employee:", error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Box style={{ background: "#FFFFFF", color: "black", padding: "1rem" }}>
|
<Box style={{ background: "#FFFFFF", color: "black", padding: "1rem" }}>
|
||||||
{/* <TextField
|
|
||||||
type="text"
|
|
||||||
value={title}
|
|
||||||
onChange={(e) => setTitle(e.target.value)}
|
|
||||||
variant="outlined"
|
|
||||||
size="small"
|
|
||||||
fullWidth
|
|
||||||
/> */}
|
|
||||||
<Typography
|
<Typography
|
||||||
style={{ margin: "0.5rem 0rem", fontWeight: "bold" }}
|
style={{ margin: "0.5rem 0rem", fontWeight: "bold" }}
|
||||||
variant="h6"
|
variant="h6"
|
||||||
>
|
>
|
||||||
{" "}
|
Update Employee
|
||||||
Add Employee:{" "}
|
|
||||||
</Typography>
|
</Typography>
|
||||||
|
|
||||||
<div className="mb-3">
|
<div className="mb-3">
|
||||||
<label htmlFor="title" className="form-label">
|
<label htmlFor="title" className="form-label">
|
||||||
Employee Name*
|
Employee Name*
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
className="form-control"
|
className="form-control"
|
||||||
id="title"
|
placeholder="Enter employee name"
|
||||||
placeholder="Eg: Roshan Garg"
|
|
||||||
value={employeeName}
|
value={employeeName}
|
||||||
onChange={(e) => setEmployeeName(e.target.value)}
|
onChange={(e) => setEmployeeName(e.target.value)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* <div className="mb-3">
|
<div className="mb-3">
|
||||||
<label htmlFor="welcomeMsgforDes" className="form-label">
|
<label htmlFor="phone" className="form-label">
|
||||||
Email*
|
Phone Number
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<input
|
<input
|
||||||
type="email"
|
type="text"
|
||||||
className="form-control"
|
className="form-control"
|
||||||
// style={{ width: "300px" }}
|
placeholder="Enter phone number"
|
||||||
id="welcomeMsgforDes"
|
value={phone}
|
||||||
placeholder="Eg: rosham@gmailcom "
|
onChange={(e) => setPhone(e.target.value)}
|
||||||
value={email}
|
|
||||||
onChange={(e) => setEmail(e.target.value)}
|
|
||||||
/>
|
/>
|
||||||
</div> */}
|
</div>
|
||||||
|
|
||||||
<Box>
|
<Box>
|
||||||
<label htmlFor="welcomeMsgforDes" className="form-label">
|
<label htmlFor="accessTo" className="form-label">
|
||||||
Access to*
|
Access to*
|
||||||
</label>
|
</label>
|
||||||
<div>
|
<div>
|
||||||
@ -86,11 +117,12 @@ const EditEmployee = () => {
|
|||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
<div style={{ display: "flex" }}>
|
<div style={{ display: "flex" }}>
|
||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
color="primary"
|
color="primary"
|
||||||
// onClick={handleSaveClick}
|
onClick={handleUpdateEmployee}
|
||||||
style={{
|
style={{
|
||||||
fontWeight: "bold",
|
fontWeight: "bold",
|
||||||
marginBottom: "1rem",
|
marginBottom: "1rem",
|
||||||
@ -103,7 +135,6 @@ const EditEmployee = () => {
|
|||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
color="primary"
|
color="primary"
|
||||||
// onClick={handleCancelClick}
|
|
||||||
onClick={() => navigate("/employee")}
|
onClick={() => navigate("/employee")}
|
||||||
style={{
|
style={{
|
||||||
fontWeight: "bold",
|
fontWeight: "bold",
|
||||||
|
@ -33,7 +33,7 @@ const Dashboard = () => {
|
|||||||
//3rd
|
//3rd
|
||||||
const [product, setProduct] = useState([]);
|
const [product, setProduct] = useState([]);
|
||||||
const getAllProduct = async () => {
|
const getAllProduct = async () => {
|
||||||
let res = await axios.get(`/api/product/getAll/`, {
|
let res = await axios.get(`/api/product/getAll/admin`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
},
|
},
|
||||||
|
73
src/views/exportExcel.js
Normal file
73
src/views/exportExcel.js
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
import React, { useEffect, useState } from "react";
|
||||||
|
import * as XLSX from "xlsx";
|
||||||
|
import { saveAs } from "file-saver";
|
||||||
|
import { isAutheticated } from "src/auth";
|
||||||
|
import axios from "axios";
|
||||||
|
|
||||||
|
function ExportToExcel() {
|
||||||
|
const token = isAutheticated();
|
||||||
|
const [newOrdersData, setNewOrdersData] = useState([]);
|
||||||
|
|
||||||
|
const data = [
|
||||||
|
{ name: "John", email: "john@example.com", age: 28 },
|
||||||
|
{ name: "Jane", email: "jane@example.com", age: 32 },
|
||||||
|
// ... more data
|
||||||
|
];
|
||||||
|
useEffect(() => {
|
||||||
|
function getNewOrder() {
|
||||||
|
axios
|
||||||
|
.get(`/api/order/getAll/new`, {
|
||||||
|
headers: {
|
||||||
|
"Access-Control-Allow-Origin": "*",
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.then((res) => {
|
||||||
|
console.log(res);
|
||||||
|
const filteredOrders = res.data.order.filter(
|
||||||
|
(order) => order.orderType === "WebSite"
|
||||||
|
);
|
||||||
|
|
||||||
|
setNewOrdersData(filteredOrders);
|
||||||
|
// setLoading(false);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err);
|
||||||
|
// setLoading(false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
getNewOrder();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const exportToExcel = () => {
|
||||||
|
const flattenedData = newOrdersData.map((order) => ({
|
||||||
|
...order,
|
||||||
|
// Flatten shippingInfo object
|
||||||
|
shippingInfo: JSON.stringify(order.shippingInfo),
|
||||||
|
// Concatenate item names into a single string
|
||||||
|
items: order.items.map((item) => item.name).join(", "),
|
||||||
|
}));
|
||||||
|
|
||||||
|
const worksheet = XLSX.utils.json_to_sheet(flattenedData);
|
||||||
|
const workbook = XLSX.utils.book_new();
|
||||||
|
XLSX.utils.book_append_sheet(workbook, worksheet, "Sheet1");
|
||||||
|
|
||||||
|
const excelBuffer = XLSX.write(workbook, {
|
||||||
|
bookType: "xlsx",
|
||||||
|
type: "array",
|
||||||
|
});
|
||||||
|
const blob = new Blob([excelBuffer], {
|
||||||
|
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8",
|
||||||
|
});
|
||||||
|
|
||||||
|
saveAs(blob, "exportedData.xlsx");
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="App">
|
||||||
|
<button onClick={exportToExcel}>Export as Excel</button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ExportToExcel;
|
File diff suppressed because it is too large
Load Diff
@ -93,7 +93,7 @@ function EditOrder() {
|
|||||||
function getProductDetails() {
|
function getProductDetails() {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
axios
|
axios
|
||||||
.get(`/api/product/getAll/`, {
|
.get(`/api/product/getAll/admin`, {
|
||||||
headers: {
|
headers: {
|
||||||
"Access-Control-Allow-Origin": "*",
|
"Access-Control-Allow-Origin": "*",
|
||||||
Authorization: `Bearer ${token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
|
@ -100,8 +100,10 @@ const Login = () => {
|
|||||||
setLoading({ loading: true });
|
setLoading({ loading: true });
|
||||||
try {
|
try {
|
||||||
const res = await axios.post("/api/v1/user/login/", auth);
|
const res = await axios.post("/api/v1/user/login/", auth);
|
||||||
|
console.log(res);
|
||||||
if (res.data.success == true) {
|
if (res.data.success == true) {
|
||||||
localStorage.setItem("authToken", res.data.token);
|
localStorage.setItem("authToken", res.data.token);
|
||||||
|
|
||||||
let response = await axios.get(`/api/v1/user/details`, {
|
let response = await axios.get(`/api/v1/user/details`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${res.data.token}`,
|
Authorization: `Bearer ${res.data.token}`,
|
||||||
@ -109,7 +111,7 @@ const Login = () => {
|
|||||||
});
|
});
|
||||||
// console.log(response.data)
|
// console.log(response.data)
|
||||||
const data = response.data;
|
const data = response.data;
|
||||||
if (data.user.role === "admin") {
|
if (data.user.role === "admin" || data.user.role === "Employee") {
|
||||||
history("/dashboard");
|
history("/dashboard");
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
|
Loading…
Reference in New Issue
Block a user