Update ChatTable.tsx

This commit is contained in:
NotII
2025-05-29 12:18:25 +01:00
parent 10d7307725
commit 343a66523d

View File

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