diff --git a/components/dashboard/ChatTable.tsx b/components/dashboard/ChatTable.tsx index add4a76..ec2327b 100644 --- a/components/dashboard/ChatTable.tsx +++ b/components/dashboard/ChatTable.tsx @@ -169,7 +169,7 @@ export default function ChatTable() { }; // Fetch chats with pagination - const fetchChats = async () => { + const fetchChats = async (page = currentPage, limit = itemsPerPage) => { setLoading(true); try { @@ -177,7 +177,7 @@ export default function ChatTable() { const { vendorId } = getVendorIdFromToken(); // Now fetch chats for this vendor using clientFetch with pagination - const response = await clientFetch(`/chats/vendor/${vendorId}?page=${currentPage}&limit=${itemsPerPage}`); + const response = await clientFetch(`/chats/vendor/${vendorId}?page=${page}&limit=${limit}`); // Check if the response is the old format (array) or new paginated format if (Array.isArray(response)) { @@ -217,16 +217,18 @@ export default function ChatTable() { const goToNextPage = () => { if (currentPage < totalPages) { isManualRefresh.current = true; - setCurrentPage(prev => prev + 1); - fetchChats(); + const nextPage = currentPage + 1; + setCurrentPage(nextPage); + fetchChats(nextPage); } }; const goToPrevPage = () => { if (currentPage > 1) { isManualRefresh.current = true; - setCurrentPage(prev => prev - 1); - fetchChats(); + const prevPage = currentPage - 1; + setCurrentPage(prevPage); + fetchChats(prevPage); } }; @@ -236,7 +238,7 @@ export default function ChatTable() { isManualRefresh.current = true; setItemsPerPage(newLimit); setCurrentPage(1); // Reset to first page when changing limit - fetchChats(); + fetchChats(1, newLimit); }; return (