diff --git a/components/dashboard/ChatTable.tsx b/components/dashboard/ChatTable.tsx index b72c232..7b40376 100644 --- a/components/dashboard/ChatTable.tsx +++ b/components/dashboard/ChatTable.tsx @@ -24,6 +24,13 @@ import { ChevronLeft, ChevronRight } from "lucide-react"; +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from "@/components/ui/select"; import { clientFetch } from "@/lib/client-utils"; import { toast } from "sonner"; import { getCookie } from "@/lib/client-utils"; @@ -59,7 +66,7 @@ export default function ChatTable() { const [currentPage, setCurrentPage] = useState(1); const [totalPages, setTotalPages] = useState(1); const [totalChats, setTotalChats] = useState(0); - const ITEMS_PER_PAGE = 10; + const [itemsPerPage, setItemsPerPage] = useState(10); // Initialize audio element for notifications useEffect(() => { @@ -103,7 +110,7 @@ export default function ChatTable() { return { vendorId, authToken }; }; - // Fetch chats when component mounts or page changes + // Fetch chats when component mounts or page/limit changes useEffect(() => { fetchChats(); @@ -113,7 +120,7 @@ export default function ChatTable() { }, 30000); // Check every 30 seconds return () => clearInterval(interval); - }, [currentPage]); + }, [currentPage, itemsPerPage]); // Fetch unread counts const fetchUnreadCounts = async () => { @@ -146,7 +153,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=${ITEMS_PER_PAGE}`); + const response = await clientFetch(`/chats/vendor/${vendorId}?page=${currentPage}&limit=${itemsPerPage}`); // Check if the response is the old format (array) or new paginated format if (Array.isArray(response)) { @@ -195,6 +202,13 @@ export default function ChatTable() { } }; + // Handle items per page change + const handleItemsPerPageChange = (value: string) => { + const newLimit = parseInt(value); + setItemsPerPage(newLimit); + setCurrentPage(1); // Reset to first page when changing limit + }; + return (
@@ -315,26 +329,45 @@ export default function ChatTable() {
Showing {chats.length} of {totalChats} chats
-
- -
- Page {currentPage} of {totalPages} +
+
+ Rows per page: + +
+
+ +
+ Page {currentPage} of {totalPages} +
+
-
)}