diff --git a/src/components/Directory/NotesDirectory.jsx b/src/components/Directory/NotesDirectory.jsx
index fab739ee..b20f9a5e 100644
--- a/src/components/Directory/NotesDirectory.jsx
+++ b/src/components/Directory/NotesDirectory.jsx
@@ -128,42 +128,40 @@ const NotesDirectory = ({
{" "}
-
-
+ >
+ Include Deleted Notes
+
+
{!showEditor && (
@@ -225,23 +223,23 @@ const NotesDirectory = ({
)}
{!isLoading && notesToDisplay.length > 0
? notesToDisplay
- .slice()
- .reverse()
- .map((noteItem) => (
-
- ))
+ .slice()
+ .reverse()
+ .map((noteItem) => (
+
+ ))
: !isLoading &&
!showEditor && (
-
{noNotesMessage}
- )}
+
{noNotesMessage}
+ )}
);
diff --git a/src/components/Documents/DocumentVersionList.jsx b/src/components/Documents/DocumentVersionList.jsx
index 87b4004e..5c01b9c7 100644
--- a/src/components/Documents/DocumentVersionList.jsx
+++ b/src/components/Documents/DocumentVersionList.jsx
@@ -13,174 +13,276 @@ const DocumentVersionList = ({
isPending,
setOpenDocument,
VerifyDocument,
+ RejectDocument,
+ showVersions,
+ latestDoc,
}) => {
const canVerifyDocument = useHasUserPermission(VERIFY_DOCUMENT);
const canDownloadDocument = useHasUserPermission(DOWNLOAD_DOCUMENT);
+
const handleOpenDocument = () => {
if (canDownloadDocument) {
setOpenDocument(true);
}
};
- const contentTypeIcons = {
- "application/pdf": "fa-solid fa-file-pdf text-primary",
- "application/msword": "fa-solid fa-file-word text-primary",
- "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
- "fa-solid fa-file-word text-primary",
- "application/vnd.ms-excel": "fa-solid fa-file-excel text-success",
- "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":
- "fa-solid fa-file-excel text-primary",
- "application/vnd.ms-powerpoint": "fa-solid fa-file-powerpoint text-primary",
- "application/vnd.openxmlformats-officedocument.presentationml.presentation":
- "fa-solid fa-file-powerpoint text-primary",
- "image/jpg": "fa-solid fa-file-image text-primary",
- "image/jpeg": "fa-solid fa-file-image text-primary",
- "image/png": "fa-solid fa-file-image text-primary",
- "image/gif": "fa-solid fa-file-image text-primary",
- "text/plain": "fa-solid fa-file-lines text-primary",
- "text/csv": "fa-solid fa-file-csv text-primary",
- "application/json": "fa-solid fa-file-code text-primary",
- default: "fa-solid fa-file text-primary",
- };
-
- const getIcon = (fileName = "") => {
- const ext = fileName.split(".").pop().toLowerCase();
- return contentTypeIcons[ext] || contentTypeIcons.default;
- };
-
- const sortedVersions = versionList?.data
- ? [...versionList.data].sort((a, b) => b.version - a.version)
- : [];
if (versionLoding) {
return
;
}
+ const sortedVersions = versionList?.data
+ ? [...versionList.data].sort((a, b) => b.version - a.version)
+ : [];
+
+ const currentDoc = sortedVersions.length ? sortedVersions[0] : latestDoc;
+
+ if (!showVersions) {
+ if (!currentDoc) {
+ return
No documents available.
;
+ }
+ return (
+ <>
+
+
+
+ {/* Left Side: Document Details */}
+
+
+
+
+
+ {currentDoc.name}
+
+
+
+ {getDocuementsStatus(currentDoc.isVerified)}
+
+ File Size: {currentDoc.fileSize} Kb
+
+
+
+
+ Uploaded by
+
+
+
+
+ {`${currentDoc.uploadedBy?.firstName ?? ""} ${currentDoc.uploadedBy?.lastName ?? ""}`.trim() || "N/A"}
+
+
+
+
+ {formatUTCToLocalTime(currentDoc?.uploadedAt)}
+
+
+
+
+
+
+ latest
+
+
+
+ {/* Right Side: Status and Info */}
+
+ {/*
+ latest
+ */}
+
+ {currentDoc?.updatedBy && (
+ <>
+
Updated by
+
+
+
+ {`${currentDoc.updatedBy?.firstName ?? ""} ${currentDoc.updatedBy?.lastName ?? ""}`.trim() || "N/A"}
+
+
+ >
+ )}
+
+ {/* Conditionally render updated date */}
+ {currentDoc?.updatedAt && (
+
+ {formatUTCToLocalTime(currentDoc?.updatedAt)}
+
+ )}
+
+
+
+
+ {/* Buttons Div - only for the latest pending document when showVersions is false */}
+ {currentDoc.isVerified === null && canVerifyDocument && (
+
+ {isPending ? (
+ Please Wait...
+ ) : (
+ <>
+
+
+ >
+ )}
+
+ )}
+ >
+ );
+ }
+
+ // If showVersions is true, display all versions
if (!sortedVersions.length) {
return
No documents available.
;
}
- const latestDoc = sortedVersions[0];
-
return (
-
-
-
-
-
-
- {sortedVersions.map((document, index) => (
-
0 ? "ms-4" : "" // indent only older versions
- }`}
- >
-
-
-
-
- {document.name}
-
- Version-{document.version}
- {" "}
-
- File Size: {document.fileSize} Kb
-
-
-
-
-
- {formatUTCToLocalTime(document?.uploadedAt)} |
- Uploaded by{" "}
-
-
-
- {`${document.uploadedBy?.firstName ?? ""} ${document.uploadedBy?.lastName ?? ""
- }`.trim() || "N/A"}
-
-
-
-
-
- {document?.verifiedAt && (
- <>
- {formatUTCToLocalTime(document?.verifiedAt)} |{" "}
- {document.isVerified
- ? "Verified by "
- : "Rejected by "}
-
-
-
- {`${document.verifiedBy?.firstName ?? ""} ${document.verifiedBy?.lastName ?? ""
- }`.trim() || "N/A"}
-
-
- >
- )}
-
-
-
- {document?.updatedAt && (
-
- {formatUTCToLocalTime(document?.updatedAt)} |
- Updated by{" "}
-
-
-
- {`${document.updatedBy?.firstName ?? ""} ${document.updatedBy?.lastName ?? ""
- }`.trim() || "N/A"}
-
-
-
- )}
+
+
+ {sortedVersions.map((document, index) => (
+
+
+ {/* Left Side: Document Details */}
+
+
+
+
+
+ {document.name}
+
-
-
+
{getDocuementsStatus(document.isVerified)}
+
+ File Size: {document.fileSize} Kb
+
+
+
+ Uploaded by
+
+
+
+
+ {`${document.uploadedBy?.firstName ?? ""} ${document.uploadedBy?.lastName ?? ""}`.trim() || "N/A"}
+
+
+
+
+ {formatUTCToLocalTime(document?.uploadedAt)}
+
+ {document?.verifiedAt && (
+
+
+ {document.isVerified ? "Approved by" : "Rejected by"}
+
+
+
+
+ {`${document.verifiedBy?.firstName ?? ""} ${document.verifiedBy?.lastName ?? ""}`.trim() || "N/A"}
+
+
+
+ )}
+ {/* Conditionally render verified date */}
+ {document?.verifiedAt && (
+
+ {formatUTCToLocalTime(document?.verifiedAt)}
+
+ )}
+
+
+ version {document.version}
+
+ {document.isLatest && (
+
+ latest
+
+ )}
+
+ {/* Right Side: Status and Actions */}
+
+ {/*
+ version {document.version}
+ */}
+ {document.isLatest && (
+
+ latest
+
+ )}
+
+ {document?.updatedBy && (
+ <>
+
Updated by
+
+
+
+ {`${document.updatedBy?.firstName ?? ""} ${document.updatedBy?.lastName ?? ""}`.trim() || "N/A"}
+
+
+ >
+ )}
+
+ {/* Conditionally render updated date */}
+ {document?.updatedAt && (
+
+ {formatUTCToLocalTime(document?.updatedAt)}
+
+ )}
+
+
- ))}
-
+
+ ))}
diff --git a/src/components/Documents/ViewDocument.jsx b/src/components/Documents/ViewDocument.jsx
index b4e401ce..8270bb08 100644
--- a/src/components/Documents/ViewDocument.jsx
+++ b/src/components/Documents/ViewDocument.jsx
@@ -1,3 +1,4 @@
+// ViewDocument.jsx
import React, { useState } from "react";
import {
useDocumentDetails,
@@ -12,9 +13,6 @@ import {
ITEMS_PER_PAGE,
VERIFY_DOCUMENT,
} from "../../utils/constants";
-import Pagination from "../common/Pagination";
-import VersionListSkeleton from "./VersionListSkeleton";
-// import DocumentDetailsSkeleton from "./DocumentDetailsSkeleton";
import DocumentDetailsSkeleton from "./DocumentDetailsSkeleton ";
import { useHasUserPermission } from "../../hooks/useHasUserPermission";
import DocumentVersionList from "./DocumentVersionList";
@@ -22,15 +20,20 @@ import DocumentVersionList from "./DocumentVersionList";
const ViewDocument = () => {
const { viewDoc, setOpenDocument } = useDocumentContext();
const [currentPage, setCurrentPage] = useState(1);
+ const [showVersions, setShowVersions] = useState(false);
const canVerifyDocument = useHasUserPermission(VERIFY_DOCUMENT);
+
+ // Document Details
const { data, isLoading, isError, error } = useDocumentDetails(
viewDoc?.document
);
+
+ // Document Versions (fetch only if toggle is ON)
const {
data: versionList,
- isLoading: versionLoding,
+ isLoading: versionLoading,
} = useDocumentVersionList(
- data?.parentAttachmentId,
+ showVersions ? data?.parentAttachmentId : null,
ITEMS_PER_PAGE - 10,
currentPage
);
@@ -41,6 +44,7 @@ const ViewDocument = () => {
}
};
+ // Verify / Reject
const { mutate: VerifyDoc, isPending } = useVerifyDocument();
const VerifyDocument = () => {
VerifyDoc({ documentId: viewDoc?.document, isVerify: true });
@@ -62,6 +66,7 @@ const ViewDocument = () => {
Document Details
+ {/* Document Info Rows */}
@@ -103,14 +108,7 @@ const ViewDocument = () => {
{formatUTCToLocalTime(data.uploadedAt)}
-
-
- Updated At:
-
-
- {formatUTCToLocalTime(data.updatedAt) || "-"}
-
-
+
@@ -144,39 +142,32 @@ const ViewDocument = () => {
- {/* Verify / Reject */}
- {data.isVerified === null && canVerifyDocument && (
-
- {isPending ? (
-
Please Wait...
- ) : (
- <>
-
-
- >
- )}
+ {/* Toggle for Versions */}
+
+
Documents:
+
+
+ setShowVersions(e.target.checked)}
+ />
- )}
-
+
);