update
This commit is contained in:
parent
ec1979d7f7
commit
8f587978cb
@ -88,7 +88,14 @@ const _nav = [
|
|||||||
name: "Attendance",
|
name: "Attendance",
|
||||||
icon: <CIcon icon={cilUser} customClassName="nav-icon" />,
|
icon: <CIcon icon={cilUser} customClassName="nav-icon" />,
|
||||||
to: "/attendance/today",
|
to: "/attendance/today",
|
||||||
group: "AttendanceSalesCoOrdinator",
|
group: "Attendance",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
component: CNavItem,
|
||||||
|
name: "Leaves",
|
||||||
|
icon: <CIcon icon={cilUser} customClassName="nav-icon" />,
|
||||||
|
to: "/leaves/today",
|
||||||
|
group: "Leaves",
|
||||||
},
|
},
|
||||||
// {
|
// {
|
||||||
// component: CNavGroup,
|
// component: CNavGroup,
|
||||||
|
@ -15,8 +15,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://cheminova-api-2.onrender.com";
|
// axios.defaults.baseURL = "https://cheminova-api-2.onrender.com";
|
||||||
|
|
||||||
axios.defaults.headers = {
|
axios.defaults.headers = {
|
||||||
"Cache-Control": "no-cache,no-store",
|
"Cache-Control": "no-cache,no-store",
|
||||||
|
@ -127,9 +127,12 @@ import Currency from "./views/configuration/Currency";
|
|||||||
import SalesCoOrdinator from "./views/SalesCoOrdinators/SalesCoOrdinator";
|
import SalesCoOrdinator from "./views/SalesCoOrdinators/SalesCoOrdinator";
|
||||||
import EditSalesCoOrdinator from "./views/SalesCoOrdinators/EditSalesCoOrdinator";
|
import EditSalesCoOrdinator from "./views/SalesCoOrdinators/EditSalesCoOrdinator";
|
||||||
import AddSalesCoOrdinator from "./views/SalesCoOrdinators/AddSalesCoOrdinator";
|
import AddSalesCoOrdinator from "./views/SalesCoOrdinators/AddSalesCoOrdinator";
|
||||||
import TodayAttendanceSales from "./views/SalesAttendance/TodayAttendanceSales";
|
import TodayAttendance from "./views/Attendance/TodayAttendance";
|
||||||
import AttendanceSalesCoordinator from "./views/SalesAttendance/AttendanceSalesCoordinator";
|
import AttendanceSalesCoordinator from "./views/Attendance/AttendanceSalesCoordinator";
|
||||||
import SingleAttendanceSalesCoOrdinator from "./views/SalesAttendance/SingleAttendanceSalesCoordinator";
|
import SingleAttendanceSalesCoOrdinator from "./views/Attendance/SingleAttendanceSalesCoordinator";
|
||||||
|
import TodayLeave from "./views/Leaves/TodayLeaves";
|
||||||
|
import LeaveSalesCoordinator from "./views/Leaves/LeaveSalesCoordinator";
|
||||||
|
import SingleLeaveSalesCoOrdinator from "./views/Leaves/SingleLeaveSalesCoordinator";
|
||||||
const routes = [
|
const routes = [
|
||||||
//dashboard
|
//dashboard
|
||||||
|
|
||||||
@ -197,12 +200,12 @@ const routes = [
|
|||||||
element: AddSalesCoOrdinator,
|
element: AddSalesCoOrdinator,
|
||||||
navName: "SalesCoOrdinators",
|
navName: "SalesCoOrdinators",
|
||||||
},
|
},
|
||||||
// Attendence SalesCoOrdinator
|
// Attendence
|
||||||
{
|
{
|
||||||
path: "/attendance/today",
|
path: "/attendance/today",
|
||||||
name: "Today's Attendance SalesCoOrdinator",
|
name: "Today's Attendance",
|
||||||
element: TodayAttendanceSales,
|
element: TodayAttendance,
|
||||||
navName: "AttendanceSalesCoOrdinator",
|
navName: "Attendance",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "/salescoordinator/attendance",
|
path: "/salescoordinator/attendance",
|
||||||
@ -216,6 +219,25 @@ const routes = [
|
|||||||
element: SingleAttendanceSalesCoOrdinator,
|
element: SingleAttendanceSalesCoOrdinator,
|
||||||
navName: "AttendanceSalesCoOrdinator",
|
navName: "AttendanceSalesCoOrdinator",
|
||||||
},
|
},
|
||||||
|
// Leaves
|
||||||
|
{
|
||||||
|
path: "/leaves/today",
|
||||||
|
name: "Today's leaves",
|
||||||
|
element: TodayLeave,
|
||||||
|
navName: "Leaves",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/salescoordinator/leave",
|
||||||
|
name: "Leave SalesCoOrdinator",
|
||||||
|
element: LeaveSalesCoordinator,
|
||||||
|
navName: "LeaveSalesCoOrdinator",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/leave/view/:id",
|
||||||
|
name: "Single SalesCoOrdinator Leave",
|
||||||
|
element: SingleLeaveSalesCoOrdinator,
|
||||||
|
navName: "LeaveSalesCoOrdinator",
|
||||||
|
},
|
||||||
//Gst tax
|
//Gst tax
|
||||||
{
|
{
|
||||||
path: "/tax",
|
path: "/tax",
|
||||||
|
@ -6,7 +6,7 @@ import { useNavigate } from "react-router-dom";
|
|||||||
import { isAutheticated } from "src/auth";
|
import { isAutheticated } from "src/auth";
|
||||||
import swal from "sweetalert";
|
import swal from "sweetalert";
|
||||||
|
|
||||||
const TodayAttendanceSales = () => {
|
const TodayAttendance = () => {
|
||||||
const token = isAutheticated();
|
const token = isAutheticated();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
@ -151,7 +151,7 @@ const TodayAttendanceSales = () => {
|
|||||||
return (
|
return (
|
||||||
<tr key={i}>
|
<tr key={i}>
|
||||||
<td className="text-start">
|
<td className="text-start">
|
||||||
{attendance?.user?.id}
|
{attendance?.user?.uniqueId}
|
||||||
</td>
|
</td>
|
||||||
<td className="text-start">
|
<td className="text-start">
|
||||||
{attendance?.user?.name}
|
{attendance?.user?.name}
|
||||||
@ -180,8 +180,8 @@ const TodayAttendanceSales = () => {
|
|||||||
)}
|
)}
|
||||||
</td>
|
</td>
|
||||||
<td className="text-start">
|
<td className="text-start">
|
||||||
{attendance?.note ? (
|
{attendance?.notes ? (
|
||||||
attendance?.note
|
attendance?.notes
|
||||||
) : (
|
) : (
|
||||||
<small className="m-0 text-secondary">
|
<small className="m-0 text-secondary">
|
||||||
No Note Added!
|
No Note Added!
|
||||||
@ -271,4 +271,4 @@ const TodayAttendanceSales = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default TodayAttendanceSales;
|
export default TodayAttendance;
|
319
src/views/Leaves/LeaveSalesCoordinator.js
Normal file
319
src/views/Leaves/LeaveSalesCoordinator.js
Normal file
@ -0,0 +1,319 @@
|
|||||||
|
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 { isAutheticated } from "src/auth";
|
||||||
|
import swal from "sweetalert";
|
||||||
|
|
||||||
|
const LeaveSalesCoordinator = () => {
|
||||||
|
const token = isAutheticated();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [salescoordinatorsData, setSalesCoOrdinatorsData] = useState([]);
|
||||||
|
const nameRef = useRef();
|
||||||
|
const mobileRef = useRef();
|
||||||
|
const verifyRef = useRef();
|
||||||
|
const [currentPage, setCurrentPage] = useState(1);
|
||||||
|
const [itemPerPage, setItemPerPage] = useState(10);
|
||||||
|
const [totalData, setTotalData] = useState(0);
|
||||||
|
|
||||||
|
const getSalesCoOrdinatorsData = async () => {
|
||||||
|
setLoading(true);
|
||||||
|
try {
|
||||||
|
const res = await axios.get(`/api/salescoordinator/getAll/`, {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
},
|
||||||
|
params: {
|
||||||
|
page: currentPage,
|
||||||
|
show: itemPerPage,
|
||||||
|
name: nameRef.current.value,
|
||||||
|
mobileNumber: mobileRef.current.value,
|
||||||
|
isVerified: verifyRef.current.value,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
setSalesCoOrdinatorsData(res.data?.salesCoOrinators);
|
||||||
|
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(() => {
|
||||||
|
getSalesCoOrdinatorsData();
|
||||||
|
}, [currentPage, itemPerPage]);
|
||||||
|
|
||||||
|
const handleFilter = () => {
|
||||||
|
setCurrentPage(1);
|
||||||
|
getSalesCoOrdinatorsData();
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="main-content">
|
||||||
|
<div className="page-content">
|
||||||
|
<div className="container-fluid">
|
||||||
|
<div className="row">
|
||||||
|
<div className="col-12">
|
||||||
|
<div className="page-title-box d-flex align-items-center justify-content-between">
|
||||||
|
<div style={{ fontSize: "22px" }} className="fw-bold">
|
||||||
|
Sales Coordinators Leaves
|
||||||
|
</div>
|
||||||
|
<div className="page-title-right">
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
color="secondary"
|
||||||
|
style={{
|
||||||
|
fontWeight: "bold",
|
||||||
|
marginBottom: "1rem",
|
||||||
|
textTransform: "capitalize",
|
||||||
|
}}
|
||||||
|
onClick={() => {
|
||||||
|
navigate("/leaves/today", { replace: true });
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="row">
|
||||||
|
<div className="col-lg-12">
|
||||||
|
<div className="card">
|
||||||
|
<div className="card-body">
|
||||||
|
<div className="row ml-0 mr-0 mb-10">
|
||||||
|
<div className="col-lg-1">
|
||||||
|
<div className="dataTables_length">
|
||||||
|
<label className="w-100">
|
||||||
|
Show
|
||||||
|
<select
|
||||||
|
onChange={(e) => {
|
||||||
|
setItemPerPage(Number(e.target.value));
|
||||||
|
setCurrentPage(1);
|
||||||
|
}}
|
||||||
|
className="form-control"
|
||||||
|
disabled={loading}
|
||||||
|
>
|
||||||
|
<option value="10">10</option>
|
||||||
|
<option value="25">25</option>
|
||||||
|
<option value="50">50</option>
|
||||||
|
<option value="100">100</option>
|
||||||
|
</select>
|
||||||
|
entries
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="col-lg-3">
|
||||||
|
<label>Sales Coordinator Name:</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
placeholder="Sales Coordinator name"
|
||||||
|
className="form-control"
|
||||||
|
ref={nameRef}
|
||||||
|
disabled={loading}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="col-lg-3">
|
||||||
|
<label>Mobile Number:</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
placeholder="Mobile Number"
|
||||||
|
className="form-control"
|
||||||
|
ref={mobileRef}
|
||||||
|
disabled={loading}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="col-lg-3">
|
||||||
|
<label>Verify Sales Coordinator:</label>
|
||||||
|
<select
|
||||||
|
className="form-control"
|
||||||
|
ref={verifyRef}
|
||||||
|
disabled={loading}
|
||||||
|
>
|
||||||
|
<option value="">----Select----</option>
|
||||||
|
<option value="true">YES</option>
|
||||||
|
<option value="false">NO</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div className="col-lg-2">
|
||||||
|
<button
|
||||||
|
className="btn btn-primary ms-1 mt-4"
|
||||||
|
onClick={handleFilter}
|
||||||
|
disabled={loading}
|
||||||
|
>
|
||||||
|
{loading ? "Searching.." : "Filter"}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="table-responsive table-shoot mt-3">
|
||||||
|
<table className="table table-centered table-nowrap">
|
||||||
|
<thead
|
||||||
|
className="thead-light"
|
||||||
|
style={{ background: "#ecdddd" }}
|
||||||
|
>
|
||||||
|
<tr>
|
||||||
|
<th className="text-start">Name</th>
|
||||||
|
<th className="text-start">Mobile No.</th>
|
||||||
|
<th className="text-start">Email</th>
|
||||||
|
<th className="text-start">Verify</th>
|
||||||
|
<th className="text-start">Register On</th>
|
||||||
|
<th className="text-start">Action</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
|
||||||
|
<tbody>
|
||||||
|
{loading ? (
|
||||||
|
<tr>
|
||||||
|
<td className="text-center" colSpan="6">
|
||||||
|
Loading...
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
) : salescoordinatorsData.length > 0 ? (
|
||||||
|
salescoordinatorsData.map((salescoordinator, i) => (
|
||||||
|
<tr key={i}>
|
||||||
|
<td className="text-start">
|
||||||
|
{salescoordinator?.name}
|
||||||
|
</td>
|
||||||
|
<td className="text-start">
|
||||||
|
{salescoordinator?.mobileNumber}
|
||||||
|
</td>
|
||||||
|
<td className="text-start">
|
||||||
|
{salescoordinator?.email || (
|
||||||
|
<small className="m-0 text-secondary">
|
||||||
|
No Email Added!
|
||||||
|
</small>
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
<td className="text-start">
|
||||||
|
<span
|
||||||
|
className={`badge text-white ${
|
||||||
|
salescoordinator?.isVerified
|
||||||
|
? "text-bg-success"
|
||||||
|
: "text-bg-danger"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{salescoordinator?.isVerified ? "YES" : "NO"}
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
<td className="text-start">
|
||||||
|
{new Date(
|
||||||
|
salescoordinator.createdAt
|
||||||
|
).toLocaleString("en-IN", {
|
||||||
|
weekday: "short",
|
||||||
|
month: "short",
|
||||||
|
day: "numeric",
|
||||||
|
year: "numeric",
|
||||||
|
hour: "numeric",
|
||||||
|
minute: "numeric",
|
||||||
|
hour12: true,
|
||||||
|
})}
|
||||||
|
</td>
|
||||||
|
<td className="text-start">
|
||||||
|
<Link to={`/leave/view/${salescoordinator._id}`}>
|
||||||
|
<button
|
||||||
|
style={{
|
||||||
|
color: "white",
|
||||||
|
marginRight: "1rem",
|
||||||
|
}}
|
||||||
|
type="button"
|
||||||
|
className="btn btn-primary btn-sm waves-effect waves-light btn-table mt-1 mx-1"
|
||||||
|
>
|
||||||
|
View Leaves
|
||||||
|
</button>
|
||||||
|
</Link>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<tr className="text-center">
|
||||||
|
<td colSpan="6">
|
||||||
|
<h5>No Sales Coordinators Available...</h5>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
)}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="row mt-20">
|
||||||
|
<div className="col-sm-12 col-md-6 mb-20">
|
||||||
|
<div
|
||||||
|
className="dataTables_info"
|
||||||
|
id="datatable_info"
|
||||||
|
role="status"
|
||||||
|
aria-live="polite"
|
||||||
|
>
|
||||||
|
Showing {currentPage * itemPerPage - itemPerPage + 1} to{" "}
|
||||||
|
{Math.min(currentPage * itemPerPage, totalData)} of{" "}
|
||||||
|
{totalData} entries
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="col-sm-12 col-md-6">
|
||||||
|
<div className="d-flex">
|
||||||
|
<ul className="pagination ms-auto">
|
||||||
|
<li
|
||||||
|
className={
|
||||||
|
currentPage === 1
|
||||||
|
? "paginate_button page-item previous disabled"
|
||||||
|
: "paginate_button page-item previous"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
className="page-link"
|
||||||
|
onClick={() =>
|
||||||
|
setCurrentPage((prev) =>
|
||||||
|
prev > 1 ? prev - 1 : prev
|
||||||
|
)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Previous
|
||||||
|
</span>
|
||||||
|
</li>
|
||||||
|
<li
|
||||||
|
className={
|
||||||
|
currentPage * itemPerPage >= totalData
|
||||||
|
? "paginate_button page-item next disabled"
|
||||||
|
: "paginate_button page-item next"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
className="page-link"
|
||||||
|
onClick={() =>
|
||||||
|
setCurrentPage((prev) =>
|
||||||
|
prev * itemPerPage < totalData
|
||||||
|
? prev + 1
|
||||||
|
: prev
|
||||||
|
)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Next
|
||||||
|
</span>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default LeaveSalesCoordinator;
|
262
src/views/Leaves/SingleLeaveSalesCoordinator.js
Normal file
262
src/views/Leaves/SingleLeaveSalesCoordinator.js
Normal file
@ -0,0 +1,262 @@
|
|||||||
|
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 SingleLeaveSalesCoOrdinator = () => {
|
||||||
|
const { id } = useParams();
|
||||||
|
const token = isAutheticated();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [salesCoordinator, setSalesCoordinator] = useState({});
|
||||||
|
const [leaveData, setLeaveData] = useState([]);
|
||||||
|
const [currentPage, setCurrentPage] = useState(1);
|
||||||
|
const [itemPerPage, setItemPerPage] = useState(10);
|
||||||
|
const [totalData, setTotalData] = useState(0);
|
||||||
|
|
||||||
|
const getSingleSalesCoOrdinatorLeave = async () => {
|
||||||
|
setLoading(true);
|
||||||
|
try {
|
||||||
|
const res = await axios.get(`/api/v1/leave/${id}`, {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
},
|
||||||
|
params: {
|
||||||
|
page: currentPage,
|
||||||
|
show: itemPerPage,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
// console.log(res.data);
|
||||||
|
setSalesCoordinator(res.data?.user);
|
||||||
|
setLeaveData(res.data?.leave);
|
||||||
|
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(() => {
|
||||||
|
getSingleSalesCoOrdinatorLeave();
|
||||||
|
}, [itemPerPage, currentPage]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="main-content">
|
||||||
|
<div className="page-content">
|
||||||
|
<div className="container-fluid">
|
||||||
|
<div className="row">
|
||||||
|
<div className="col-12">
|
||||||
|
<div className="page-title-box d-flex align-items-center justify-content-between">
|
||||||
|
<div style={{ fontSize: "22px" }} className="fw-bold">
|
||||||
|
SalesCoOrdinator Leave
|
||||||
|
<div style={{ fontSize: "16px", marginTop: "5px" }}>
|
||||||
|
{salesCoordinator.name} ({salesCoordinator.email})
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="page-title-right">
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
color="primary"
|
||||||
|
style={{
|
||||||
|
fontWeight: "bold",
|
||||||
|
marginBottom: "1rem",
|
||||||
|
textTransform: "capitalize",
|
||||||
|
}}
|
||||||
|
onClick={() => {
|
||||||
|
navigate("/salescoordinator/leave", {
|
||||||
|
replace: true,
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="row">
|
||||||
|
<div className="col-lg-12">
|
||||||
|
<div className="card">
|
||||||
|
<div className="card-body">
|
||||||
|
<div className="row ml-0 mr-0 mb-10">
|
||||||
|
<div className="col-lg-1">
|
||||||
|
<div className="dataTables_length">
|
||||||
|
<label className="w-100">
|
||||||
|
Show
|
||||||
|
<select
|
||||||
|
onChange={(e) => {
|
||||||
|
setItemPerPage(Number(e.target.value));
|
||||||
|
setCurrentPage(1);
|
||||||
|
}}
|
||||||
|
className="form-control"
|
||||||
|
disabled={loading}
|
||||||
|
>
|
||||||
|
<option value="10">10</option>
|
||||||
|
<option value="25">25</option>
|
||||||
|
<option value="50">50</option>
|
||||||
|
<option value="100">100</option>
|
||||||
|
</select>
|
||||||
|
entries
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="table-responsive table-shoot mt-3">
|
||||||
|
<table className="table table-centered table-nowrap">
|
||||||
|
<thead
|
||||||
|
className="thead-light"
|
||||||
|
style={{ background: "#ecdddd" }}
|
||||||
|
>
|
||||||
|
<tr>
|
||||||
|
<th className="text-start">Date</th>
|
||||||
|
<th className="text-start">Time</th>
|
||||||
|
<th className="text-start">Location</th>
|
||||||
|
<th className="text-start">Reason Type</th>
|
||||||
|
<th className="text-start">Reason</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
|
||||||
|
<tbody>
|
||||||
|
{loading ? (
|
||||||
|
<tr>
|
||||||
|
<td className="text-center" colSpan="5">
|
||||||
|
Loading...
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
) : leaveData?.length > 0 ? (
|
||||||
|
leaveData?.map((leave, i) => (
|
||||||
|
<tr key={i}>
|
||||||
|
<td className="text-start">
|
||||||
|
{new Date(leave?.date).toLocaleDateString(
|
||||||
|
"en-IN",
|
||||||
|
{
|
||||||
|
weekday: "short",
|
||||||
|
month: "short",
|
||||||
|
day: "numeric",
|
||||||
|
year: "numeric",
|
||||||
|
}
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
<td className="text-start">
|
||||||
|
{leave?.time || (
|
||||||
|
<small className="m-0 text-secondary">
|
||||||
|
No Time Added!
|
||||||
|
</small>
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
<td className="text-start">
|
||||||
|
{leave?.location || (
|
||||||
|
<small className="m-0 text-secondary">
|
||||||
|
No Location Added!
|
||||||
|
</small>
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
<td className="text-start">
|
||||||
|
{leave?.leaveType || (
|
||||||
|
<small className="m-0 text-secondary">
|
||||||
|
No Reason Type Added!
|
||||||
|
</small>
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
<td className="text-start">
|
||||||
|
{leave?.reason || (
|
||||||
|
<small className="m-0 text-secondary">
|
||||||
|
No Reason Added!
|
||||||
|
</small>
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<tr className="text-center">
|
||||||
|
<td colSpan="5">
|
||||||
|
<h5>No Leave Records Available...</h5>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
)}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="row mt-20">
|
||||||
|
<div className="col-sm-12 col-md-6 mb-20">
|
||||||
|
<div
|
||||||
|
className="dataTables_info"
|
||||||
|
id="datatable_info"
|
||||||
|
role="status"
|
||||||
|
aria-live="polite"
|
||||||
|
>
|
||||||
|
Showing {currentPage * itemPerPage - itemPerPage + 1} to{" "}
|
||||||
|
{Math.min(currentPage * itemPerPage, totalData)} of{" "}
|
||||||
|
{totalData} entries
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="col-sm-12 col-md-6">
|
||||||
|
<div className="d-flex">
|
||||||
|
<ul className="pagination ms-auto">
|
||||||
|
<li
|
||||||
|
className={
|
||||||
|
currentPage === 1
|
||||||
|
? "paginate_button page-item previous disabled"
|
||||||
|
: "paginate_button page-item previous"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
className="page-link"
|
||||||
|
onClick={() =>
|
||||||
|
setCurrentPage((prev) =>
|
||||||
|
prev > 1 ? prev - 1 : prev
|
||||||
|
)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Previous
|
||||||
|
</span>
|
||||||
|
</li>
|
||||||
|
<li
|
||||||
|
className={
|
||||||
|
currentPage * itemPerPage >= totalData
|
||||||
|
? "paginate_button page-item next disabled"
|
||||||
|
: "paginate_button page-item next"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
className="page-link"
|
||||||
|
onClick={() =>
|
||||||
|
setCurrentPage((prev) =>
|
||||||
|
prev * itemPerPage < totalData
|
||||||
|
? prev + 1
|
||||||
|
: prev
|
||||||
|
)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Next
|
||||||
|
</span>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SingleLeaveSalesCoOrdinator;
|
283
src/views/Leaves/TodayLeaves.js
Normal file
283
src/views/Leaves/TodayLeaves.js
Normal file
@ -0,0 +1,283 @@
|
|||||||
|
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 TodayLeave = () => {
|
||||||
|
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 getTodayLeaveData = async () => {
|
||||||
|
setLoading(true);
|
||||||
|
try {
|
||||||
|
const res = await axios.get(`/api/v1/leave/today`, {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
},
|
||||||
|
params: {
|
||||||
|
page: currentPage,
|
||||||
|
show: itemPerPage,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
console.log(res.data);
|
||||||
|
setSalesCoOrdinatorsData(res.data?.leave);
|
||||||
|
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(() => {
|
||||||
|
getTodayLeaveData();
|
||||||
|
}, [itemPerPage, currentPage]);
|
||||||
|
|
||||||
|
const today = new Date().toLocaleDateString("en-IN", {
|
||||||
|
weekday: "short",
|
||||||
|
month: "short",
|
||||||
|
day: "numeric",
|
||||||
|
year: "numeric",
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="main-content">
|
||||||
|
<div className="page-content">
|
||||||
|
<div className="container-fluid">
|
||||||
|
<div className="row">
|
||||||
|
<div className="col-12">
|
||||||
|
<div className="page-title-box d-flex align-items-center justify-content-between">
|
||||||
|
<div style={{ fontSize: "22px" }} className="fw-bold">
|
||||||
|
Today's SalesCoOrdinators Leave
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
fontSize: "20px",
|
||||||
|
marginTop: "5px",
|
||||||
|
marginBottom: "3px",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Date : {today}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="page-title-right">
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
color="primary"
|
||||||
|
style={{
|
||||||
|
fontWeight: "bold",
|
||||||
|
marginBottom: "1rem",
|
||||||
|
textTransform: "capitalize",
|
||||||
|
}}
|
||||||
|
onClick={() => {
|
||||||
|
navigate("/salescoordinator/leave", {
|
||||||
|
replace: true,
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Show SalesCoOrdinator Leave
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="row">
|
||||||
|
<div className="col-lg-12">
|
||||||
|
<div className="card">
|
||||||
|
<div className="card-body">
|
||||||
|
<div className="row ml-0 mr-0 mb-10">
|
||||||
|
<div className="col-lg-1">
|
||||||
|
<div className="dataTables_length">
|
||||||
|
<label className="w-100">
|
||||||
|
Show
|
||||||
|
<select
|
||||||
|
onChange={(e) => {
|
||||||
|
setItemPerPage(e.target.value);
|
||||||
|
setCurrentPage(1);
|
||||||
|
}}
|
||||||
|
className="form-control"
|
||||||
|
disabled={loading}
|
||||||
|
>
|
||||||
|
<option value="10">10</option>
|
||||||
|
<option value="25">25</option>
|
||||||
|
<option value="50">50</option>
|
||||||
|
<option value="100">100</option>
|
||||||
|
</select>
|
||||||
|
entries
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="table-responsive table-shoot mt-3">
|
||||||
|
<table className="table table-centered table-nowrap">
|
||||||
|
<thead
|
||||||
|
className="thead-light"
|
||||||
|
style={{ background: "#ecdddd" }}
|
||||||
|
>
|
||||||
|
<tr>
|
||||||
|
<th className="text-start">ID</th>
|
||||||
|
<th className="text-start">Name</th>
|
||||||
|
<th className="text-start">Email</th>
|
||||||
|
<th className="text-start">Position</th>
|
||||||
|
<th className="text-start">Time</th>
|
||||||
|
<th className="text-start">ReasonType</th>
|
||||||
|
<th className="text-start">Reason</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
|
||||||
|
<tbody>
|
||||||
|
{loading ? (
|
||||||
|
<tr>
|
||||||
|
<td className="text-center" colSpan="7">
|
||||||
|
Loading...
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
) : salescoordinatorsData?.length > 0 ? (
|
||||||
|
salescoordinatorsData?.map((leave, i) => {
|
||||||
|
return (
|
||||||
|
<tr key={i}>
|
||||||
|
<td className="text-start">
|
||||||
|
{leave?.user?.uniqueId}
|
||||||
|
</td>
|
||||||
|
<td className="text-start">
|
||||||
|
{leave?.user?.name}
|
||||||
|
</td>
|
||||||
|
<td className="text-start">
|
||||||
|
{leave?.user?.email ? (
|
||||||
|
leave?.user?.email
|
||||||
|
) : (
|
||||||
|
<small className="m-0 text-secondary">
|
||||||
|
No Email Added!
|
||||||
|
</small>
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
<td className="text-start">
|
||||||
|
{leave?.user?.userType || (
|
||||||
|
<small className="m-0 text-secondary">
|
||||||
|
No Position Added!
|
||||||
|
</small>
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
<td className="text-start">
|
||||||
|
{leave?.time || (
|
||||||
|
<small className="m-0 text-secondary">
|
||||||
|
No Time Added!
|
||||||
|
</small>
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
<td className="text-start">
|
||||||
|
{leave?.leaveType || (
|
||||||
|
<small className="m-0 text-secondary">
|
||||||
|
No Reason Type Added!
|
||||||
|
</small>
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
<td className="text-start">
|
||||||
|
{leave?.reason ? (
|
||||||
|
leave?.reason
|
||||||
|
) : (
|
||||||
|
<small className="m-0 text-secondary">
|
||||||
|
No Reason Added!
|
||||||
|
</small>
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
);
|
||||||
|
})
|
||||||
|
) : (
|
||||||
|
<tr className="text-center">
|
||||||
|
<td colSpan="7">
|
||||||
|
<h5>No Leave Records Available...</h5>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
)}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="row mt-20">
|
||||||
|
<div className="col-sm-12 col-md-6 mb-20">
|
||||||
|
<div
|
||||||
|
className="dataTables_info"
|
||||||
|
id="datatable_info"
|
||||||
|
role="status"
|
||||||
|
aria-live="polite"
|
||||||
|
>
|
||||||
|
Showing {currentPage * itemPerPage - itemPerPage + 1} to{" "}
|
||||||
|
{Math.min(currentPage * itemPerPage, totalData)} of{" "}
|
||||||
|
{totalData} entries
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="col-sm-12 col-md-6">
|
||||||
|
<div className="d-flex">
|
||||||
|
<ul className="pagination ms-auto">
|
||||||
|
<li
|
||||||
|
className={
|
||||||
|
currentPage === 1
|
||||||
|
? "paginate_button page-item previous disabled"
|
||||||
|
: "paginate_button page-item previous"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
className="page-link"
|
||||||
|
onClick={() =>
|
||||||
|
setCurrentPage((prev) =>
|
||||||
|
prev > 1 ? prev - 1 : prev
|
||||||
|
)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Previous
|
||||||
|
</span>
|
||||||
|
</li>
|
||||||
|
<li
|
||||||
|
className={
|
||||||
|
currentPage * itemPerPage >= totalData
|
||||||
|
? "paginate_button page-item next disabled"
|
||||||
|
: "paginate_button page-item next"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
className="page-link"
|
||||||
|
onClick={() =>
|
||||||
|
setCurrentPage((prev) =>
|
||||||
|
prev * itemPerPage < totalData
|
||||||
|
? prev + 1
|
||||||
|
: prev
|
||||||
|
)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Next
|
||||||
|
</span>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default TodayLeave;
|
@ -85,26 +85,43 @@ const AddPrincipalDistributor = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const generatePassword = (name, email) => {
|
const generatePassword = (name, email) => {
|
||||||
|
// Combine name and email, and convert to lowercase
|
||||||
const combinedStr = (name + email).toLowerCase();
|
const combinedStr = (name + email).toLowerCase();
|
||||||
|
|
||||||
|
// Define character pools
|
||||||
const specialChars = "@#*";
|
const specialChars = "@#*";
|
||||||
const alphaChars = combinedStr.match(/[a-zA-Z]/g);
|
const numbers = "0123456789";
|
||||||
const filteredChars = combinedStr.match(/[^\W_]/g);
|
const alphaLower = combinedStr.match(/[a-z]/g) || [];
|
||||||
let passwordChars = alphaChars.concat(filteredChars);
|
const alphaUpper = combinedStr.match(/[A-Z]/g) || [];
|
||||||
|
|
||||||
const specialChar = specialChars.charAt(
|
// Ensure at least one character from each category
|
||||||
Math.floor(Math.random() * specialChars.length)
|
const specialChar = specialChars.charAt(Math.floor(Math.random() * specialChars.length));
|
||||||
);
|
const numberChar = numbers.charAt(Math.floor(Math.random() * numbers.length));
|
||||||
const randomIndex = Math.floor(Math.random() * (passwordChars.length + 1));
|
const lowerChar = alphaLower.length > 0 ? alphaLower[Math.floor(Math.random() * alphaLower.length)] : String.fromCharCode(Math.floor(Math.random() * 26) + 97);
|
||||||
passwordChars.splice(randomIndex, 0, specialChar);
|
const upperChar = alphaUpper.length > 0 ? alphaUpper[Math.floor(Math.random() * alphaUpper.length)] : String.fromCharCode(Math.floor(Math.random() * 26) + 65);
|
||||||
|
|
||||||
|
// Combine required characters
|
||||||
|
let passwordChars = [specialChar, numberChar, lowerChar, upperChar];
|
||||||
|
|
||||||
|
// Fill remaining positions with random characters from the combined string
|
||||||
|
const allChars = combinedStr + specialChars + numbers;
|
||||||
|
while (passwordChars.length < 8) {
|
||||||
|
passwordChars.push(allChars.charAt(Math.floor(Math.random() * allChars.length)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Shuffle characters to ensure randomness
|
||||||
passwordChars = passwordChars.sort(() => Math.random() - 0.5);
|
passwordChars = passwordChars.sort(() => Math.random() - 0.5);
|
||||||
const password = passwordChars.join("").slice(0, 8);
|
|
||||||
|
// Generate password of length 8
|
||||||
|
const password = passwordChars.slice(0, 8).join("");
|
||||||
|
|
||||||
return password;
|
return password;
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleFormSubmit = async (e) => {
|
const handleFormSubmit = async (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
try {
|
try {
|
||||||
|
// Validate input fields
|
||||||
if (
|
if (
|
||||||
!user.name ||
|
!user.name ||
|
||||||
!user.email ||
|
!user.email ||
|
||||||
@ -116,17 +133,21 @@ const AddPrincipalDistributor = () => {
|
|||||||
) {
|
) {
|
||||||
throw new Error("Fill all fields!");
|
throw new Error("Fill all fields!");
|
||||||
}
|
}
|
||||||
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const generatedPassword = generatePassword(user.name, user.email);
|
const generatedPassword = generatePassword(user.name, user.email);
|
||||||
|
|
||||||
|
// Attempt to register user
|
||||||
const userResponse = await axios.post("/api/v1/user/register", {
|
const userResponse = await axios.post("/api/v1/user/register", {
|
||||||
...user,
|
...user,
|
||||||
password: generatedPassword,
|
password: generatedPassword,
|
||||||
|
role:"principal-Distributor",
|
||||||
});
|
});
|
||||||
|
|
||||||
if (userResponse.status === 201) {
|
if (userResponse.status === 201 || userResponse.status === 200) {
|
||||||
const userId = userResponse.data.userId;
|
const userId = userResponse.data.userId;
|
||||||
|
|
||||||
|
// Add address details for the user
|
||||||
const addressResponse = await axios.post(
|
const addressResponse = await axios.post(
|
||||||
`/api/shipping/address/admin/new/${userId}`,
|
`/api/shipping/address/admin/new/${userId}`,
|
||||||
{
|
{
|
||||||
@ -140,6 +161,7 @@ const AddPrincipalDistributor = () => {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
if (addressResponse.status === 201) {
|
if (addressResponse.status === 201) {
|
||||||
toast.success("Principal Distributor and Address Added Successfully");
|
toast.success("Principal Distributor and Address Added Successfully");
|
||||||
@ -152,6 +174,7 @@ const AddPrincipalDistributor = () => {
|
|||||||
toast.error(error.response?.data?.message || "Something went wrong!");
|
toast.error(error.response?.data?.message || "Something went wrong!");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const handleCancel = () => {
|
const handleCancel = () => {
|
||||||
navigate("/principal-distributor");
|
navigate("/principal-distributor");
|
||||||
|
Loading…
Reference in New Issue
Block a user