diff --git a/src/App.js b/src/App.js index 6473605..ba18c6d 100644 --- a/src/App.js +++ b/src/App.js @@ -1,111 +1,192 @@ -import React, { Component, Suspense } from "react"; +// import React, { Component, Suspense } from "react"; +// import axios from "axios"; +// import { Router, Route, Routes, HashRouter } from "react-router-dom"; +// import { useState, useEffect } from "react"; +// import { Toaster } from "react-hot-toast"; +// import "./scss/style.scss"; +// import ForgotPassword from "./views/pages/register/ForgotPassword"; +// import NewRegister from "./views/pages/register/NewRegister"; +// import ProtectedRoute from './components/ProtectedRoute'; +// import { isAutheticated } from "./auth"; +// import InternetConnectionPopUp from "./views/InternetConnectionPopUp"; + +// const loading = ( +//
+//
+//
+// ); +// // import EditProducts from './views/Commerce/Editproducts' +// // Containers +// const DefaultLayout = React.lazy(() => import("./layout/DefaultLayout")); + +// // Pages +// const Login = React.lazy(() => import("./views/pages/login/Login")); +// const Register = React.lazy(() => +// import("./views/pages/register/Change_password") +// ); +// const Page404 = React.lazy(() => +// import("./views/pages/register/page404/Page404") +// ); +// const Page500 = React.lazy(() => import("./views/pages/page500/Page500")); + +// const App = () => { +// const [userdata, setUserData] = useState(null); +// const token = isAutheticated(); + +// 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("jjjjjjjj", 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(); +// }, []); +// return ( +// +// +// +// } /> +// } +// /> +// } +// /> +// } /> +// } /> + +// +// ) : userdata === false ? ( +// +// ) : ( +//
+// ) +// }/>} +// /> + +// } />}/> +//
+// +//
+// +//
+// ); +// }; +// export default App; + +import React, { Suspense, useEffect, useState } from "react"; import axios from "axios"; -import { Router, Route, Routes, HashRouter } from "react-router-dom"; -import { useState, useEffect } from "react"; +import { HashRouter, Routes, Route, Navigate } from "react-router-dom"; import { Toaster } from "react-hot-toast"; import "./scss/style.scss"; import ForgotPassword from "./views/pages/register/ForgotPassword"; import NewRegister from "./views/pages/register/NewRegister"; -// import ProtectedRoute from './components/ProtectedRoute'; +import ProtectedRoute from './components/ProtectedRoute'; import { isAutheticated } from "./auth"; import InternetConnectionPopUp from "./views/InternetConnectionPopUp"; const loading = ( -
-
-
+
+
+
); -// import EditProducts from './views/Commerce/Editproducts' -// Containers -const DefaultLayout = React.lazy(() => import("./layout/DefaultLayout")); -// Pages +const DefaultLayout = React.lazy(() => import("./layout/DefaultLayout")); const Login = React.lazy(() => import("./views/pages/login/Login")); -const Register = React.lazy(() => - import("./views/pages/register/Change_password") -); -const Page404 = React.lazy(() => - import("./views/pages/register/page404/Page404") -); +const Page404 = React.lazy(() => import("./views/pages/register/page404/Page404")); const Page500 = React.lazy(() => import("./views/pages/page500/Page500")); const App = () => { - const [userdata, setUserData] = useState(null); - const token = isAutheticated(); + const [userdata, setUserData] = useState(null); + const token = isAutheticated(); - 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("jjjjjjjj", 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(); - }, []); - return ( - - - - } /> - } - /> - } - /> - } /> - } /> - - - ) : userdata === false ? ( - - ) : ( -
- ) + useEffect(() => { + const getUser = async () => { + let existanceData = localStorage.getItem("authToken"); + if (!existanceData) { + setUserData(false); + } else { + try { + let response = await axios.get(`/api/v1/user/details`, { + headers: { + Authorization: `Bearer ${token}`, + }, + }); + 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(); + }, [token]); - } /> -
- -
- -
- ); + return ( + + + + } /> + } /> + } /> + } /> + } /> + + } + /> + + {/* Redirect all other routes to 404 */} + } /> + + + + + + ); }; + export default App; diff --git a/src/_nav.js b/src/_nav.js index 730ed17..0bb43e5 100644 --- a/src/_nav.js +++ b/src/_nav.js @@ -38,13 +38,13 @@ const _nav = [ icon: , group: "", }, - // { - // component: CNavItem, - // name: "Customers", - // icon: , - // to: "/customers-details", - // group: "Customers", - // }, + { + component: CNavItem, + name: "Principal Distributor", + icon: , + to: "/principal-distributor", + group: "PrincipalDistributor", + }, // { // component: CNavGroup, @@ -84,6 +84,13 @@ const _nav = [ group: "SalesCoOrdinator", }, // { + // component: CNavItem, + // name: "Attendance", + // icon: , + // to: "/attendance/today", + // group: "AttendanceSalesCoOrdinator", + // }, + // { // component: CNavGroup, // name: "Orders", // icon: , diff --git a/src/components/ProtectedRoute.js b/src/components/ProtectedRoute.js index 91ad63a..bb65726 100644 --- a/src/components/ProtectedRoute.js +++ b/src/components/ProtectedRoute.js @@ -1,18 +1,35 @@ -import React, { useEffect, useState, } from "react"; +// import React, { useEffect, useState, } from "react"; +// import { useNavigate } from "react-router-dom"; +// const ProtectedRoute = (props) => { +// let Cmp = props; +// const history = useNavigate(); +// useEffect(() => { +// if (!localStorage.getItem('authToken')) +// history('/') +// }, []) +// return ( +// <> +// +// {/* {...props} */} +// +// ) +// } + +// export default ProtectedRoute +import React, { useEffect } from "react"; import { useNavigate } from "react-router-dom"; -const ProtectedRoute = (props) => { - let Cmp = props; - const history = useNavigate(); + +const ProtectedRoute = ({ element: Element }) => { + const navigate = useNavigate(); + useEffect(() => { - if (!localStorage.getItem('authToken')) - history('/') - }, []) - return ( - <> - - {/* {...props} */} - - ) + if (!localStorage.getItem('authToken')) { + navigate('/'); + } + }, [navigate]); + + return ; } -export default ProtectedRoute \ No newline at end of file +export default ProtectedRoute; + diff --git a/src/index.js b/src/index.js index b47a948..adbdd11 100644 --- a/src/index.js +++ b/src/index.js @@ -15,8 +15,8 @@ import { cibGmail } from "@coreui/icons"; import { createRoot } from "react-dom/client"; const setupAxios = () => { - // axios.defaults.baseURL = "http://localhost:5000"; - axios.defaults.baseURL = "https://cheminova-api-2.onrender.com"; + axios.defaults.baseURL = "http://localhost:5000"; + // axios.defaults.baseURL = "https://cheminova-api-2.onrender.com"; axios.defaults.headers = { "Cache-Control": "no-cache,no-store", diff --git a/src/routes.js b/src/routes.js index 6852fc2..8d46c8c 100644 --- a/src/routes.js +++ b/src/routes.js @@ -89,9 +89,9 @@ import EditShippingPolicy from "./views/Content/editShippingPolicy"; import EditRefundpolicy from "./views/Content/editRefundPolicy"; import EditAboutUs from "./views/Content/editAboutUs"; -// import EditUserAddress from "./views/customerDetails/editUserAddress"; +// import editPrincipalDistributorAddress from "./views/customerDetails/editPrincipalDistributorAddress"; // import AddUserAddress from "./views/customerDetails/addUserAddress"; -import viewDetails from "./views/customerDetails/viewDetails"; +import viewDetails from "./views/PrincipalDistributors/viewDetails"; import Design from "./views/Design/design"; import RegisterImage from "./views/Images/RegisterImage"; import LoginImage from "./views/Images/LoginImage"; @@ -112,11 +112,11 @@ import CreateBlog from "./views/Blog/CreateBlog"; import users from "./views/Users/users"; import UpdateBlog from "./views/Blog/EditBlog"; import ViewBlog from "./views/Blog/ViewBlog"; -import CustomerTable from "./views/customerDetails/customerTable"; -import SingleUserAllDetails from "./views/customerDetails/singleUserAllDetails"; +import principalDistributor from "./views/PrincipalDistributors/principalDistributor"; +import SinglePrincipalDistributorAllDetails from "./views/PrincipalDistributors/singlePrincipalDistributorAllDetails"; import { element } from "prop-types"; -import AddCustomer from "./views/customerDetails/addCustomer"; +import addPrincipalDistributor from "./views/PrincipalDistributors/addPrincipalDistributor"; import InStoreCashOrders from "./views/orders/InStoreCashOrders"; import InStoreQRCodeOrders from "./views/orders/InStoreQRCodeOrders"; @@ -127,6 +127,9 @@ import Currency from "./views/configuration/Currency"; import SalesCoOrdinator from "./views/SalesCoOrdinators/SalesCoOrdinator"; import EditSalesCoOrdinator from "./views/SalesCoOrdinators/EditSalesCoOrdinator"; import AddSalesCoOrdinator from "./views/SalesCoOrdinators/AddSalesCoOrdinator"; +import TodayAttendanceSales from "./views/SalesAttendance/TodayAttendanceSales"; +import AttendanceSalesCoordinator from "./views/SalesAttendance/AttendanceSalesCoordinator"; +import SingleAttendanceSalesCoOrdinator from "./views/SalesAttendance/SingleAttendanceSalesCoordinator"; const routes = [ //dashboard @@ -194,6 +197,25 @@ const routes = [ element: AddSalesCoOrdinator, navName: "SalesCoOrdinators", }, + // Attendence SalesCoOrdinator + { + path: "/attendance/today", + name: "Today's Attendance SalesCoOrdinator", + element: TodayAttendanceSales, + navName: "AttendanceSalesCoOrdinator", + }, + { + path: "/salescoordinator/attendance", + name: "Attendance SalesCoOrdinator", + element: AttendanceSalesCoordinator, + navName: "AttendanceSalesCoOrdinator", + }, + { + path: "/attendance/view/:id", + name: "Single SalesCoOrdinator Attendance", + element: SingleAttendanceSalesCoOrdinator, + navName: "AttendanceSalesCoOrdinator", + }, //Gst tax { path: "/tax", @@ -240,22 +262,22 @@ const routes = [ // }, //------------------customers Route------------------------- { - path: "/customers-details", - name: "Customers", - element: CustomerTable, - navName: "Customers", + path: "/principal-distributor", + name: "PrincipalDistributor", + element: principalDistributor, + navName: "PrincipalDistributor", }, { - path: "/customers-details/:_id", - name: "Customers", - element: SingleUserAllDetails, - navName: "Customers", + path: "/principal-distributor/:_id", + name: "PrincipalDistributor", + element: SinglePrincipalDistributorAllDetails, + navName: "PrincipalDistributor", }, { - path: "/add-customer", - name: "Customers", - element: AddCustomer, - navName: "Customers", + path: "/add-principal-distributor", + name: "PrincipalDistributor", + element: addPrincipalDistributor, + navName: "PrincipalDistributor", }, //------------------ End customers Route------------------------- @@ -267,7 +289,7 @@ const routes = [ // { // path: "/users-address/edit/:id", // name: "Edit user address", - // element: EditUserAddress, + // element: editPrincipalDistributorAddress, // }, { path: "/users-address/view", diff --git a/src/views/PrincipalDistributors/addPrincipalDistributor.js b/src/views/PrincipalDistributors/addPrincipalDistributor.js new file mode 100644 index 0000000..c573f70 --- /dev/null +++ b/src/views/PrincipalDistributors/addPrincipalDistributor.js @@ -0,0 +1,361 @@ +import React, { useState } from "react"; +import { + TextField, + Button, + Card, + FormControl, + Grid, + FormHelperText, + OutlinedInput, + Box, +} from "@mui/material"; +import { useNavigate } from "react-router-dom"; +import toast from "react-hot-toast"; +import axios from "axios"; +import { isAutheticated } from "src/auth"; + +const styles = { + formStyle: { + fontWeight: "700", + fontSize: "12px", + fontFamily: "inter", + marginBottom: "3px", + marginLeft: "0", + }, + topRightButton: { + position: "absolute", + top: "10px", + right: "10px", + }, +}; + +const AddPrincipalDistributor = () => { + const navigate = useNavigate(); + const [user, setUser] = useState({ + name: "", + email: "", + password: "", + phone: "", + }); + const [id, setUserId] = useState(""); + const token = isAutheticated(); + + const [loading, setLoading] = useState(false); + const [data, setData] = useState({ + street: "", + city: "", + state: "", + postalCode: "", + country: "", + company_name: "", + gst_number: "", + }); + + const handleChange = (e) => { + setData((prev) => ({ ...prev, [e.target.name]: e.target.value })); + }; + + const handleInputChanges = (e) => { + setUser({ ...user, [e.target.name]: e.target.value }); + }; + + const handleAddressSubmit = (e) => { + e.preventDefault(); + if ( + data.street === "" || + data.city === "" || + data.state === "" || + data.postalCode === "" || + data.country === "" + ) { + toast.error("Please fill all mandatory fields."); + return; + } + setLoading(true); + axios + .post( + `/api/shipping/address/admin/new/${id}`, + { ...data }, + { + headers: { + "Access-Control-Allow-Origin": "*", + Authorization: `Bearer ${token}`, + }, + } + ) + .then((res) => { + setLoading(false); + navigate("/principal-distributor"); + toast.success(res.data.message ? res.data.message : "Address Added!"); + }) + .catch((error) => { + setLoading(false); + toast.error( + error.response.data.message + ? error.response.data.message + : "Something went wrong!" + ); + }); + }; + + const generatePassword = (name, email) => { + const combinedStr = (name + email).toLowerCase(); + const specialChars = "@#*"; + const alphaChars = combinedStr.match(/[a-zA-Z]/g); + const filteredChars = combinedStr.match(/[^\W_]/g); + let passwordChars = alphaChars.concat(filteredChars); + + 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); + const password = passwordChars.join("").slice(0, 8); + return password; + }; + + const handleFormSubmit = async (e) => { + e.preventDefault(); + try { + if (!user.name || !user.email || !user.phone) { + throw new Error("Fill all fields!"); + } + + const generatedPassword = generatePassword(user.name, user.email); + setUser({ ...user, password: generatedPassword }); + + const response = await axios.post("/api/v1/user/register", { + ...user, + password: generatedPassword, + }); + if (response.status === 201) { + toast.success("User Added Successfully"); + // console.log(response.data); + setUserId(response.data.userId); + } + } catch (error) { + console.log(error.response.data.message); + toast.error(error.response.data.message); + } + }; + + const handleCancel = () => { + navigate("/principal-distributor"); + }; + + return ( +
+ + + +
+ +
+ +
+ +
+ +
+ + +
+ + + + + STREET ADDRESS* + + + + + + + + COUNTRY* + + + + + + + + TOWN CITY* + + + + + + + + STATE* + + + + + + + + ZIP CODE* + + + + + + + + Company Name + + + + + + + + GST Number + + + + + + + + +
+
+
+ ); +}; + +export default AddPrincipalDistributor; diff --git a/src/views/customerDetails/addUserAddress.js b/src/views/PrincipalDistributors/addPrincipalDistributorAddress.js similarity index 99% rename from src/views/customerDetails/addUserAddress.js rename to src/views/PrincipalDistributors/addPrincipalDistributorAddress.js index d9367b3..c841534 100644 --- a/src/views/customerDetails/addUserAddress.js +++ b/src/views/PrincipalDistributors/addPrincipalDistributorAddress.js @@ -18,7 +18,7 @@ import { useNavigate } from "react-router-dom"; export default function AddUserAddress() { const token = isAutheticated(); - console.log(token); + // console.log(token); const [selectUserType, setSelectUserType] = useState(""); const [name, setName] = useState(""); const [email, setEmail] = useState(""); diff --git a/src/views/customerDetails/editUserAddress.js b/src/views/PrincipalDistributors/editPrincipalDistributorAddress.js similarity index 99% rename from src/views/customerDetails/editUserAddress.js rename to src/views/PrincipalDistributors/editPrincipalDistributorAddress.js index f341db6..983ab0c 100644 --- a/src/views/customerDetails/editUserAddress.js +++ b/src/views/PrincipalDistributors/editPrincipalDistributorAddress.js @@ -15,7 +15,7 @@ import axios from "axios"; import { isAutheticated } from "src/auth"; import { useNavigate, useParams } from "react-router-dom"; -export default function EditUserAddress() { +export default function editPrincipalDistributorAddress() { const token = isAutheticated(); const [selectUserType, setSelectUserType] = useState(""); diff --git a/src/views/customerDetails/mainAddress.js b/src/views/PrincipalDistributors/mainAddress.js similarity index 100% rename from src/views/customerDetails/mainAddress.js rename to src/views/PrincipalDistributors/mainAddress.js diff --git a/src/views/customerDetails/orderDetails.js b/src/views/PrincipalDistributors/orderDetails.js similarity index 100% rename from src/views/customerDetails/orderDetails.js rename to src/views/PrincipalDistributors/orderDetails.js diff --git a/src/views/customerDetails/customerTable.js b/src/views/PrincipalDistributors/principalDistributor.js similarity index 96% rename from src/views/customerDetails/customerTable.js rename to src/views/PrincipalDistributors/principalDistributor.js index ba6f0fb..0c65d7e 100644 --- a/src/views/customerDetails/customerTable.js +++ b/src/views/PrincipalDistributors/principalDistributor.js @@ -18,7 +18,7 @@ import SearchIcon from "@mui/icons-material/Search"; import Fuse from "fuse.js"; import { Typography } from "@material-ui/core"; import OrderDetails from "./orderDetails"; -const CustomerTable = () => { +const principalDistributor = () => { const token = isAutheticated(); const [query, setQuery] = useState(""); const navigate = useNavigate(); @@ -44,6 +44,7 @@ const CustomerTable = () => { }, }) .then((res) => { + // console.log(res.data); setUsers(res.data.users); setLoading(false); }) @@ -62,7 +63,7 @@ const CustomerTable = () => { useEffect(() => { getUsers(); }, [success]); - console.log(users); + // console.log(users); useEffect(() => { const loadData = () => { @@ -72,7 +73,7 @@ const CustomerTable = () => { }; loadData(); }, [currentPage, itemPerPage, users]); - console.log(users); + // console.log(users); // const handleDelete = (id) => { // swal({ @@ -128,7 +129,7 @@ const CustomerTable = () => { " >
- All Customers + All Principal Distributor
@@ -141,10 +142,10 @@ const CustomerTable = () => { textTransform: "capitalize", }} onClick={() => { - navigate("/add-customer"); + navigate("/add-principal-distributor"); }} > - Add User + Add Principal Distributor
@@ -191,7 +192,7 @@ const CustomerTable = () => { style={{ background: "rgb(140, 213, 213)" }} > - Customer Name + Principal Distributor Name Unique Id {/* Profile Image */} @@ -313,7 +314,9 @@ const CustomerTable = () => { Delete */} - + + + + + + +
+
+
+
+
+
+
+ +
+
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+ +
+ + + + + + + + + + + + + + {loading ? ( + + + + ) : salescoordinatorsData?.length > 0 ? ( + salescoordinatorsData?.map((salescoordinator, i) => { + return ( + + + + + + + + + ); + }) + ) : ( + + + + )} + +
NameMobile No.EmailVerifyRegister OnAction
+ Loading... +
+ {salescoordinator?.name} + + {salescoordinator?.mobileNumber} + + {salescoordinator?.email ? ( + salescoordinator?.email + ) : ( + + No Email Added! + + )} + + + {salescoordinator?.isVerified + ? "YES" + : "NO"} + + + {new Date( + salescoordinator.createdAt + ).toLocaleString("en-IN", { + weekday: "short", + month: "short", + day: "numeric", + year: "numeric", + hour: "numeric", + minute: "numeric", + hour12: true, + })} + + + + +
+
No SalesCoOrdinator Available...
+
+
+ +
+
+
+ Showing {currentPage * itemPerPage - itemPerPage + 1} to{" "} + {Math.min(currentPage * itemPerPage, totalData)} of{" "} + {totalData} entries +
+
+ +
+
+
    +
  • + + setCurrentPage((prev) => + prev > 1 ? prev - 1 : prev + ) + } + > + Previous + +
  • +
  • = totalData + ? "paginate_button page-item next disabled" + : "paginate_button page-item next" + } + > + + setCurrentPage((prev) => + prev * itemPerPage < totalData + ? prev + 1 + : prev + ) + } + > + Next + +
  • +
+
+
+
+
+
+
+
+ + + + ); +}; + +export default AttendanceSalesCoordinator; diff --git a/src/views/SalesAttendance/SingleAttendanceSalesCoordinator.js b/src/views/SalesAttendance/SingleAttendanceSalesCoordinator.js new file mode 100644 index 0000000..3856eb1 --- /dev/null +++ b/src/views/SalesAttendance/SingleAttendanceSalesCoordinator.js @@ -0,0 +1,255 @@ +import React, { useState, useEffect } from "react"; +import { useParams, useNavigate } from "react-router-dom"; +import axios from "axios"; +import Button from "@material-ui/core/Button"; +import { isAutheticated } from "src/auth"; +import swal from "sweetalert"; + +const SingleAttendanceSalesCoOrdinator = () => { + const { id } = useParams(); + const token = isAutheticated(); + const navigate = useNavigate(); + const [loading, setLoading] = useState(false); + const [salesCoordinator, setSalesCoordinator] = useState({}); + const [attendanceData, setAttendanceData] = useState([]); + const [currentPage, setCurrentPage] = useState(1); + const [itemPerPage, setItemPerPage] = useState(10); + const [totalData, setTotalData] = useState(0); + + const getSingleSalesCoOrdinatorAttendance = async () => { + setLoading(true); + try { + const res = await axios.get(`/api/v1/attendance/${id}`, { + headers: { + Authorization: `Bearer ${token}`, + }, + params: { + page: currentPage, + show: itemPerPage, + }, + }); + setSalesCoordinator(res.data?.user); + setAttendanceData(res.data?.attendance); + // console.log(res.data); + setTotalData(res.data?.total_data); + } catch (err) { + const msg = err?.response?.data?.message || "Something went wrong!"; + swal({ + title: "Error", + text: msg, + icon: "error", + button: "Retry", + dangerMode: true, + }); + } finally { + setLoading(false); + } + }; + + useEffect(() => { + getSingleSalesCoOrdinatorAttendance(); + }, [itemPerPage, currentPage]); + + return ( +
+
+
+
+
+
+
+ SalesCoOrdinator Attendance +
+ {salesCoordinator.name} ({salesCoordinator.email}) +
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+ +
+ + + + + + + + + + + + {loading ? ( + + + + ) : attendanceData?.length > 0 ? ( + attendanceData?.map((attendance, i) => { + return ( + + + + + + + ); + }) + ) : ( + + + + )} + +
DateTimeLocationNote
+ Loading... +
+ {new Date( + attendance?.date + ).toLocaleDateString("en-IN", { + weekday: "short", + month: "short", + day: "numeric", + year: "numeric", + })} + + {attendance?.time || ( + + No Time Added! + + )} + + {attendance?.location || ( + + No Location Added! + + )} + + {attendance?.notes || ( + + No Note Added! + + )} +
+
No Attendance Records Available...
+
+
+ +
+
+
+ Showing {currentPage * itemPerPage - itemPerPage + 1} to{" "} + {Math.min(currentPage * itemPerPage, totalData)} of{" "} + {totalData} entries +
+
+ +
+
+
    +
  • + + setCurrentPage((prev) => + prev > 1 ? prev - 1 : prev + ) + } + > + Previous + +
  • +
  • = totalData + ? "paginate_button page-item next disabled" + : "paginate_button page-item next" + } + > + + setCurrentPage((prev) => + prev * itemPerPage < totalData + ? prev + 1 + : prev + ) + } + > + Next + +
  • +
+
+
+
+
+
+
+
+
+
+
+ ); +}; + +export default SingleAttendanceSalesCoOrdinator; diff --git a/src/views/SalesAttendance/TodayAttendanceSales.js b/src/views/SalesAttendance/TodayAttendanceSales.js new file mode 100644 index 0000000..66243a5 --- /dev/null +++ b/src/views/SalesAttendance/TodayAttendanceSales.js @@ -0,0 +1,274 @@ +import React, { useState, useEffect } 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 { isAutheticated } from "src/auth"; +import swal from "sweetalert"; + +const TodayAttendanceSales = () => { + const token = isAutheticated(); + const navigate = useNavigate(); + const [loading, setLoading] = useState(false); + const [salescoordinatorsData, setSalesCoOrdinatorsData] = useState([]); + const [currentPage, setCurrentPage] = useState(1); + const [itemPerPage, setItemPerPage] = useState(10); + const [totalData, setTotalData] = useState(0); + + const getTodayAttendanceData = async () => { + setLoading(true); + try { + const res = await axios.get(`/api/v1/attendance/today`, { + headers: { + Authorization: `Bearer ${token}`, + }, + params: { + page: currentPage, + show: itemPerPage, + }, + }); + setSalesCoOrdinatorsData(res.data?.attendance); + setTotalData(res.data?.total_data); + } catch (err) { + const msg = err?.response?.data?.message || "Something went wrong!"; + swal({ + title: "Error", + text: msg, + icon: "error", + button: "Retry", + dangerMode: true, + }); + } finally { + setLoading(false); + } + }; + + useEffect(() => { + getTodayAttendanceData(); + }, [itemPerPage, currentPage]); + + const today = new Date().toLocaleDateString("en-IN", { + weekday: "short", + month: "short", + day: "numeric", + year: "numeric", + }); + + return ( +
+
+
+
+
+
+
+ Today's SalesCoOrdinators Attendance +
+ Date : {today} +
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+ +
+ + + + + + + + + + + + + + {loading ? ( + + + + ) : salescoordinatorsData?.length > 0 ? ( + salescoordinatorsData?.map((attendance, i) => { + return ( + + + + + + + + + ); + }) + ) : ( + + + + )} + +
IDNameEmailPositionTimeNote
+ Loading... +
+ {attendance?.user?.id} + + {attendance?.user?.name} + + {attendance?.user?.email ? ( + attendance?.user?.email + ) : ( + + No Email Added! + + )} + + {attendance?.user?.userType || ( + + No Position Added! + + )} + + {attendance?.time || ( + + No Time Added! + + )} + + {attendance?.note ? ( + attendance?.note + ) : ( + + No Note Added! + + )} +
+
No Attendance Records Available...
+
+
+ +
+
+
+ Showing {currentPage * itemPerPage - itemPerPage + 1} to{" "} + {Math.min(currentPage * itemPerPage, totalData)} of{" "} + {totalData} entries +
+
+ +
+
+
    +
  • + + setCurrentPage((prev) => + prev > 1 ? prev - 1 : prev + ) + } + > + Previous + +
  • +
  • = totalData + ? "paginate_button page-item next disabled" + : "paginate_button page-item next" + } + > + + setCurrentPage((prev) => + prev * itemPerPage < totalData + ? prev + 1 + : prev + ) + } + > + Next + +
  • +
+
+
+
+
+
+
+
+
+
+
+ ); +}; + +export default TodayAttendanceSales; diff --git a/src/views/SalesCoOrdinators/SalesCoOrdinator.js b/src/views/SalesCoOrdinators/SalesCoOrdinator.js index 77d57bd..7165301 100644 --- a/src/views/SalesCoOrdinators/SalesCoOrdinator.js +++ b/src/views/SalesCoOrdinators/SalesCoOrdinator.js @@ -1,10 +1,11 @@ -import React, { useState, useEffect, useRef } from "react"; +import React, { useState, useEffect, useRef, useCallback } 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 { isAutheticated } from "src/auth"; import swal from "sweetalert"; +import debounce from 'lodash.debounce'; const SalesCoOrdinator = () => { const token = isAutheticated(); @@ -36,8 +37,6 @@ const SalesCoOrdinator = () => { isVerified: VerifySalesCoOrdinatorRef.current.value, }, }); - // console.log(res.data.salesCoOrinators - // ); setSalesCoOrdinatorsData(res.data?.salesCoOrinators); setTotalData(res.data?.total_data); } catch (err) { @@ -58,6 +57,15 @@ const SalesCoOrdinator = () => { getSalesCoOrdinatorsData(); }, [success, itemPerPage, currentPage]); + const debouncedSearch = useCallback(debounce(() => { + setCurrentPage(1); + getSalesCoOrdinatorsData(); + }, 500), []); + + const handleSearchChange = () => { + debouncedSearch(); + }; + const handleDelete = (id) => { swal({ title: "Are you sure?", @@ -163,6 +171,7 @@ const SalesCoOrdinator = () => { placeholder="SalesCoOrdinator name" className="form-control" ref={nameRef} + onChange={handleSearchChange} disabled={loading} /> @@ -173,6 +182,7 @@ const SalesCoOrdinator = () => { placeholder="Mobile Number" className="form-control" ref={mobileRef} + onChange={handleSearchChange} disabled={loading} /> @@ -181,6 +191,7 @@ const SalesCoOrdinator = () => { -
- -
@@ -271,16 +270,6 @@ const SalesCoOrdinator = () => { })} - {/* - - */} - @@ -290,19 +279,17 @@ const SalesCoOrdinator = () => { marginRight: "1rem", }} type="button" - className="btn btn-info btn-sm waves-effect waves-light btn-table mt-1 mx-1" + className="btn btn-info btn-sm waves-effect waves-light btn-table ml-2" > Edit @@ -311,108 +298,34 @@ const SalesCoOrdinator = () => { ); }) ) : ( - - -
No SalesCoOrdinator Available...
+ + + No SalesCoOrdinator found! )}
- -
-
-
- Showing {currentPage * itemPerPage - itemPerPage + 1} to{" "} - {Math.min(currentPage * itemPerPage, totalData)} of{" "} - {totalData} entries -
+
+
+ Showing {salescoordinatorsData?.length} of {totalData} entries
- -
-
-
    -
  • - setCurrentPage((prev) => prev - 1)} - disabled={loading} - > - Previous - -
  • - - {!(currentPage - 1 < 1) && ( -
  • - - setCurrentPage((prev) => prev - 1) - } - disabled={loading} - > - {currentPage - 1} - -
  • - )} - -
  • - {currentPage} -
  • - - {!( - (currentPage + 1) * itemPerPage - itemPerPage > - totalData - 1 - ) && ( -
  • - - setCurrentPage((prev) => prev + 1) - } - disabled={loading} - > - {currentPage + 1} - -
  • - )} - -
  • - totalData - 1 - ) - ? "paginate_button page-item next" - : "paginate_button page-item next disabled" - } - > - setCurrentPage((prev) => prev + 1)} - disabled={loading} - > - Next - -
  • -
-
+
+ +
diff --git a/src/views/customerDetails/addCustomer.js b/src/views/customerDetails/addCustomer.js deleted file mode 100644 index 025e7ab..0000000 --- a/src/views/customerDetails/addCustomer.js +++ /dev/null @@ -1,441 +0,0 @@ -import React, { useState } from "react"; -import { - TextField, - Button, - Card, - FormControl, - Grid, - FormHelperText, - OutlinedInput, - Box, -} from "@mui/material"; -import { useNavigate } from "react-router-dom"; -import toast from "react-hot-toast"; -import axios from "axios"; // Import axios for making HTTP requests -import { isAutheticated } from "src/auth"; -const styles = { - formStyle: { - fontWeight: "700", - fontSize: "12px", - fontFamily: "inter", - marginBottom: "3px", - marginLeft: "0", - }, -}; -const AddCustomer = () => { - const navigate = useNavigate(); - const [user, setUser] = useState({ - name: "", - email: "", - password: "", // No need to initialize password here - }); - const [id, setUserId] = useState(""); - const token = isAutheticated(); - - const [loading, setLoading] = useState(false); - const [data, setData] = useState({ - first_Name: "", - last_Name: "", - phone_Number: Number, - street: "", - city: "", - state: "", - postalCode: "", - country: "", - company_name: "", - gst_number: Number, - }); - - // console.log(data); - const handleChange = (e) => { - setData((prev) => ({ ...prev, [e.target.name]: e.target.value })); - }; - - const handerInputChanges = (e) => { - setUser({ ...user, [e.target.name]: e.target.value }); - }; - function handleAddressSubmit(e) { - e.preventDefault(); - if ( - data.first_Name === "" || - data.last_Name === "" || - data.phone_Number === null || - data.street === "" || - data.city === "" || - data.state === "" || - data.postalCode === "" || - data.country === "" - ) { - swal({ - title: "Warning", - text: "Please fill All mendetory fields ", - icon: "warning", - button: "ok", - dangerMode: true, - }); - return; - } - setLoading(true); - axios - .post( - `/api/shipping/address/admin/new/${id}`, - { - ...data, - }, - - { - headers: { - "Access-Control-Allow-Origin": "*", - Authorization: `Bearer ${token}`, - }, - } - ) - .then((res) => { - setLoading(false); - // setSuccess((prev) => !prev); - navigate("/customers-details"); - toast.success(res.data.message ? res.data.message : "Address Added!"); - }) - .catch((error) => { - setLoading(false); - toast.error( - error.response.data.message - ? error.response.data.message - : "Something went wrong!" - ); - }); - } - - // Generate password function - 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 filteredChars = combinedStr.match(/[^\W_]/g); // Filter out non-alphanumeric characters - let passwordChars = alphaChars.concat(filteredChars); // Combine alphabetic and filtered characters - - // Insert a random special character at a random position in the password characters array - const specialChar = specialChars.charAt( - Math.floor(Math.random() * specialChars.length) - ); // Pick a random special character - const randomIndex = Math.floor(Math.random() * (passwordChars.length + 1)); // Pick a random position to insert the special character - passwordChars.splice(randomIndex, 0, specialChar); // Insert the special character at the random position - - passwordChars = passwordChars.sort(() => Math.random() - 0.5); // Shuffle the characters - const password = passwordChars.join("").slice(0, 8); // Take the first 8 characters - return password; - }; - const handleFormSubmit = async (e) => { - e.preventDefault(); - try { - if (!user.name || !user.email) { - throw new Error("Fill all fields!"); - } - - // Generate password based on name and email - const generatedPassword = generatePassword(user.name, user.email); - console.log(generatedPassword); // Use generatedPassword instead of generatePassword - setUser({ ...user, password: generatedPassword }); // Set generated password to user state - - const response = await axios.post("/api/v1/user/register", { - ...user, // Send user details - password: generatedPassword, // Send generated password to the backend - }); - if (response.status === 201) { - toast.success("User Added Successful"); - setUserId(response.data.userId); - } - } catch (error) { - console.log(error.response.data.message); - toast.error(error.response.data.message); - } - }; - - console.log(user); - console.log("this is the id ", id); - - return ( -
- -
- -
- -
- - -
- - -
- - - - - - - FIRST NAME* - - handleChange(e)} - - // value={accountDetails.firstname} - // onChange={handerInputChanges} - /> - - - - - - LAST NAME* - - handleChange(e)} - // value={accountDetails.firstname} - // onChange={handerInputChanges} - /> - - - - - - PHONE NUMBER* - - handleChange(e)} - // value={accountDetails.firstname} - // onChange={handerInputChanges} - /> - - - - - - STREET ADDRESS* - - handleChange(e)} - // value={accountDetails.firstname} - // onChange={handerInputChanges} - /> - - - - - - - - COUNTRY* - - handleChange(e)} - // value={accountDetails.firstname} - // onChange={handerInputChanges} - /> - - - - - - TOWN CITY* - - handleChange(e)} - // value={accountDetails.firstname} - // onChange={handerInputChanges} - /> - - - - - - - - STATE* - - handleChange(e)} - // value={accountDetails.firstname} - // onChange={handerInputChanges} - /> - - - - - - - ZIP CODE* - - handleChange(e)} - // value={accountDetails.firstname} - // onChange={handerInputChanges} - /> - - - - - - Company Name - - handleChange(e)} - - // value={accountDetails.firstname} - // onChange={handerInputChanges} - /> - - - - - - GST Number - - handleChange(e)} - - // value={accountDetails.firstname} - // onChange={handerInputChanges} - /> - - - - - - - - -
-
-
- ); -}; - -export default AddCustomer;