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