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 {
|
import {
|
||||||
useDocumentDetails,
|
useDocumentDetails,
|
||||||
useDocumentVersionList,
|
useDocumentVersionList,
|
||||||
|
useVerifyDocument,
|
||||||
} from "../../hooks/useDocument";
|
} from "../../hooks/useDocument";
|
||||||
import { getDocuementsStatus, useDocumentContext } from "./Documents";
|
import { getDocuementsStatus, useDocumentContext } from "./Documents";
|
||||||
import { formatUTCToLocalTime } from "../../utils/dateUtils";
|
import { formatUTCToLocalTime } from "../../utils/dateUtils";
|
||||||
@ -12,7 +13,7 @@ import VersionListSkeleton from "./VersionListSkeleton";
|
|||||||
import DocumentDetailsSkeleton from "./DocumentDetailsSkeleton ";
|
import DocumentDetailsSkeleton from "./DocumentDetailsSkeleton ";
|
||||||
|
|
||||||
const ViewDocument = () => {
|
const ViewDocument = () => {
|
||||||
const { viewDoc, setViewDoc,setOpenDocument } = useDocumentContext();
|
const { viewDoc, setViewDoc, setOpenDocument } = useDocumentContext();
|
||||||
const [currentPage, setCurrentPage] = useState(1);
|
const [currentPage, setCurrentPage] = useState(1);
|
||||||
const { data, isLoading, isError, error } = useDocumentDetails(
|
const { data, isLoading, isError, error } = useDocumentDetails(
|
||||||
viewDoc?.document
|
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>;
|
if (isError) return <div>{error.message}</div>;
|
||||||
return (
|
return (
|
||||||
<div className="p-1">
|
<div className="p-1">
|
||||||
<p className="fw-bold fs-6">Document Details</p>
|
<p className="fw-bold fs-6">Document Details</p>
|
||||||
|
|
||||||
|
|
||||||
<div className="row mb-2">
|
<div className="row mb-2">
|
||||||
<div className="col-12 col-md-6">
|
<div className="col-12 col-md-6">
|
||||||
<div className="d-flex text-start">
|
<div className="d-flex text-start">
|
||||||
@ -166,11 +171,11 @@ const ViewDocument = () => {
|
|||||||
|
|
||||||
<div className="row text-start py-2">
|
<div className="row text-start py-2">
|
||||||
<p className="m-0 fw-semibold : ">Documents</p>
|
<p className="m-0 fw-semibold : ">Documents</p>
|
||||||
{versionLoding && <VersionListSkeleton items={2}/>}
|
{versionLoding && <VersionListSkeleton items={2} />}
|
||||||
{!versionLoding &&(<div className="list-group mx-0">
|
{!versionLoding && (
|
||||||
{
|
<div className="list-group mx-0">
|
||||||
versionList?.data.map((document) => (
|
{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">
|
<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">
|
<div className="d-flex w-100 justify-content-between m-0">
|
||||||
<p className="m-0">
|
<p className="m-0">
|
||||||
{document.name}{" "}
|
{document.name}{" "}
|
||||||
@ -184,23 +189,45 @@ const ViewDocument = () => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="d-flex align-items-center justify-content-between text-secondary">
|
<div className="d-flex align-items-center justify-content-between text-secondary">
|
||||||
<div className="d-flex align-items-center">
|
<div className="d-flex align-items-center">
|
||||||
Upload By
|
Upload By
|
||||||
<Avatar
|
<Avatar
|
||||||
size="xs"
|
size="xs"
|
||||||
classAvatar="m-0"
|
classAvatar="m-0"
|
||||||
firstName={document.uploadedBy?.firstName}
|
firstName={document.uploadedBy?.firstName}
|
||||||
lastName={document.uploadedBy?.lastName}
|
lastName={document.uploadedBy?.lastName}
|
||||||
/>
|
/>
|
||||||
<span className="text-truncate m-0 ">
|
<span className="text-truncate m-0 ">
|
||||||
{`${document.uploadedBy?.firstName ?? ""} ${
|
{`${document.uploadedBy?.firstName ?? ""} ${
|
||||||
document.uploadedBy?.lastName ?? ""
|
document.uploadedBy?.lastName ?? ""
|
||||||
}`.trim() || "N/A"}
|
}`.trim() || "N/A"}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="d-flex text-primary align-items-center cursor-pointer"onClick={()=>setOpenDocument(true)} >
|
<div className="d-flex text-primary align-items-center gap-2 ">
|
||||||
<small >view</small> <i className='bx bx-sm bx-link-external'></i>
|
{document.isVerified == null &&
|
||||||
</div>
|
(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>
|
||||||
{/* <div className="d-flex gap-2">
|
{/* <div className="d-flex gap-2">
|
||||||
{document?.updatedAt && (
|
{document?.updatedAt && (
|
||||||
@ -211,7 +238,8 @@ const ViewDocument = () => {
|
|||||||
</div> */}
|
</div> */}
|
||||||
</a>
|
</a>
|
||||||
))}
|
))}
|
||||||
</div>)}
|
</div>
|
||||||
|
)}
|
||||||
{!versionLoding && versionList?.data?.length > 0 && (
|
{!versionLoding && versionList?.data?.length > 0 && (
|
||||||
<Pagination
|
<Pagination
|
||||||
currentPage={currentPage}
|
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}`),
|
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}`)
|
deleteDocument:(id)=>api.delete(`/api/Document/delete/${id}`)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user