diff --git a/frontend/src/pages/admin/EventsListPage.tsx b/frontend/src/pages/admin/EventsListPage.tsx index 0b8b293a..57379a6a 100644 --- a/frontend/src/pages/admin/EventsListPage.tsx +++ b/frontend/src/pages/admin/EventsListPage.tsx @@ -104,17 +104,6 @@ export const EventsListPage: React.FC = () => { setPage(1); }, [statusFilter, debouncedSearchTerm]); - // Clamp the active page when the result count shrinks (#442 — bulk - // delete of an entire page would leave the user on a now-empty - // page=N where N > totalPages, with no auto-correction). Triggers - // after each successful refetch when totalPages drops below the - // current page (bulk delete, individual delete, archive, anything). - useEffect(() => { - if (data?.pagination && page > data.pagination.totalPages) { - setPage(Math.max(1, data.pagination.totalPages)); - } - }, [data?.pagination, page]); - // Close dropdown when clicking outside useEffect(() => { const handleClickOutside = (event: MouseEvent) => { @@ -157,6 +146,20 @@ export const EventsListPage: React.FC = () => { placeholderData: (prev) => prev, }); + // Clamp the active page when the result count shrinks (#442 — bulk + // delete of an entire page would leave the user on a now-empty + // page=N where N > totalPages, with no auto-correction). Triggers + // after each successful refetch when totalPages drops below the + // current page (bulk delete, individual delete, archive, anything). + // Must live AFTER the useQuery above so `data` is in scope — the + // original placement at the top of the component caused a TDZ + // ReferenceError on /admin/events that crashed the page (#454). + useEffect(() => { + if (data?.pagination && page > data.pagination.totalPages) { + setPage(Math.max(1, data.pagination.totalPages)); + } + }, [data?.pagination, page]); + // Aggregate counters come from the dashboard stats endpoint so the cards // and the "All (N)" filter button always reflect global totals, not the // currently visible page.