login user can be verify documents
This commit is contained in:
parent
ef00f83c44
commit
11be36b67a
@ -2,6 +2,7 @@ import React, { useState } from "react";
|
||||
import {
|
||||
useDocumentDetails,
|
||||
useDocumentVersionList,
|
||||
useVerifyDocument,
|
||||
} from "../../hooks/useDocument";
|
||||
import { getDocuementsStatus, useDocumentContext } from "./Documents";
|
||||
import { formatUTCToLocalTime } from "../../utils/dateUtils";
|
||||
@ -12,7 +13,7 @@ import VersionListSkeleton from "./VersionListSkeleton";
|
||||
import DocumentDetailsSkeleton from "./DocumentDetailsSkeleton ";
|
||||
|
||||
const ViewDocument = () => {
|
||||
const { viewDoc, setViewDoc,setOpenDocument } = useDocumentContext();
|
||||
const { viewDoc, setViewDoc, setOpenDocument } = useDocumentContext();
|
||||
const [currentPage, setCurrentPage] = useState(1);
|
||||
const { data, isLoading, isError, error } = useDocumentDetails(
|
||||
viewDoc?.document
|
||||
@ -33,13 +34,17 @@ const ViewDocument = () => {
|
||||
}
|
||||
};
|
||||
|
||||
if (isLoading) return <DocumentDetailsSkeleton/>;
|
||||
const { mutate: VerifyDoc, isPending } = useVerifyDocument();
|
||||
const VerifyDocument = () => {
|
||||
VerifyDoc({ documentId: viewDoc?.document, isVerify: true });
|
||||
};
|
||||
|
||||
if (isLoading) return <DocumentDetailsSkeleton />;
|
||||
if (isError) return <div>{error.message}</div>;
|
||||
return (
|
||||
<div className="p-1">
|
||||
<p className="fw-bold fs-6">Document Details</p>
|
||||
|
||||
|
||||
<div className="row mb-2">
|
||||
<div className="col-12 col-md-6">
|
||||
<div className="d-flex text-start">
|
||||
@ -166,11 +171,11 @@ const ViewDocument = () => {
|
||||
|
||||
<div className="row text-start py-2">
|
||||
<p className="m-0 fw-semibold : ">Documents</p>
|
||||
{versionLoding && <VersionListSkeleton items={2}/>}
|
||||
{!versionLoding &&(<div className="list-group mx-0">
|
||||
{
|
||||
versionList?.data.map((document) => (
|
||||
<a className="list-group-item list-group-item-action py-1 border border-bottom border-top-0 border-start-0 border-end-0">
|
||||
{versionLoding && <VersionListSkeleton items={2} />}
|
||||
{!versionLoding && (
|
||||
<div className="list-group mx-0">
|
||||
{versionList?.data.map((document) => (
|
||||
<a className="list-group-item list-group-item-action py-1 border border-bottom border-top-0 border-start-0 border-end-0" key={document.id}>
|
||||
<div className="d-flex w-100 justify-content-between m-0">
|
||||
<p className="m-0">
|
||||
{document.name}{" "}
|
||||
@ -184,23 +189,45 @@ const ViewDocument = () => {
|
||||
</div>
|
||||
</div>
|
||||
<div className="d-flex align-items-center justify-content-between text-secondary">
|
||||
<div className="d-flex align-items-center">
|
||||
Upload By
|
||||
<Avatar
|
||||
size="xs"
|
||||
classAvatar="m-0"
|
||||
firstName={document.uploadedBy?.firstName}
|
||||
lastName={document.uploadedBy?.lastName}
|
||||
/>
|
||||
<span className="text-truncate m-0 ">
|
||||
{`${document.uploadedBy?.firstName ?? ""} ${
|
||||
document.uploadedBy?.lastName ?? ""
|
||||
}`.trim() || "N/A"}
|
||||
</span>
|
||||
</div>
|
||||
<div className="d-flex text-primary align-items-center cursor-pointer"onClick={()=>setOpenDocument(true)} >
|
||||
<small >view</small> <i className='bx bx-sm bx-link-external'></i>
|
||||
</div>
|
||||
<div className="d-flex align-items-center">
|
||||
Upload By
|
||||
<Avatar
|
||||
size="xs"
|
||||
classAvatar="m-0"
|
||||
firstName={document.uploadedBy?.firstName}
|
||||
lastName={document.uploadedBy?.lastName}
|
||||
/>
|
||||
<span className="text-truncate m-0 ">
|
||||
{`${document.uploadedBy?.firstName ?? ""} ${
|
||||
document.uploadedBy?.lastName ?? ""
|
||||
}`.trim() || "N/A"}
|
||||
</span>
|
||||
</div>
|
||||
<div className="d-flex text-primary align-items-center gap-2 ">
|
||||
{document.isVerified == null &&
|
||||
(isPending ? (
|
||||
<div
|
||||
class="spinner-border spinner-border-sm text-primary"
|
||||
role="status"
|
||||
>
|
||||
<span class="visually-hidden">Loading...</span>
|
||||
</div>
|
||||
) : (
|
||||
<span
|
||||
className="cursor-pointer"
|
||||
onClick={VerifyDocument}
|
||||
>
|
||||
verify
|
||||
</span>
|
||||
))}
|
||||
<span
|
||||
className="cursor-pointer text-decoration-underline"
|
||||
onClick={() => setOpenDocument(true)}
|
||||
>
|
||||
<small>view</small>{" "}
|
||||
<i className="bx bx-sm bx-link-external"></i>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
{/* <div className="d-flex gap-2">
|
||||
{document?.updatedAt && (
|
||||
@ -211,7 +238,8 @@ const ViewDocument = () => {
|
||||
</div> */}
|
||||
</a>
|
||||
))}
|
||||
</div>)}
|
||||
</div>
|
||||
)}
|
||||
{!versionLoding && versionList?.data?.length > 0 && (
|
||||
<Pagination
|
||||
currentPage={currentPage}
|
||||
|
@ -142,3 +142,27 @@ export const useUpdateDocument = (onSuccessCallBack) => {
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const useVerifyDocument = ()=>{
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn:async({documentId,isVerify}) => await DocumentRepository.verifyDocument(documentId,isVerify),
|
||||
onSuccess: (data, variables) => {
|
||||
queryClient.invalidateQueries({ queryKey: ["DocumentVersionList"] });
|
||||
queryClient.invalidateQueries({ queryKey: ["DocumentList"] });
|
||||
showToast(
|
||||
data.response.data.message ||
|
||||
"Document Successfully Verified !",
|
||||
"success"
|
||||
);
|
||||
},
|
||||
onError: (error) => {
|
||||
showToast(
|
||||
error.response.data.message ||
|
||||
"Something went wrong please try again !",
|
||||
"error"
|
||||
);
|
||||
},
|
||||
|
||||
})
|
||||
}
|
@ -16,7 +16,7 @@ export const DocumentRepository = {
|
||||
|
||||
getDocumentVersion:(id)=>api.get(`/api/Document/get/version/${id}`),
|
||||
|
||||
verifyDocument:(id)=>api.post(`/api/Document/verify/${id}`),
|
||||
verifyDocument:(id,isVerify)=>api.post(`/api/Document/verify/${id}/?isVerify=${isVerify}`),
|
||||
|
||||
deleteDocument:(id)=>api.delete(`/api/Document/delete/${id}`)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user