Vaibhav_Task-#90 #24
@ -1,4 +1,4 @@
|
|||||||
import React, { useState, useEffect } 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,6 +11,7 @@ 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";
|
||||||
|
|
||||||
const EmployeeList = () => {
|
const EmployeeList = () => {
|
||||||
const { profile: loginUser } = useProfile();
|
const { profile: loginUser } = useProfile();
|
||||||
@ -101,7 +102,29 @@ const EmployeeList = () => {
|
|||||||
openModal();
|
openModal();
|
||||||
}
|
}
|
||||||
}, [modelConfig, isCreateModalOpen]);
|
}, [modelConfig, isCreateModalOpen]);
|
||||||
|
const tableRef = useRef(null);
|
||||||
|
const handleExport = (type) => {
|
||||||
|
if (!currentItems || currentItems.length === 0) return;
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case "csv":
|
||||||
|
exportToCSV(currentItems, "employees");
|
||||||
|
break;
|
||||||
|
case "excel":
|
||||||
|
exportToExcel(currentItems, "employees");
|
||||||
|
break;
|
||||||
|
case "pdf":
|
||||||
|
exportToPDF(currentItems, "employees"); // Pass the employeeList directly
|
||||||
|
break;
|
||||||
|
case "print":
|
||||||
|
printTable(tableRef.current);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{isCreateModalOpen && (
|
{isCreateModalOpen && (
|
||||||
@ -198,13 +221,23 @@ const EmployeeList = () => {
|
|||||||
</button>
|
</button>
|
||||||
<ul className="dropdown-menu">
|
<ul className="dropdown-menu">
|
||||||
<li>
|
<li>
|
||||||
<a
|
<a className="dropdown-item" href="#" onClick={() => handleExport("print")}>
|
||||||
aria-label="dropdown item action"
|
<i className="bx bx-printer me-1"></i> Print
|
||||||
className="dropdown-item"
|
</a>
|
||||||
href="#"
|
</li>
|
||||||
>
|
<li>
|
||||||
{/* <i className="bx bx-printer me-1"></i> */}
|
<a className="dropdown-item" href="#" onClick={() => handleExport("csv")}>
|
||||||
Coming Soon
|
<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>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a className="dropdown-item" href="#" onClick={() => handleExport("pdf")}>
|
||||||
|
<i className="bx bxs-file-pdf me-1"></i> PDF
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
@ -237,6 +270,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}
|
||||||
>
|
>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user