-
-
-
-
- {document.name}
-
-
-
- {getDocuementsStatus(document.isVerified)}
-
- File Size: {document.fileSize} Kb
-
-
-
-
- Uploaded by
+
+
+
+
+ {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.uploadedBy?.firstName ?? ""} ${document.uploadedBy?.lastName ?? ""}`.trim() || "N/A"}
+
+ {`${document.verifiedBy?.firstName ?? ""} ${document.verifiedBy?.lastName ?? ""}`.trim() || "N/A"}
-
- {formatUTCToLocalTime(document?.uploadedAt)}
-
- {document?.verifiedAt && (
-
-
- {document.isVerified ? "Approved by" : "Rejected by"}
-
-
-
-
- {`${document.verifiedBy?.firstName ?? ""} ${document.verifiedBy?.lastName ?? ""}`.trim() || "N/A"}
-
-
-
- {formatUTCToLocalTime(document?.verifiedAt)}
-
-
- )}
-
-
-
- {/* Right Side: Status and Actions */}
-
- {document.isLatest && (
-
- latest
-
)}
-
-
- {document?.updatedBy && (
- <>
-
Updated by
-
-
-
- {`${document.updatedBy?.firstName ?? ""} ${document.updatedBy?.lastName ?? ""}`.trim() || "N/A"}
-
-
-
- {formatUTCToLocalTime(document?.updatedAt)}
-
- >
- )}
-
-
- version {document.version}
-
+ {/* 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 5eb46f37..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 });
@@ -57,11 +61,12 @@ const ViewDocument = () => {
{error?.response?.status}
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 && (
-