Added Document Managment feature #388
@ -16,36 +16,12 @@ const DocumentVersionList = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const canVerifyDocument = useHasUserPermission(VERIFY_DOCUMENT);
|
const canVerifyDocument = useHasUserPermission(VERIFY_DOCUMENT);
|
||||||
const canDownloadDocument = useHasUserPermission(DOWNLOAD_DOCUMENT);
|
const canDownloadDocument = useHasUserPermission(DOWNLOAD_DOCUMENT);
|
||||||
|
|
||||||
const handleOpenDocument = () => {
|
const handleOpenDocument = () => {
|
||||||
if (canDownloadDocument) {
|
if (canDownloadDocument) {
|
||||||
setOpenDocument(true);
|
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
|
const sortedVersions = versionList?.data
|
||||||
? [...versionList.data].sort((a, b) => b.version - a.version)
|
? [...versionList.data].sort((a, b) => b.version - a.version)
|
||||||
@ -59,123 +35,125 @@ const DocumentVersionList = ({
|
|||||||
return <p className="text-muted">No documents available.</p>;
|
return <p className="text-muted">No documents available.</p>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const latestDoc = sortedVersions[0];
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="accordion" id="docAccordion">
|
<>
|
||||||
<div className="accordion-item shadow-none">
|
<div className="d-flex justify-content-between align-items-center mb-3">
|
||||||
<h2 className="accordion-header" id="headingDoc">
|
<h5 className="mb-0">Documents</h5>
|
||||||
<button
|
<div className="form-check form-switch">
|
||||||
className="accordion-button"
|
<input
|
||||||
type="button"
|
className="form-check-input"
|
||||||
data-bs-toggle="collapse"
|
type="checkbox"
|
||||||
data-bs-target="#collapseDoc"
|
id="showVersionsSwitch"
|
||||||
aria-expanded="true"
|
/>
|
||||||
aria-controls="collapseDoc"
|
<label className="form-check-label" htmlFor="showVersionsSwitch">
|
||||||
>
|
Show Versions
|
||||||
<i className="bx bxs-folder me-2 text-warning fs-5"></i>
|
</label>
|
||||||
{latestDoc.name} (Latest v{latestDoc.version})
|
</div>
|
||||||
</button>
|
</div>
|
||||||
</h2>
|
<div className="accordion" id="docAccordion">
|
||||||
<div
|
<div className="accordion-item shadow-none">
|
||||||
id="collapseDoc"
|
|
||||||
className="accordion-collapse collapse show"
|
|
||||||
aria-labelledby="headingDoc"
|
|
||||||
data-bs-parent="#docAccordion"
|
|
||||||
>
|
|
||||||
<div className="accordion-body p-2">
|
<div className="accordion-body p-2">
|
||||||
<div className="list-group list-group-flush">
|
<div className="list-group list-group-flush">
|
||||||
{sortedVersions.map((document, index) => (
|
{sortedVersions.map((document, index) => (
|
||||||
<div
|
<div
|
||||||
key={document.id}
|
key={document.id}
|
||||||
className={`list-group-item list-group-item-action d-flex align-items-center cursor-pointer ${index > 0 ? "ms-4" : "" // indent only older versions
|
className="list-group-item list-group-item-action" style={{ marginLeft: "-30px" }}
|
||||||
}`}
|
|
||||||
>
|
>
|
||||||
<FileIcon
|
<div className="d-flex justify-content-between">
|
||||||
type={document.contentType}
|
{/* Left Side: Document Details */}
|
||||||
size="fs-2"
|
<div className="d-flex align-items-start">
|
||||||
className="me-2"
|
<FileIcon
|
||||||
/>
|
type={document.contentType}
|
||||||
|
size="fs-2"
|
||||||
<div className="w-100">
|
className="me-2"
|
||||||
<div className="d-flex justify-content-between align-items-center">
|
/>
|
||||||
<small className=" fw-normal">{document.name}</small>
|
<div>
|
||||||
<small className=" fw-normal">
|
<div className="d-flex align-items-center mb-1">
|
||||||
Version-{document.version}
|
<span className="fw-normal">
|
||||||
</small>{" "}
|
{document.name}
|
||||||
<small className=" text-secondary fw-normal">
|
</span>
|
||||||
File Size: {document.fileSize} Kb
|
</div>
|
||||||
</small>
|
<div className="d-flex align-items-center mb-1">
|
||||||
</div>
|
{getDocuementsStatus(document.isVerified)}
|
||||||
<div className="d-flex justify-content-between m-0">
|
<span className="text-secondary ms-7">
|
||||||
<div
|
File Size: {document.fileSize} Kb
|
||||||
className="user-info text-start m-0"
|
</span>
|
||||||
onClick={handleOpenDocument}
|
</div>
|
||||||
>
|
|
||||||
<div className="d-flex align-items-center">
|
<div className="d-flex align-items-center">
|
||||||
{formatUTCToLocalTime(document?.uploadedAt)} |
|
<small className="text-secondary me-2">
|
||||||
Uploaded by{" "}
|
Uploaded by
|
||||||
<div className="d-flex align-items-center ms-1">
|
</small>
|
||||||
|
<Avatar
|
||||||
|
size="xs"
|
||||||
|
classAvatar="m-0"
|
||||||
|
firstName={document.uploadedBy?.firstName}
|
||||||
|
lastName={document.uploadedBy?.lastName}
|
||||||
|
/>
|
||||||
|
<span className="ms-1">
|
||||||
|
<small className="fw-normal">
|
||||||
|
{`${document.uploadedBy?.firstName ?? ""} ${document.uploadedBy?.lastName ?? ""}`.trim() || "N/A"}
|
||||||
|
</small>
|
||||||
|
</span>
|
||||||
|
<small className="ms-2">
|
||||||
|
{formatUTCToLocalTime(document?.uploadedAt)}
|
||||||
|
</small>
|
||||||
|
</div>
|
||||||
|
{document?.verifiedAt && (
|
||||||
|
<div className="d-flex align-items-center mt-1">
|
||||||
|
<small className="text-secondary me-2">
|
||||||
|
{document.isVerified ? "Approved by" : "Rejected by"}
|
||||||
|
</small>
|
||||||
<Avatar
|
<Avatar
|
||||||
size="xs"
|
size="xs"
|
||||||
classAvatar="m-0"
|
classAvatar="m-0"
|
||||||
firstName={document.uploadedBy?.firstName}
|
firstName={document.verifiedBy?.firstName}
|
||||||
lastName={document.uploadedBy?.lastName}
|
lastName={document.verifiedBy?.lastName}
|
||||||
/>
|
/>
|
||||||
<span className="text-truncate ms-1">
|
<span className="ms-1">
|
||||||
{`${document.uploadedBy?.firstName ?? ""} ${document.uploadedBy?.lastName ?? ""
|
<small className="fw-normal">
|
||||||
}`.trim() || "N/A"}
|
{`${document.verifiedBy?.firstName ?? ""} ${document.verifiedBy?.lastName ?? ""}`.trim() || "N/A"}
|
||||||
|
</small>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
<small className="ms-2">
|
||||||
</div>
|
{formatUTCToLocalTime(document?.verifiedAt)}
|
||||||
|
</small>
|
||||||
<div className="d-flex align-items-center">
|
|
||||||
{document?.verifiedAt && (
|
|
||||||
<>
|
|
||||||
{formatUTCToLocalTime(document?.verifiedAt)} |{" "}
|
|
||||||
{document.isVerified
|
|
||||||
? "Verified by "
|
|
||||||
: "Rejected by "}
|
|
||||||
<div className="d-flex align-items-center ms-1">
|
|
||||||
<Avatar
|
|
||||||
size="xs"
|
|
||||||
classAvatar="m-0"
|
|
||||||
firstName={document.verifiedBy?.firstName}
|
|
||||||
lastName={document.verifiedBy?.lastName}
|
|
||||||
/>
|
|
||||||
<span className="text-truncate ms-1">
|
|
||||||
{`${document.verifiedBy?.firstName ?? ""} ${document.verifiedBy?.lastName ?? ""
|
|
||||||
}`.trim() || "N/A"}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
{document?.updatedAt && (
|
|
||||||
<div className="d-flex align-items-center">
|
|
||||||
{formatUTCToLocalTime(document?.updatedAt)} |
|
|
||||||
Updated by{" "}
|
|
||||||
<div className="d-flex align-items-center ms-1">
|
|
||||||
<Avatar
|
|
||||||
size="xs"
|
|
||||||
classAvatar="m-0"
|
|
||||||
firstName={document.updatedBy?.firstName}
|
|
||||||
lastName={document.updatedBy?.lastName}
|
|
||||||
/>
|
|
||||||
<span className="text-truncate ms-1">
|
|
||||||
{`${document.updatedBy?.firstName ?? ""} ${document.updatedBy?.lastName ?? ""
|
|
||||||
}`.trim() || "N/A"}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="d-flex align-items-end">
|
{/* Right Side: Status and Actions */}
|
||||||
{getDocuementsStatus(document.isVerified)}
|
<div className="d-flex flex-column align-items-end" style={{ marginTop: "42px", marginRight: "-52px" }}>
|
||||||
|
{document.isLatest && (
|
||||||
|
<span className="badge bg-success-subtle text-success">
|
||||||
|
latest
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="d-flex align-items-center mt-1">
|
||||||
|
{document?.updatedBy && (
|
||||||
|
<>
|
||||||
|
<small className="text-secondary me-2">Updated by</small>
|
||||||
|
<Avatar
|
||||||
|
size="xs"
|
||||||
|
classAvatar="m-0"
|
||||||
|
firstName={document.updatedBy?.firstName}
|
||||||
|
lastName={document.updatedBy?.lastName}
|
||||||
|
/>
|
||||||
|
<span className="ms-1">
|
||||||
|
<small className="fw-normal">
|
||||||
|
{`${document.updatedBy?.firstName ?? ""} ${document.updatedBy?.lastName ?? ""}`.trim() || "N/A"}
|
||||||
|
</small>
|
||||||
|
</span>
|
||||||
|
<small className="ms-2">
|
||||||
|
{formatUTCToLocalTime(document?.updatedAt)}
|
||||||
|
</small>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
<small className="text-secondary mt-1">
|
||||||
|
version {document.version}
|
||||||
|
</small>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -184,7 +162,7 @@ const DocumentVersionList = ({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ const ViewDocument = () => {
|
|||||||
<p className="danger-text">{error?.response?.status}</p>
|
<p className="danger-text">{error?.response?.status}</p>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
console.log("kartik", data)
|
||||||
return (
|
return (
|
||||||
<div className="p-3">
|
<div className="p-3">
|
||||||
<p className="fw-bold fs-5 mb-3 border-bottom pb-2">Document Details</p>
|
<p className="fw-bold fs-5 mb-3 border-bottom pb-2">Document Details</p>
|
||||||
@ -150,7 +150,7 @@ const ViewDocument = () => {
|
|||||||
{isPending ? (
|
{isPending ? (
|
||||||
<span className="text-muted">Please Wait...</span>
|
<span className="text-muted">Please Wait...</span>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={RejectDocument}
|
onClick={RejectDocument}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user