Date: Thu, 14 May 2026 13:11:44 -0500
Subject: [PATCH 4/5] fix: resolved code rabbit requested changes
---
frontend/src/components/Pagination.tsx | 9 ++++++---
frontend/src/hooks/useUrlPagination.ts | 13 +++++--------
frontend/src/pages/ProgramsPage.tsx | 11 ++++++++++-
3 files changed, 21 insertions(+), 12 deletions(-)
diff --git a/frontend/src/components/Pagination.tsx b/frontend/src/components/Pagination.tsx
index 7032c8003..ef2aa9d6f 100644
--- a/frontend/src/components/Pagination.tsx
+++ b/frontend/src/components/Pagination.tsx
@@ -1,3 +1,4 @@
+import { useId } from 'react';
import { ChevronLeftIcon, ChevronRightIcon } from '@heroicons/react/24/outline';
interface PaginationProps {
@@ -17,8 +18,10 @@ export function Pagination({
onPageChange,
onItemsPerPageChange,
itemLabel = 'items',
- instanceId = 'pagination'
+ instanceId
}: PaginationProps) {
+ const generatedId = useId();
+ const itemsPerPageId = `${instanceId ?? `pagination-${generatedId}`}-items-per-page`;
const totalPages = Math.ceil(totalItems / itemsPerPage);
const startItem = totalItems === 0 ? 0 : (currentPage - 1) * itemsPerPage + 1;
const endItem = Math.min(currentPage * itemsPerPage, totalItems);
@@ -73,11 +76,11 @@ export function Pagination({
-
)}
- {total >= perPage && (
+ {total > 0 && (
= 1 ? parsedPerPage : defaultPerPage;
- const setPage = (newPage: number, options?: { replace?: boolean }) => {
- const params = new URLSearchParams(searchParams);
- params.set(pageKey, newPage.toString());
- setSearchParams(params, { replace: options?.replace ?? false });
- };
+ const setPage = useCallback(
+ (newPage: number, options?: { replace?: boolean }) => {
+ const params = new URLSearchParams(searchParams);
+ params.set(pageKey, newPage.toString());
+ setSearchParams(params, { replace: options?.replace ?? false });
+ },
+ [searchParams, setSearchParams, pageKey]
+ );
- const setPerPage = (newPerPage: number) => {
- const params = new URLSearchParams(searchParams);
- params.set(perPageKey, newPerPage.toString());
- params.set(pageKey, '1');
- setSearchParams(params, { replace: false });
- };
+ const setPerPage = useCallback(
+ (newPerPage: number) => {
+ const params = new URLSearchParams(searchParams);
+ params.set(perPageKey, newPerPage.toString());
+ params.set(pageKey, '1');
+ setSearchParams(params, { replace: false });
+ },
+ [searchParams, setSearchParams, pageKey, perPageKey]
+ );
return { page, perPage, setPage, setPerPage };
}
diff --git a/frontend/src/pages/ClassesPage.tsx b/frontend/src/pages/ClassesPage.tsx
index 1a9e665ba..c868aec67 100644
--- a/frontend/src/pages/ClassesPage.tsx
+++ b/frontend/src/pages/ClassesPage.tsx
@@ -47,7 +47,7 @@ import {
MapPin,
Users
} from 'lucide-react';
-import { Pagination } from '@/components/shared';
+import { Pagination } from '@/components/Pagination';
import { TakeAttendanceModal } from './class-detail/TakeAttendanceModal';
import { BulkCancelClassesModal } from '@/components/BulkCancelClassesModal';
@@ -216,7 +216,7 @@ export default function ClassesPage() {
useEffect(() => {
setCurrentPage(1);
- }, [searchQuery, todayOnly, attendanceConcerns, facilityFilter, programFilter, statusFilter]);
+ }, [searchQuery, todayOnly, attendanceConcerns, facilityFilter, programFilter, statusFilter, setCurrentPage]);
const paginatedClasses = useMemo(() => {
const start = (currentPage - 1) * itemsPerPage;
diff --git a/frontend/src/pages/ProgramsPage.tsx b/frontend/src/pages/ProgramsPage.tsx
index 9a398ba72..5b75ef8b7 100644
--- a/frontend/src/pages/ProgramsPage.tsx
+++ b/frontend/src/pages/ProgramsPage.tsx
@@ -998,7 +998,7 @@ export default function ProgramsPage() {
)}
{/* Pagination */}
- {filtered.length > perPage && (
+ {filtered.length > 0 && (
)}
- {total >= perPage && (
+ {total > 0 && (
{
if (
diff --git a/frontend/src/pages/programs/ProgramOverviewFacilityAdmin.tsx b/frontend/src/pages/programs/ProgramOverviewFacilityAdmin.tsx
index 608ab3640..6bf83c48b 100644
--- a/frontend/src/pages/programs/ProgramOverviewFacilityAdmin.tsx
+++ b/frontend/src/pages/programs/ProgramOverviewFacilityAdmin.tsx
@@ -1408,7 +1408,7 @@ function AuditHistoryTab({
)}
- {totalItems > itemsPerPage && (
+ {totalItems > 0 && (