added userPermissions

This commit is contained in:
Pramod Mahajan 2025-04-23 12:14:30 +05:30
parent 38fbc6dc84
commit c61cb3bb63

View File

@ -1,4 +1,4 @@
import React, { useState, useEffect,useRef } from "react";
import React, { useState, useEffect, useRef } from "react";
import moment from "moment";
import { Link, NavLink, useNavigate } from "react-router-dom";
import Avatar from "../../components/common/Avatar";
@ -11,7 +11,12 @@ import { hasUserPermission } from "../../utils/authUtils";
import { MANAGE_EMPLOYEES } from "../../utils/constants";
import { useHasUserPermission } from "../../hooks/useHasUserPermission";
import SuspendEmp from "../../components/Employee/SuspendEmp";
import {exportToCSV,exportToExcel,printTable,exportToPDF} from "../../utils/tableExportUtils";
import {
exportToCSV,
exportToExcel,
printTable,
exportToPDF,
} from "../../utils/tableExportUtils";
const EmployeeList = () => {
const { profile: loginUser } = useProfile();
@ -114,7 +119,7 @@ const EmployeeList = () => {
exportToExcel(currentItems, "employees");
break;
case "pdf":
exportToPDF(currentItems, "employees"); // Pass the employeeList directly
exportToPDF(currentItems, "employees"); // Pass the employeeList directly
break;
case "print":
printTable(tableRef.current);
@ -124,7 +129,6 @@ const EmployeeList = () => {
}
};
return (
<>
{isCreateModalOpen && (
@ -163,32 +167,36 @@ const EmployeeList = () => {
className="dataTables_length text-start"
id="DataTables_Table_0_length"
>
<label>
<select
id="project-select"
onChange={(e) => setSelectedProject(e.target.value)}
name="DataTables_Table_0_length"
aria-controls="DataTables_Table_0"
className="form-select form-select-sm"
value={selectedProject || ""}
>
{projectLoading ? (
<option value="Loading">Loading...</option>
) : (
<>
<option value="">All Employees</option>
{Array.isArray(projects) &&
projects
.filter((item) => loginUser?.projects?.includes(String(item.id)))
.map((item) => (
<option key={item.id} value={item.id}>
{item.name}
</option>
))}
</>
)}
</select>
</label>
<label>
<select
id="project-select"
onChange={(e) => setSelectedProject(e.target.value)}
name="DataTables_Table_0_length"
aria-controls="DataTables_Table_0"
className="form-select form-select-sm"
value={selectedProject || ""}
>
{projectLoading ? (
<option value="Loading">Loading...</option>
) : (
<>
<option value="">All Employees</option>
{Array.isArray(projects) &&
projects
.filter((item) =>
loginUser?.projects?.includes(
String(item.id)
)
)
.map((item) => (
<option key={item.id} value={item.id}>
{item.name}
</option>
))}
</>
)}
</select>
</label>
</div>
</div>
</div>
@ -223,22 +231,39 @@ const EmployeeList = () => {
</button>
<ul className="dropdown-menu">
<li>
<a className="dropdown-item" href="#" onClick={() => handleExport("print")}>
<a
className="dropdown-item"
href="#"
onClick={() => handleExport("print")}
>
<i className="bx bx-printer me-1"></i> Print
</a>
</li>
<li>
<a className="dropdown-item" href="#" onClick={() => handleExport("csv")}>
<a
className="dropdown-item"
href="#"
onClick={() => handleExport("csv")}
>
<i className="bx bx-file me-1"></i> CSV
</a>
</li>
<li>
<a className="dropdown-item" href="#" onClick={() => handleExport("excel")}>
<i className="bx bxs-file-export me-1"></i> Excel
<a
className="dropdown-item"
href="#"
onClick={() => handleExport("excel")}
>
<i className="bx bxs-file-export me-1"></i>{" "}
Excel
</a>
</li>
<li>
<a className="dropdown-item" href="#" onClick={() => handleExport("pdf")}>
<a
className="dropdown-item"
href="#"
onClick={() => handleExport("pdf")}
>
<i className="bx bxs-file-pdf me-1"></i> PDF
</a>
</li>
@ -462,19 +487,19 @@ const EmployeeList = () => {
}
className="dropdown-item py-1"
>
<i className="bx bx-detail bx-sm"></i> View
<i className="bx bx-detail bx-sm"></i> View
</button>
<Link
to={`/employee/manage/${item.id}`}
className="dropdown-item py-1"
>
<i class='bx bx-edit bx-sm'></i> Edit
<i class="bx bx-edit bx-sm"></i> Edit
</Link>
<button
className="dropdown-item py-1"
onClick={handleShow}
>
<i class='bx bx-task-x bx-sm'></i> Suspend
<i class="bx bx-task-x bx-sm"></i> Suspend
</button>
<button
className="dropdown-item py-1"
@ -483,7 +508,7 @@ const EmployeeList = () => {
data-bs-target="#managerole-modal"
onClick={() => handleConfigData(item.id)}
>
<i class='bx bx-cog bx-sm'></i> Manage Role
<i class="bx bx-cog bx-sm"></i> Manage Role
</button>
</div>
</div>