// DocumentManager.js import React, { useState } from "react"; import DocumentForm from "./DocumentForm"; import ConfirmModal from "../common/ConfirmModal"; const EmpDocuments = () => { const [searchText, setSearchText] = useState(""); const [documents, setDocuments] = useState([ { name: "Adhar Card", uploadedDate: "21 Aug, 2025", uploadedBy: "Alice Johnson", fileType: "PDF", url: "#", initials: "AC", files: [], }, { name: "Pan Card", uploadedDate: "15 Jul, 2025", uploadedBy: "Bob Smith", fileType: "Excel", url: "#", initials: "PC", files: [], }, { name: "Driving Licence", uploadedDate: "10 Aug, 2025", uploadedBy: "Carol Lee", fileType: "Word", url: "#", initials: "DL", files: [], }, { name: "", uploadedDate: "05 Aug, 2025", uploadedBy: "David Kim", fileType: "PNG", url: "#", initials: "DM", files: [], }, { name: "Client Presentation", uploadedDate: "18 Aug, 2025", uploadedBy: "Eve Brown", fileType: "PPT", url: "#", initials: "CP", files: [], }, ]); const [showForm, setShowForm] = useState(false); const [currentDocument, setCurrentDocument] = useState(null); // New state for the delete modal const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false); const [documentToDelete, setDocumentToDelete] = useState(null); const filteredDocuments = documents.filter((doc) => (doc.name || "Unnamed Document").toLowerCase().includes(searchText.toLowerCase()) ); const handleSearch = (e) => { setSearchText(e.target.value); }; const handleCreateClick = () => { setCurrentDocument(null); setShowForm(true); }; const handleEditClick = (doc) => { setCurrentDocument(doc); setShowForm(true); }; const handleSave = (newDoc) => { if (currentDocument) { // Edit an existing document setDocuments( documents.map((doc) => (doc === currentDocument ? { ...newDoc, initials: doc.initials } : doc)) ); } else { // Create a new document setDocuments([...documents, { ...newDoc, initials: newDoc.name ? newDoc.name.slice(0, 2).toUpperCase() : "--" }]); } setShowForm(false); }; const handleCancel = () => { setShowForm(false); setCurrentDocument(null); }; const handleDelete = (doc) => { // Set the document to be deleted and open the modal setDocumentToDelete(doc); setIsDeleteModalOpen(true); }; // New function to handle the confirmed deletion const handleConfirmDelete = () => { if (documentToDelete) { setDocuments(documents.filter((doc) => doc !== documentToDelete)); setIsDeleteModalOpen(false); // Close the modal setDocumentToDelete(null); // Clear the document to delete } }; // Function to close the delete modal const handleCloseDeleteModal = () => { setIsDeleteModalOpen(false); setDocumentToDelete(null); }; return (
{/* Header: Search & Create */}
{/* Table */}
{filteredDocuments.length > 0 ? ( filteredDocuments.map((doc, index) => ( )) ) : ( )}
Document Name Uploaded Date Uploaded By File Type Action
{doc.initials || (doc.name ? doc.name.slice(0, 2).toUpperCase() : "--")}
{doc.uploadedDate} {doc.uploadedBy} {doc.fileType} handleEditClick(doc)} > handleDelete(doc)} >
No documents available.
{/* Document Form Modal */} {showForm && (
)} {/* Delete Confirmation Modal */} {isDeleteModalOpen && (
)}
); }; export default EmpDocuments;