From 7eb22bb785912777c92d4dd90e14ecf8fc7ca6e2 Mon Sep 17 00:00:00 2001 From: pramod mahajan Date: Tue, 2 Sep 2025 16:40:04 +0530 Subject: [PATCH] added pagination --- src/components/Documents/DocumentsList.jsx | 47 ++++++++++------------ 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/src/components/Documents/DocumentsList.jsx b/src/components/Documents/DocumentsList.jsx index 69e7d0d1..3fe39a49 100644 --- a/src/components/Documents/DocumentsList.jsx +++ b/src/components/Documents/DocumentsList.jsx @@ -1,4 +1,4 @@ -import React, { useEffect } from "react"; +import React, { useEffect, useState } from "react"; import { useDocumentListByEntityId } from "../../hooks/useDocument"; import { ITEMS_PER_PAGE } from "../../utils/constants"; import Avatar from "../common/Avatar"; @@ -6,25 +6,10 @@ import { formatUTCToLocalTime } from "../../utils/dateUtils"; import Loader from "../common/Loader"; import { useDebounce } from "../../utils/appUtils"; import { DocumentTableSkeleton } from "./DocumentSkeleton"; -import { useDocumentContext } from "./Documents"; +import { getDocuementsStatus, useDocumentContext } from "./Documents"; +import Pagination from "../common/Pagination"; + -export const getDocuementsStatus = (status) => { - switch (status) { - case true: - return ( - Verified - ); - case false: - return ( - Rejected - ); - case null: - default: - return ( - Pending - ); - } -}; const DocumentsList = ({ Document_Entity, Entity, @@ -34,12 +19,13 @@ const DocumentsList = ({ setRefetchFn, }) => { const debouncedSearch = useDebounce(searchText, 500); + const [currentPage,setCurrentPage] = useState(1) const { data, isError, isLoading, error, refetch, isFetching } = useDocumentListByEntityId( Document_Entity, Entity, ITEMS_PER_PAGE, - 1, + currentPage, filters, debouncedSearch ); @@ -54,14 +40,18 @@ const DocumentsList = ({ setIsRefetching(isFetching); }, [isFetching, setIsRefetching]); - const {setManageDoc} = useDocumentContext() + const {setManageDoc,setViewDoc} = useDocumentContext() // check no data scenarios - const noData = !isLoading && !isError && data?.length === 0; + const noData = !isLoading && !isError && data?.data.length === 0; const isSearchEmpty = noData && !!debouncedSearch; const isFilterEmpty = noData && false; const isInitialEmpty = noData && !debouncedSearch; - + const paginate = (page) => { + if (page >= 1 && page <= (data?.totalPages ?? 1)) { + setCurrentPage(page); + } + }; if (isLoading || isFetching) return if (isError) return
Error: {error?.message || "Something went wrong"}
; @@ -138,7 +128,7 @@ const DocumentsList = ({ - {data?.map((doc) => ( + {data?.data?.map((doc) => ( {DocumentColumns.map((col) => ( @@ -147,7 +137,7 @@ const DocumentsList = ({ ))}
- + setViewDoc({document:doc?.id,isOpen:true})}> setManageDoc({document:doc?.id,isOpen:true})}> @@ -158,6 +148,13 @@ const DocumentsList = ({ ))} + {data?.data?.length > 0 && ( + + )}
); };