From 528d3b756ce46dbddba1f463acde7a7a680c80bb Mon Sep 17 00:00:00 2001 From: pramod mahajan Date: Tue, 2 Sep 2025 20:28:23 +0530 Subject: [PATCH] InActiving documents --- src/components/Documents/DocumentsList.jsx | 159 ++++++++++++++------- src/components/Documents/ViewDocument.jsx | 5 +- src/hooks/useDocument.js | 23 +++ src/repositories/DocumentRepository.jsx | 2 +- 4 files changed, 133 insertions(+), 56 deletions(-) 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
No results found for "{debouncedSearch}"
; if (isFilterEmpty) return
No documents match your filter.
; + const handleDelete = () => { + debugger; + ActiveInActive( + { documentId: deletingId, isActive: false }, + { + onSettled: () => { + setDeletingId(null); + setIsDeleteModalOpen(false); + }, + } + ); + }; const DocumentColumns = [ { key: "name", @@ -113,59 +131,92 @@ const DocumentsList = ({ ]; return ( -
- - - - {DocumentColumns.map((col) => ( - - ))} - - - - - {data?.data?.map((doc) => ( - - {DocumentColumns.map((col) => ( - - ))} - - - ))} - -
- {col.label} - - Action -
- {col.customRender ? col.customRender(doc) : col.getValue(doc)} - -
- - setViewDoc({ document: doc?.id, isOpen: true }) - } - > - - - setManageDoc({ document: doc?.id, isOpen: true }) - } - > - - -
-
- {data?.data?.length > 0 && ( - + <> + {IsDeleteModalOpen && ( +
+ setIsDeleteModalOpen(false)} + loading={isPending} + paramData={deletingId} + /> +
)} -
+ +
+ + + + {DocumentColumns.map((col) => ( + + ))} + + + + + {data?.data?.map((doc) => ( + + {DocumentColumns.map((col) => ( + + ))} + + + ))} + +
+ {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); + }} + > +
+
+ {data?.data?.length > 0 && ( + + )} +
+ ); }; diff --git a/src/components/Documents/ViewDocument.jsx b/src/components/Documents/ViewDocument.jsx index cd84fe78..c0487f69 100644 --- a/src/components/Documents/ViewDocument.jsx +++ b/src/components/Documents/ViewDocument.jsx @@ -40,7 +40,10 @@ const ViewDocument = () => { }; if (isLoading) return ; - if (isError) return
{error.message}
; + if (isError) return
+

{error?.response?.data?.message || error?.message}

+

{error?.response?.status}

+
; return (

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