diff --git a/src/app/admin/bookings/page.tsx b/src/app/admin/bookings/page.tsx index 368d06a..4b38aa3 100644 --- a/src/app/admin/bookings/page.tsx +++ b/src/app/admin/bookings/page.tsx @@ -699,29 +699,24 @@ function BookingsPageInner() { const [addOpen, setAddOpen] = useState(false); const [searchResults, setSearchResults] = useState(null); const [statusFilter, setStatusFilter] = useState("all"); - const [newBookingsBanner, setNewBookingsBanner] = useState(false); + const [refreshKey, setRefreshKey] = useState(0); const lastTotalRef = useRef(null); const { showError } = useToast(); - // #10: Pause polling when browser tab not visible + // Poll for new bookings, auto-refresh silently useEffect(() => { - let id: ReturnType; - function startPolling() { - id = setInterval(() => { - if (document.hidden) return; - adminFetch("/api/admin/unread-counts") - .then((r) => r.json()) - .then((data: { total: number }) => { - if (lastTotalRef.current !== null && data.total !== lastTotalRef.current) { - // #6: Show banner instead of remounting with key - setNewBookingsBanner(true); - } - lastTotalRef.current = data.total; - }) - .catch(() => {}); - }, 10000); - } - startPolling(); + const id = setInterval(() => { + if (document.hidden) return; + adminFetch("/api/admin/unread-counts") + .then((r) => r.json()) + .then((data: { total: number }) => { + if (lastTotalRef.current !== null && data.total !== lastTotalRef.current) { + setRefreshKey((k) => k + 1); + } + lastTotalRef.current = data.total; + }) + .catch(() => {}); + }, 10000); return () => clearInterval(id); }, []); @@ -772,16 +767,6 @@ function BookingsPageInner() { - {/* #6: New bookings banner instead of full remount */} - {newBookingsBanner && ( - - )} - {/* Search */}
{/* Dashboard — what needs attention */} - + {/* Tabs */}
@@ -851,8 +836,8 @@ function BookingsPageInner() { ))}
- {/* Tab content — no key={refreshKey}, banner handles new data */} -
+ {/* Tab content — auto-refreshes when new bookings detected */} +
{tab === "reminders" && } {tab === "classes" && } {tab === "master-classes" && } @@ -864,7 +849,7 @@ function BookingsPageInner() { setAddOpen(false)} - onAdded={() => setNewBookingsBanner(true)} + onAdded={() => setRefreshKey((k) => k + 1)} />
);