From 7e4a8157bfec325c295fa08ba2402fbf89d97e52 Mon Sep 17 00:00:00 2001 From: Kartik Sharma Date: Thu, 27 Nov 2025 10:40:10 +0530 Subject: [PATCH] Change the UI for Employee and Directory and adding export functionality. --- src/pages/Directory/DirectoryPage.jsx | 222 ++++++++++++++++++-------- src/pages/employee/EmployeeList.jsx | 133 +++++++-------- src/utils/exportUtils.js | 27 ---- 3 files changed, 214 insertions(+), 168 deletions(-) delete mode 100644 src/utils/exportUtils.js diff --git a/src/pages/Directory/DirectoryPage.jsx b/src/pages/Directory/DirectoryPage.jsx index 43c2f823..c5f07fbd 100644 --- a/src/pages/Directory/DirectoryPage.jsx +++ b/src/pages/Directory/DirectoryPage.jsx @@ -19,7 +19,7 @@ import BucketList from "../../components/Directory/BucketList"; import { MainDirectoryPageSkeleton } from "../../components/Directory/DirectoryPageSkeleton"; import ContactProfile from "../../components/Directory/ContactProfile"; import GlobalModel from "../../components/common/GlobalModel"; -import { exportToCSV } from "../../utils/exportUtils"; +import { exportToCSV,exportToExcel,exportToPDF1,exportToPDF,printTable } from "../../utils/tableExportUtils"; import ConfirmModal from "../../components/common/ConfirmModal"; import { useSelectedProject } from "../../slices/apiDataManager"; @@ -64,11 +64,49 @@ export default function DirectoryPage({ IsPage = true, projectId = null }) { const [ContactData, setContactData] = useState([]); const handleExport = (type) => { - if (activeTab === "notes" && type === "csv") { - exportToCSV(notesData, "notes.csv"); - } - if (activeTab === "contacts" && type === "csv") { - exportToCSV(ContactData, "contact.csv"); + let exportData = activeTab === "notes" ? notesData : ContactData; + if (!exportData?.length) return; + + switch (type) { + case "csv": + exportToCSV(exportData, activeTab === "notes" ? "Notes" : "Contacts"); + break; + case "excel": + exportToExcel(exportData, activeTab === "notes" ? "Notes" : "Contacts"); + break; + case "pdf": + if (activeTab === "notes") { + exportToPDF1(exportData, "Notes"); + } else { + // Columns for Contacts PDF + const columns = [ + "Email", + "Phone", + "Organization", + "Category", + "Tags", + ]; + + // Sanitize and trim long text to avoid PDF overflow + const sanitizedData = exportData.map((item) => ({ + Email: (item.Email || "").slice(0, 40), + Phone: (item.Phone || "").slice(0, 20), + Organization: (item.Organization || "").slice(0, 30), + Category: (item.Category || "").slice(0, 20), + Tags: (item.Tags || "").slice(0, 40), + })); + + // Export with proper spacing + exportToPDF(sanitizedData, "Contacts", columns, { + columnWidths: [200, 120, 180, 120, 200], // Adjust widths per column + fontSizeHeader: 12, + fontSizeRow: 10, + rowHeight: 25, + }); + } + break; + default: + console.warn("Unsupported export type"); } }; @@ -133,7 +171,7 @@ export default function DirectoryPage({ IsPage = true, projectId = null }) { ]} > )} -
+
    @@ -158,13 +196,11 @@ export default function DirectoryPage({ IsPage = true, projectId = null }) {
-
-
-
-
- {activeTab === "notes" && ( -
+
+
+
+ {activeTab === "notes" && ( setSearchNote(e.target.value)} /> -
- )} + )} - {activeTab === "contacts" && ( -
-
-
+ {activeTab === "contacts" && ( +
+
setsearchContact(e.target.value)} /> +
+ {" "} + + +
-
+
+ + +
    + {activeTab === "contacts" && ( +
  • +
    + + setShowActive(e.target.checked) + } + /> +
    + + {showActive + ? "Active Contacts" + : "Inactive Contacts"} + +
  • + )} +
  • + +
  • +
  • + +
  • +
  • + +
  • +
  • + setGridView(true)} > - - -
  • + +
  • + setGridView(false)} > - - - -
    - setShowActive(e.target.checked)} - /> - -
    -
-
- )} -
-
-
- -
diff --git a/src/pages/employee/EmployeeList.jsx b/src/pages/employee/EmployeeList.jsx index ba7a13ba..9417f8bc 100644 --- a/src/pages/employee/EmployeeList.jsx +++ b/src/pages/employee/EmployeeList.jsx @@ -298,31 +298,7 @@ const EmployeeList = () => {
{/* Switches: All Employees + Inactive */}
- {/* All Employees Switch */} - - {/* Show Inactive Employees Switch */} - -
- setShowInactive(e.target.checked)} - /> - -
-
- - {/* Right side: Search + Export + Add Employee */} -
- {/* Search Input - ALWAYS ENABLED */} + {/* {showAllEmployees && ( */}
- {/* Export Dropdown */} - + {/* )} */} +
+ {/* Right side: Search + Add Employee + Options */} +
{/* Add Employee Button */} {Manage_Employee && ( )} + + {/* 3-Dots Dropdown (New Combined Menu) */} +
+ +
    + +
  • +
    + setShowInactive(e.target.checked)} + /> +
    + Show Inactive Employees +
  • + + +

  • + +
  • + +
  • +
  • + +
  • +
  • + +
  • +
  • + +
  • +
+
+
{ - if (!data || data.length === 0) return; - - const headers = Object.keys(data[0]); - const csvRows = []; - - // Add headers - csvRows.push(headers.join(",")); - - // Add values - data.forEach(row => { - const values = headers.map(header => `"${row[header] ?? ""}"`); - csvRows.push(values.join(",")); - }); - - // Create CSV Blob - const csvContent = csvRows.join("\n"); - const blob = new Blob([csvContent], { type: "text/csv;charset=utf-8;" }); - - // Create download link - const link = document.createElement("a"); - const url = URL.createObjectURL(blob); - link.setAttribute("href", url); - link.setAttribute("download", filename); - link.click(); -};