diff --git a/src/_nav.js b/src/_nav.js index 49d2855..ca0faf1 100644 --- a/src/_nav.js +++ b/src/_nav.js @@ -24,6 +24,7 @@ import { cilUser, cilAlarm, cilFeaturedPlaylist, + cilLocationPin, } from "@coreui/icons"; import { CNavGroup, CNavItem, CNavTitle, CTabContent } from "@coreui/react"; @@ -40,12 +41,7 @@ const _nav = [ icon: , to: "/customers-details", }, - // { - // component: CNavItem, - // name: "Design", - // icon: , - // to: "/design", - // }, + { component: CNavGroup, name: "Charts", @@ -309,6 +305,12 @@ const _nav = [ icon: , to: "/contact/request", }, + // { + // component: CNavItem, + // name: "Email CMS", + // icon: , + // to: "/email-cms", + // }, ], }, //Blog start @@ -318,6 +320,13 @@ const _nav = [ icon: , to: "/blogs", }, + // Employee + { + component: CNavItem, + name: "Employee", + icon: , + to: "/employee", + }, //Point of Sale start { component: CNavItem, diff --git a/src/routes.js b/src/routes.js index 34f7de9..68f4b07 100644 --- a/src/routes.js +++ b/src/routes.js @@ -141,6 +141,10 @@ import Pos from "./views/PointOfSale/Pos"; import InStoreCashOrders from "./views/orders/InStoreCashOrders"; import POSViewOrders from "./views/orders/POSViewOrders"; import InStoreQRCodeOrders from "./views/orders/InStoreQRCodeOrders"; +import EmailCms from "./views/CustomerSupport/EmailCMS/EmailCms"; +import RegistrationEmail from "./views/CustomerSupport/EmailCMS/RegistrationEmail"; +import Employee from "./views/EmployeeAccess/Employee"; +import AddEmployee from "./views/EmployeeAccess/addEmployee"; const routes = [ { path: "/", exact: true, name: "Home" }, { @@ -279,6 +283,16 @@ const routes = [ element: AddContactRequest, }, //Support Requests + // { + // path: "/email-cms", + // name: "CustomerSupport Requests", + // element: EmailCms, + // }, + // { + // path: "/email-cms/registration-email", + // name: "CustomerSupport Requests", + // element: RegistrationEmail, + // }, { path: "/support/request", @@ -338,17 +352,17 @@ const routes = [ path: "/home", name: "Home", element: Home, - }, + }, { path: "/home/panel-1", name: "EditPanel1", element: EditPanel1, - }, + }, { path: "/home/panel-2", name: "EditPanel2", element: EditPanel2, - }, + }, { path: "/home/panel-3", name: "EditPanel3", @@ -358,12 +372,7 @@ const routes = [ path: "/home/panel-4", name: "EditPanel4", element: Editpanel4, - }, - - - - - + }, // { path: '/complaint/view/:id', name: 'view Complain', element: ViewComplaint }, //Complaints @@ -576,6 +585,17 @@ const routes = [ name: "Blogs", element: ViewBlog, }, + // Employee + { + path: "/employee", + name: "Employee", + element: Employee, + }, + { + path: "/add-employee", + name: "Employee", + element: AddEmployee, + }, //Charts { path: "/new-user-day-wise", diff --git a/src/views/CustomerSupport/EmailCMS/EmailCms.js b/src/views/CustomerSupport/EmailCMS/EmailCms.js new file mode 100644 index 0000000..dfb2489 --- /dev/null +++ b/src/views/CustomerSupport/EmailCMS/EmailCms.js @@ -0,0 +1,111 @@ +import { + Button, + Paper, + Table, + TableBody, + TableCell, + TableContainer, + TableHead, + TableRow, + Typography, +} from "@mui/material"; +import React from "react"; +import { Link } from "react-router-dom"; + +export default function EmailCms() { + const pages = [ + { + name: "New user registration", + action: "Edit", + path: "/email-cms/registration-email", + }, + { + name: "Forgot Password", + action: "Edit", + path: "#", + }, + { + name: "Change Password Notification ", + action: "Edit", + path: "#", + }, + { + name: "New Order", + action: "Edit", + path: "#", + }, + { + name: "Order - Processing", + action: "Edit", + path: "#", + }, + { + name: "Order - Dispatched", + action: "Edit", + path: "#", + }, + { + name: "Order - Delivered", + action: "Edit", + path: "#", + }, + { + name: "Order - Cancelled", + action: "Edit", + path: "#", + }, + ]; + + return ( +
+ + Email CMS + + + + + + Page + + Action + + + + + {pages.map((row) => ( + + + {row.name} + + + {" "} + + + + + + ))} + +
+
+
+ ); +} diff --git a/src/views/CustomerSupport/EmailCMS/RegistrationEmail.js b/src/views/CustomerSupport/EmailCMS/RegistrationEmail.js new file mode 100644 index 0000000..2f274f3 --- /dev/null +++ b/src/views/CustomerSupport/EmailCMS/RegistrationEmail.js @@ -0,0 +1,207 @@ +import { Typography } from "@material-ui/core"; +import { Box, Button } from "@mui/material"; + +import React, { useEffect, useState } from "react"; +import ReactrichTextEditor from "../../Content/reactrichTextEditor"; +import ReactQuill from "react-quill"; +import "react-quill/dist/quill.snow.css"; +import axios from "axios"; +import { isAutheticated } from "src/auth"; +import { useNavigate, useNavigation } from "react-router-dom"; + +// const TOOLBAR_OPTIONS = [ +// [{ header: [1, 2, 3, 4, 5, 6, false] }], +// [{ font: [] }], +// [{ list: "ordered" }, { list: "bullet" }], +// ["bold", "italic", "underline", "strike"], +// [{ color: [] }, { background: [] }], +// [{ align: [] }], +// [{ script: "super" }, { script: "sub" }], +// ["undo", "redo"], +// ]; + +export default function RegistrationEmail() { + const [title, setTitle] = useState("Registration Email"); + const [welcomemsg, setWelcomeMsg] = useState(""); + const [welcomemsgforDescription, setWelcomeMsgForDescription] = useState(""); + + const [subject, setSubject] = useState(""); + const [description, setDescription] = useState(""); + const [content, setContent] = useState(""); + const [added, setAdded] = useState(false); + const [olderContent, setOlderContent] = useState(""); + const [id, setId] = useState(null); + + const token = isAutheticated(); + + const getTermsAndConditions = async () => { + const response = await axios.get("/api/get-email-data", { + headers: { + Authorization: `Bearer ${token}`, + }, + }); + if (response.status === 200) { + if (response.data?.registerEmaildata.length === 0) { + return; + } + // console.log(response); + // setContent(response?.data?.registerEmaildata[0]?.termsAndContionContent); + // setOlderContent( + // response?.data?.registerEmaildata[0]?.termsAndContionContent + // ); + setSubject(response?.data?.registerEmaildata[0]?.subject); + setDescription(response?.data?.registerEmaildata[0]?.description); + setId(response?.data?.registerEmaildata[0]?._id); + } + }; + + const addTermsandConditions = async () => { + const response = await axios.post( + "/api/register-email", + { subject: subject, description: description }, + { + headers: { + Authorization: `Bearer ${token}`, + }, + } + ); + if (response.status == 200) { + swal({ + title: "Congratulations!!", + text: response?.data?.message, + icon: "success", + button: "OK", + }); + } + }; + const handleCancelClick = () => { + setAdded(!added); + }; + + const handleSaveClick = async () => { + // if (id === null) { + await addTermsandConditions(); + setAdded(true); + // } else { + // await updateContent(); + // setAdded(false); + // } + + // Reload terms and conditions + // await getTermsAndConditions(); + }; + useEffect(() => { + // addTermsandConditions(); + getTermsAndConditions(); + }, [added]); + return ( +
+
+ + +
+ + + {/* setTitle(e.target.value)} + variant="outlined" + size="small" + fullWidth + /> */} + + {" "} + Email Confiramtion:{" "} + + +
+ + + setWelcomeMsg(e.target.value)} + /> +
+ App Name : Smellika +
+ + + + setSubject(e.target.value)} + /> +
+ +
+ + + setWelcomeMsgForDescription(e.target.value)} + /> + + +
+
+
+ ); +} diff --git a/src/views/EmployeeAccess/Employee.js b/src/views/EmployeeAccess/Employee.js new file mode 100644 index 0000000..c1b20b4 --- /dev/null +++ b/src/views/EmployeeAccess/Employee.js @@ -0,0 +1,479 @@ +import React, { useState, useEffect } from "react"; +import { Link } from "react-router-dom"; +import Button from "@material-ui/core/Button"; +import { useNavigate } from "react-router-dom"; +import axios from "axios"; +import { isAutheticated } from "src/auth"; +import swal from "sweetalert"; +import { + Box, + FormControl, + IconButton, + InputLabel, + MenuItem, + Select, + TextField, +} from "@mui/material"; +import SearchIcon from "@mui/icons-material/Search"; +import Fuse from "fuse.js"; +import { Typography } from "@material-ui/core"; +// import OrderDetails from "./orderDetails"; +const Employee = () => { + 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 [users, setUsers] = useState([]); + + const [currentPage, setCurrentPage] = useState(1); + const [itemPerPage, setItemPerPage] = useState(10); + const [showData, setShowData] = useState(users); + + const handleShowEntries = (e) => { + setCurrentPage(1); + setItemPerPage(e.target.value); + }; + + // const getUsers = async () => { + // axios + // .get(`/api/v1/admin/users`, { + // headers: { + // Authorization: `Bearer ${token}`, + // }, + // }) + // .then((res) => { + // setUsers(res.data.users); + // 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(() => { + // getUsers(); + // }, [success]); + // console.log(users); + + // useEffect(() => { + // const loadData = () => { + // const indexOfLastPost = currentPage * itemPerPage; + // const indexOfFirstPost = indexOfLastPost - itemPerPage; + // setShowData(users.slice(indexOfFirstPost, indexOfLastPost)); + // }; + // loadData(); + // }, [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, + // }); + // }); + // } + // }); + // }; + + return ( +
+
+
+
+
+
+
+ All Employees +
+ +
+ +
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+ +
+ + + + + + + + + + + + + {!loading && showData.length === 0 && ( + + + + )} + {!loading ? ( + + + + ) : ( + // showData.map((user, i) => { + // return ( + // + // + // + + // + // {loading1 && ( + // <> + // + // + // + // )} + + // + + // + // + // ); + // }) + + + + {/* */} + + + {/* + */} + + + )} + +
Employee NameEmailAccess to Action
+
No Data Available
+
+ Loading... +
{user.name}{user._id} + // {new Date(user.createdAt).toLocaleString( + // "en-IN", + // { + // weekday: "short", + // month: "short", + // day: "numeric", + // year: "numeric", + // hour: "numeric", + // minute: "numeric", + // hour12: true, + // } + // )} + // loading...loading... + // {/* + // + // + // + // + // + // + // + // */} + // + // + // + //
Roshan Gargroshan@gmail.comProfile ImagedashboardLast PurchaseOrders + + +
+
+ +
+
+
+ Showing {currentPage * itemPerPage - itemPerPage + 1} to{" "} + {Math.min(currentPage * itemPerPage, users.length)} of{" "} + {users.length} entries +
+
+ +
+
+
    +
  • + setCurrentPage((prev) => prev - 1)} + > + Previous + +
  • + + {!(currentPage - 1 < 1) && ( +
  • + + setCurrentPage((prev) => prev - 1) + } + > + {currentPage - 1} + +
  • + )} + +
  • + + {currentPage} + +
  • + + {!( + (currentPage + 1) * itemPerPage - itemPerPage > + users.length - 1 + ) && ( +
  • + { + setCurrentPage((prev) => prev + 1); + }} + > + {currentPage + 1} + +
  • + )} + +
  • + users.length - 1 + ) + ? "paginate_button page-item next" + : "paginate_button page-item next disabled" + } + > + setCurrentPage((prev) => prev + 1)} + > + Next + +
  • +
+
+
+
+
+
+
+
+
+
+
+ ); +}; + +export default Employee; diff --git a/src/views/EmployeeAccess/addEmployee.js b/src/views/EmployeeAccess/addEmployee.js new file mode 100644 index 0000000..b0efd0d --- /dev/null +++ b/src/views/EmployeeAccess/addEmployee.js @@ -0,0 +1,123 @@ +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 { useNavigate } from "react-router-dom"; +import _nav from "src/_nav"; + +const AddEmployee = () => { + const [employeeName, setEmployeeName] = useState(""); + const [email, setEmail] = useState(""); + const navigate = useNavigate(); + const [checkedItems, setCheckedItems] = useState({}); + const filteredNav = _nav.filter((item) => item.name !== "Employee"); + const handleCheckboxChange = (name) => (event) => { + setCheckedItems({ + ...checkedItems, + [name]: event.target.checked, + }); + }; + console.log(checkedItems); + + return ( +
+ + {/* setTitle(e.target.value)} + variant="outlined" + size="small" + fullWidth + /> */} + + {" "} + Add Employee:{" "} + + +
+ + + setEmployeeName(e.target.value)} + /> +
+ +
+ + + setEmail(e.target.value)} + /> +
+ + +
+ {filteredNav.map((item, index) => ( +
+ + {item.name} +
+ ))} +
+
+
+ + +
+
+
+ ); +}; + +export default AddEmployee; diff --git a/src/views/Products/Products.js b/src/views/Products/Products.js index f7f11c1..c11f724 100644 --- a/src/views/Products/Products.js +++ b/src/views/Products/Products.js @@ -1,57 +1,784 @@ -import React, { useState, useEffect } from "react"; +// import React, { useState, useEffect } from "react"; +// import { Link } from "react-router-dom"; +// import Button from "@material-ui/core/Button"; +// import { useNavigate } from "react-router-dom"; +// import axios from "axios"; +// import { isAutheticated } from "src/auth"; +// import swal from "sweetalert"; +// import { +// Box, +// FormControl, +// IconButton, +// InputLabel, +// MenuItem, +// Select, +// TextField, +// } from "@mui/material"; +// import SearchIcon from "@mui/icons-material/Search"; +// import Fuse from "fuse.js"; +// import { Typography } from "@material-ui/core"; +// const Products = () => { +// const token = isAutheticated(); +// const [query, setQuery] = useState(""); +// const navigate = useNavigate(); +// const [loading, setLoading] = useState(true); +// const [success, setSuccess] = useState(true); +// const [productsData, setProductsData] = useState([]); +// const [filterData, setFilterData] = useState([]); +// const [queryData, setQueryData] = useState([]); + +// const [currentPage, setCurrentPage] = useState(1); +// const [itemPerPage, setItemPerPage] = useState(10); +// const [showData, setShowData] = useState(productsData); + +// const handleShowEntries = (e) => { +// setCurrentPage(1); +// setItemPerPage(e.target.value); +// }; + +// const getProductsData = async () => { +// axios +// .get(`/api/product/getAll/`, { +// headers: { +// Authorization: `Bearer ${token}`, +// }, +// }) +// .then((res) => { +// setProductsData(res.data?.product); +// setLoading(false); +// }) +// .catch((error) => { +// const msg = error?.response?.data?.message || "Something went wrong!"; + +// swal({ +// title: error, +// text: msg, +// icon: "error", +// button: "Retry", +// dangerMode: true, +// }); +// setLoading(false); +// }); +// }; + +// useEffect(() => { +// getProductsData(); +// }, [success]); + +// useEffect(() => { +// const loadData = () => { +// const indexOfLastPost = currentPage * itemPerPage; +// const indexOfFirstPost = indexOfLastPost - itemPerPage; +// setShowData(productsData.slice(indexOfFirstPost, indexOfLastPost)); +// }; +// loadData(); +// }, [currentPage, itemPerPage, productsData]); + +// 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/product/delete/${id}`, { +// headers: { +// "Access-Control-Allow-Origin": "*", +// Authorization: `Bearer ${token}`, +// }, +// }) +// .then((res) => { +// swal({ +// title: "Deleted", +// text: "Product Deleted successfully!", +// icon: "success", +// button: "ok", +// }); +// setSuccess((prev) => !prev); +// }) +// .catch((err) => { +// const msg = err?.response?.data?.message || "Something went wrong!"; + +// swal({ +// title: "Warning", +// text: msg, +// icon: "error", +// button: "Retry", +// dangerMode: true, +// }); +// }); +// } +// }); +// }; +// const [filterCategory, setFilterCategory] = useState(""); + +// const handleSearchClick = (query) => { +// const option = { +// isCaseSensitive: true, +// includeScore: false, +// shouldSort: true, +// includeMatches: false, +// findAllMatches: false, +// minMatchCharLength: 1, +// location: 0, +// threshold: 0.6, +// distance: 100, +// useExtendedSearch: true, +// ignoreLocation: false, +// ignoreFieldNorm: false, +// fieldNormWeight: 1, +// keys: ["name"], +// }; + +// const fuse = new Fuse(productsData, option); +// const result = fuse.search(query); + +// const searchedResult = result.map((result) => result.item); +// console.log(searchedResult); +// setQueryData(searchedResult); +// }; +// useEffect(() => { +// if (query !== "") { +// setFilterCategory(""); +// } +// setTimeout(() => handleSearchClick(query), 100); +// }, [query]); +// const uniqueCategoryNames = [ +// ...new Set(showData?.map((product) => product?.category?.categoryName)), +// ]; +// useEffect(() => { +// setTimeout(() => { +// if (filterCategory !== "") { +// const filteredProducts = productsData.filter( +// (product) => product.category?.categoryName === filterCategory +// ); + +// setFilterData(filteredProducts); +// } else { +// // If no category is selected, show all products +// setShowData(productsData); +// // setFilterData(filteredProducts); +// } +// }, 100); +// }, [filterCategory, productsData]); +// return ( +//
+//
+//
+//
+//
+//
+//
+// Products +//
+ +//
+// +//
+//
+//
+//
+ +//
+//
+//
+//
+//
+//
+//
+// +//
+//
+//
+// +// +//
+//
+// +// +//
+//
+// +//
+//
+ +//
+// +// +// +// +// +// + +// +// +// +// +// +// +// {!loading && showData.length === 0 && ( +// +// +// +// )} +// {loading ? ( +// +// +// +// ) : query === "" && filterCategory == "" ? ( +// showData.map((product, i) => { +// return ( +// +// +// +// +// +// +// +// +// ); +// }) +// ) : query !== "" ? ( +// queryData.map((product, i) => { +// return ( +// +// +// +// +// +// +// +// +// ); +// }) +// ) : ( +// query == "" && +// filterData.map((product, i) => { +// return ( +// +// +// +// +// +// +// +// +// ); +// }) +// )} +// +//
ImageProductCategoryPriceAdded OnActions
+//
No Data Available
+//
+// Loading... +//
+// {product.image && +// product.image.map((i, j) => ( +// +// ))} +// {product.name} +// {product.category?.categoryName !== "" +// ? product.category?.categoryName +// : "Category Not selected "} +// +// ₹ +// {product?.total_amount +// ? product?.total_amount +// : product?.variants[0]?.price} +// +// {new Date(product.createdAt).toLocaleString( +// "en-IN", +// { +// weekday: "short", +// month: "short", +// day: "numeric", +// year: "numeric", +// hour: "numeric", +// minute: "numeric", +// hour12: true, +// } +// )} +// +// +// +// +// +// +// +// +// +// +//
+// {product.image && +// product.image.map((i, j) => ( +// +// ))} +// {product.name} +// {product.category !== "" +// ? product.category?.categoryName +// : "Category Not selected "} +// ₹{product.price} +// {new Date(product.createdAt).toLocaleString( +// "en-IN", +// { +// weekday: "short", +// month: "short", +// day: "numeric", +// year: "numeric", +// hour: "numeric", +// minute: "numeric", +// hour12: true, +// } +// )} +// +// +// +// +// +// +// +// +// +// +//
+// {product.image && +// product.image.map((i, j) => ( +// +// ))} +// {product.name} +// {product.category?.categoryName} +// ₹{product.price} +// {new Date(product.createdAt).toLocaleString( +// "en-IN", +// { +// weekday: "short", +// month: "short", +// day: "numeric", +// year: "numeric", +// hour: "numeric", +// minute: "numeric", +// hour12: true, +// } +// )} +// +// +// +// +// +// +// +// +// +// +//
+//
+ +//
+//
+//
+// Showing {currentPage * itemPerPage - itemPerPage + 1} to{" "} +// {Math.min( +// currentPage * itemPerPage, +// productsData.length +// )}{" "} +// of {productsData.length} entries +//
+//
+ +//
+//
+//
    +//
  • +// setCurrentPage((prev) => prev - 1)} +// > +// Previous +// +//
  • + +// {!(currentPage - 1 < 1) && ( +//
  • +// +// setCurrentPage((prev) => prev - 1) +// } +// > +// {currentPage - 1} +// +//
  • +// )} + +//
  • +// +// {currentPage} +// +//
  • + +// {!( +// (currentPage + 1) * itemPerPage - itemPerPage > +// productsData.length - 1 +// ) && ( +//
  • +// { +// setCurrentPage((prev) => prev + 1); +// }} +// > +// {currentPage + 1} +// +//
  • +// )} + +//
  • +// productsData.length - 1 +// ) +// ? "paginate_button page-item next" +// : "paginate_button page-item next disabled" +// } +// > +// setCurrentPage((prev) => prev + 1)} +// > +// Next +// +//
  • +//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+//
+// ); +// }; + +// export default Products; + +import React, { useState, useEffect, useRef } from "react"; import { Link } from "react-router-dom"; +import axios from "axios"; import Button from "@material-ui/core/Button"; import { useNavigate } from "react-router-dom"; -import axios from "axios"; import { isAutheticated } from "src/auth"; import swal from "sweetalert"; -import { - Box, - FormControl, - IconButton, - InputLabel, - MenuItem, - Select, - TextField, -} from "@mui/material"; -import SearchIcon from "@mui/icons-material/Search"; -import Fuse from "fuse.js"; -import { Typography } from "@material-ui/core"; const Products = () => { const token = isAutheticated(); - const [query, setQuery] = useState(""); const navigate = useNavigate(); - const [loading, setLoading] = useState(true); + const [loading, setLoading] = useState(false); const [success, setSuccess] = useState(true); const [productsData, setProductsData] = useState([]); - const [filterData, setFilterData] = useState([]); - const [queryData, setQueryData] = useState([]); + const [categories, setCategories] = useState([]); + + const nameRef = useRef(); + const categoryRef = useRef(); + const FeatureProductRef = useRef(); const [currentPage, setCurrentPage] = useState(1); const [itemPerPage, setItemPerPage] = useState(10); - const [showData, setShowData] = useState(productsData); - - const handleShowEntries = (e) => { - setCurrentPage(1); - setItemPerPage(e.target.value); - }; - + const [totalData, setTotalData] = useState(0); + // const { + // edit, + // add, + // delete: deletepermission, + // } = checkPermission("Product Master"); const getProductsData = async () => { + setLoading(true); + axios - .get(`/api/product/getAll/`, { + .get(`/api/product/getAll/admin/`, { headers: { Authorization: `Bearer ${token}`, }, + params: { + page: currentPage, + show: itemPerPage, + name: nameRef.current.value, + category: categoryRef.current.value, + FeatureProduct: FeatureProductRef.current.value, + }, }) .then((res) => { + console.log("res.data?.data", res.data?.product); setProductsData(res.data?.product); + setTotalData(res.data?.total_data); setLoading(false); }) - .catch((error) => { - const msg = error?.response?.data?.message || "Something went wrong!"; - + .catch((err) => { + const msg = err?.response?.data?.message || "Something went wrong!"; swal({ - title: error, + title: err, text: msg, icon: "error", button: "Retry", @@ -59,20 +786,30 @@ const Products = () => { }); setLoading(false); }); + + setLoading(false); + }; + + const getCatagories = () => { + axios + .get(`/api/category/getCategories`, { + headers: { + "Access-Control-Allow-Origin": "*", + Authorization: `Bearer ${token}`, + }, + }) + .then((res) => { + setCategories(res?.data?.categories); + }); }; useEffect(() => { - getProductsData(); - }, [success]); + getCatagories(); + }, []); useEffect(() => { - const loadData = () => { - const indexOfLastPost = currentPage * itemPerPage; - const indexOfFirstPost = indexOfLastPost - itemPerPage; - setShowData(productsData.slice(indexOfFirstPost, indexOfLastPost)); - }; - loadData(); - }, [currentPage, itemPerPage, productsData]); + getProductsData(); + }, [success, itemPerPage, currentPage]); const handleDelete = (id) => { swal({ @@ -101,8 +838,9 @@ const Products = () => { setSuccess((prev) => !prev); }) .catch((err) => { - const msg = err?.response?.data?.message || "Something went wrong!"; - + let msg = err?.response?.data?.message + ? err?.response?.data?.message + : "Something went wrong!"; swal({ title: "Warning", text: msg, @@ -114,57 +852,85 @@ const Products = () => { } }); }; - const [filterCategory, setFilterCategory] = useState(""); - - const handleSearchClick = (query) => { - const option = { - isCaseSensitive: true, - includeScore: false, - shouldSort: true, - includeMatches: false, - findAllMatches: false, - minMatchCharLength: 1, - location: 0, - threshold: 0.6, - distance: 100, - useExtendedSearch: true, - ignoreLocation: false, - ignoreFieldNorm: false, - fieldNormWeight: 1, - keys: ["name"], - }; - - const fuse = new Fuse(productsData, option); - const result = fuse.search(query); - - const searchedResult = result.map((result) => result.item); - console.log(searchedResult); - setQueryData(searchedResult); - }; - useEffect(() => { - if (query !== "") { - setFilterCategory(""); - } - setTimeout(() => handleSearchClick(query), 100); - }, [query]); - const uniqueCategoryNames = [ - ...new Set(showData?.map((product) => product?.category?.categoryName)), - ]; - useEffect(() => { - setTimeout(() => { - if (filterCategory !== "") { - const filteredProducts = productsData.filter( - (product) => product.category?.categoryName === filterCategory - ); - - setFilterData(filteredProducts); - } else { - // If no category is selected, show all products - setShowData(productsData); - // setFilterData(filteredProducts); + const handleFeaturedProduct = (id) => { + swal({ + title: "Are you sure?", + icon: "warning", + buttons: { + Yes: { text: "Yes", value: true }, + Cancel: { text: "Cancel", value: "cancel" }, + }, + }).then((value) => { + if (value === true) { + axios + .patch(`/api/product/admin/feature_product/status/${id}`, { + headers: { + "Access-Control-Allow-Origin": "*", + Authorization: `Bearer ${token}`, + }, + }) + .then((res) => { + swal({ + title: "Changed", + text: " Feature Product status changed successfully!", + icon: "success", + button: "ok", + }); + setSuccess((prev) => !prev); + }) + .catch((err) => { + let msg = err?.response?.data?.msg + ? err?.response?.data?.msg + : "Something went wrong!"; + swal({ + title: "Warning", + text: msg, + icon: "warning", + button: "ok", + dangerMode: true, + }); + }); } - }, 100); - }, [filterCategory, productsData]); + }); + }; + const handleStatus = (id) => { + swal({ + title: "Are you sure?", + icon: "warning", + buttons: { + Yes: { text: "Yes", value: true }, + Cancel: { text: "Cancel", value: "cancel" }, + }, + }).then((value) => { + if (value === true) { + axios + .patch(`/api/product/admin/status/${id}`, { + headers: { + "Access-Control-Allow-Origin": "*", + Authorization: `Bearer ${token}`, + }, + }) + .then((res) => { + swal({ + title: "Changed", + text: "Product status changed successfully!", + icon: "success", + button: "ok", + }); + setSuccess((prev) => !prev); + }) + .catch((err) => { + swal({ + title: "Warning", + text: "Something went wrong!", + icon: "error", + button: "Retry", + dangerMode: true, + }); + }); + } + }); + }; return (
@@ -182,7 +948,6 @@ const Products = () => {
Products
-
+
@@ -337,21 +1051,24 @@ const Products = () => { style={{ border: "1px solid" }} > Image Product Category + Feature Product Price + Status + Added On Actions - {!loading && showData.length === 0 && ( + {!loading && productsData?.length === 0 && (
No Data Available
@@ -364,21 +1081,30 @@ const Products = () => { Loading... - ) : query === "" && filterCategory == "" ? ( - showData.map((product, i) => { + ) : ( + productsData?.map((product, i) => { return ( - {product.image && - product.image.map((i, j) => ( + {product?.image && + product?.image?.length !== 0 ? ( + <> - ))} + + ) : ( +
+

No

+

image

+

uploaded!

+
+ )} {product.name} @@ -386,6 +1112,23 @@ const Products = () => { ? product.category?.categoryName : "Category Not selected "} + + + + + ₹ {product?.total_amount @@ -393,208 +1136,21 @@ const Products = () => { : product?.variants[0]?.price} - {new Date(product.createdAt).toLocaleString( - "en-IN", - { - weekday: "short", - month: "short", - day: "numeric", - year: "numeric", - hour: "numeric", - minute: "numeric", - hour12: true, - } - )} - - - - - - - - - + - + {product?.product_Status} + - - ); - }) - ) : query !== "" ? ( - queryData.map((product, i) => { - return ( - - - {product.image && - product.image.map((i, j) => ( - - ))} - - {product.name} - - {product.category !== "" - ? product.category?.categoryName - : "Category Not selected "} - - ₹{product.price} - - {new Date(product.createdAt).toLocaleString( - "en-IN", - { - weekday: "short", - month: "short", - day: "numeric", - year: "numeric", - hour: "numeric", - minute: "numeric", - hour12: true, - } - )} - - - - - - - - - - - - - - ); - }) - ) : ( - query == "" && - filterData.map((product, i) => { - return ( - - - {product.image && - product.image.map((i, j) => ( - - ))} - - {product.name} - - {product.category?.categoryName} - - ₹{product.price} {new Date(product.createdAt).toLocaleString( "en-IN", @@ -610,6 +1166,21 @@ const Products = () => { )} + {/* + + */} + + { aria-live="polite" > Showing {currentPage * itemPerPage - itemPerPage + 1} to{" "} - {Math.min( - currentPage * itemPerPage, - productsData.length - )}{" "} - of {productsData.length} entries + {Math.min(currentPage * itemPerPage, totalData)} of{" "} + {totalData} entries
@@ -710,6 +1280,7 @@ const Products = () => { className="page-link" style={{ cursor: "pointer" }} onClick={() => setCurrentPage((prev) => prev - 1)} + disabled={loading} > Previous @@ -723,6 +1294,7 @@ const Products = () => { onClick={(e) => setCurrentPage((prev) => prev - 1) } + disabled={loading} > {currentPage - 1} @@ -740,7 +1312,7 @@ const Products = () => { {!( (currentPage + 1) * itemPerPage - itemPerPage > - productsData.length - 1 + totalData - 1 ) && (
  • { onClick={() => { setCurrentPage((prev) => prev + 1); }} + disabled={loading} > {currentPage + 1} @@ -759,7 +1332,7 @@ const Products = () => { className={ !( (currentPage + 1) * itemPerPage - itemPerPage > - productsData.length - 1 + totalData - 1 ) ? "paginate_button page-item next" : "paginate_button page-item next disabled" @@ -769,6 +1342,7 @@ const Products = () => { className="page-link" style={{ cursor: "pointer" }} onClick={() => setCurrentPage((prev) => prev + 1)} + disabled={loading} > Next diff --git a/src/views/customerDetails/addCustomer.js b/src/views/customerDetails/addCustomer.js index 2f0dc20..025e7ab 100644 --- a/src/views/customerDetails/addCustomer.js +++ b/src/views/customerDetails/addCustomer.js @@ -42,6 +42,8 @@ const AddCustomer = () => { state: "", postalCode: "", country: "", + company_name: "", + gst_number: Number, }); // console.log(data); @@ -373,6 +375,50 @@ const AddCustomer = () => { /> + + + + Company Name + + handleChange(e)} + + // value={accountDetails.firstname} + // onChange={handerInputChanges} + /> + + + + + + GST Number + + handleChange(e)} + + // value={accountDetails.firstname} + // onChange={handerInputChanges} + /> + +