diff --git a/src/components/Documents/DocumentsList.jsx b/src/components/Documents/DocumentsList.jsx index 7cc64e53..2a9b8879 100644 --- a/src/components/Documents/DocumentsList.jsx +++ b/src/components/Documents/DocumentsList.jsx @@ -1,5 +1,8 @@ import React, { useEffect, useState } from "react"; -import { useDocumentListByEntityId } from "../../hooks/useDocument"; +import { + useActiveInActiveDocument, + useDocumentListByEntityId, +} from "../../hooks/useDocument"; import { ITEMS_PER_PAGE } from "../../utils/constants"; import Avatar from "../common/Avatar"; import { formatUTCToLocalTime } from "../../utils/dateUtils"; @@ -8,6 +11,7 @@ import { useDebounce } from "../../utils/appUtils"; import { DocumentTableSkeleton } from "./DocumentSkeleton"; import { getDocuementsStatus, useDocumentContext } from "./Documents"; import Pagination from "../common/Pagination"; +import ConfirmModal from "../common/ConfirmModal"; const DocumentsList = ({ Document_Entity, @@ -17,6 +21,8 @@ const DocumentsList = ({ setIsRefetching, setRefetchFn, }) => { + const [IsDeleteModalOpen, setIsDeleteModalOpen] = useState(false); + const [deletingId, setDeletingId] = useState(null); const debouncedSearch = useDebounce(searchText, 500); const [currentPage, setCurrentPage] = useState(1); const { data, isError, isLoading, error, refetch, isFetching } = @@ -40,7 +46,7 @@ const DocumentsList = ({ }, [isFetching, setIsRefetching]); const { setManageDoc, setViewDoc } = useDocumentContext(); - + const { mutate: ActiveInActive, isPending } = useActiveInActiveDocument(); const paginate = (page) => { if (page >= 1 && page <= (data?.totalPages ?? 1)) { setCurrentPage(page); @@ -59,6 +65,18 @@ const DocumentsList = ({ if (isSearchEmpty) return
- {col.label} - | - ))} -- Action - | -
---|---|
- {col.customRender ? col.customRender(doc) : col.getValue(doc)} - | - ))} -
-
-
- setViewDoc({ document: doc?.id, isOpen: true })
- }
- >
-
-
- setManageDoc({ document: doc?.id, isOpen: true })
- }
- >
-
-
-
- |
-
+ {col.label} + | + ))} ++ Action + | +
---|---|
+ {col.customRender + ? col.customRender(doc) + : col.getValue(doc)} + | + ))} +
+
+
+ setViewDoc({ document: doc?.id, isOpen: true })
+ }
+ >
+
+
+ setManageDoc({ document: doc?.id, isOpen: true })
+ }
+ >
+
+ {
+ setIsDeleteModalOpen(true);
+ setDeletingId(doc?.id);
+ }}
+ >
+
+ |
+
{error?.response?.data?.message || error?.message}
+{error?.response?.status}
+Document Details
diff --git a/src/hooks/useDocument.js b/src/hooks/useDocument.js index d4a9eb71..15c1f304 100644 --- a/src/hooks/useDocument.js +++ b/src/hooks/useDocument.js @@ -164,5 +164,28 @@ export const useVerifyDocument = ()=>{ ); }, + }) +} + +export const useActiveInActiveDocument = ()=>{ + const queryClient = useQueryClient(); + return useMutation({ + mutationFn:async({documentId,isActive}) => await DocumentRepository.deleteDocument(documentId,isActive), + onSuccess: (data, variables) => { + 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" + ); + }, + }) } \ No newline at end of file diff --git a/src/repositories/DocumentRepository.jsx b/src/repositories/DocumentRepository.jsx index 31da97cb..c7c78d57 100644 --- a/src/repositories/DocumentRepository.jsx +++ b/src/repositories/DocumentRepository.jsx @@ -18,7 +18,7 @@ export const DocumentRepository = { verifyDocument:(id,isVerify)=>api.post(`/api/Document/verify/${id}/?isVerify=${isVerify}`), - deleteDocument:(id)=>api.delete(`/api/Document/delete/${id}`) + deleteDocument:(id,isActive)=>api.delete(`/api/Document/delete/${id}/?isActive=${isActive}`) } \ No newline at end of file