'use client'; import { useEffect, useState } from 'react'; import { Bell, ChevronDown, ShieldAlert } from 'lucide-react'; import { cn } from '@/lib/utils'; import { PageHeader } from '@/components/shared/page-header'; import { AlertsPageShell } from '@/components/alerts/alerts-page-shell'; import { ReminderList } from '@/components/reminders/reminder-list'; import { useAlertCount } from '@/components/alerts/use-alerts'; /** * Merged "Inbox" surface — replaces the previously-separate /alerts and * /reminders pages. Two stacked sections (Alerts first, Reminders second) * preserve the source distinction (system-flagged vs user-set) while * giving reps a single "things demanding my attention" surface. * * Sections are collapsible; collapsed state persists in localStorage per * section so reps can default to the layout they prefer. * * URL anchors: * /inbox#alerts → ensures Alerts section is expanded + scrolls to it * /inbox#reminders → ensures Reminders section is expanded + scrolls to it * * The legacy /alerts and /reminders routes redirect here with the * appropriate hash, so old bookmarks land in the right place. */ export function InboxPageShell() { const [alertsOpen, setAlertsOpen] = useState(true); const [remindersOpen, setRemindersOpen] = useState(true); const { data: alertCount } = useAlertCount(); // Hydrate collapsed state from localStorage on mount. Stored as // 'true'/'false' strings; missing keys default to expanded. useEffect(() => { const a = localStorage.getItem('inbox.alerts.open'); const r = localStorage.getItem('inbox.reminders.open'); if (a === 'false') setAlertsOpen(false); if (r === 'false') setRemindersOpen(false); }, []); // Honor URL hash: ensure the targeted section is expanded then scroll. // Runs once on mount AND on hashchange so deep-linking from another tab // / page works the same as initial navigation. useEffect(() => { function applyHash() { const hash = window.location.hash.replace('#', ''); if (hash === 'alerts') { setAlertsOpen(true); document.getElementById('inbox-section-alerts')?.scrollIntoView({ behavior: 'smooth' }); } else if (hash === 'reminders') { setRemindersOpen(true); document.getElementById('inbox-section-reminders')?.scrollIntoView({ behavior: 'smooth' }); } } applyHash(); window.addEventListener('hashchange', applyHash); return () => window.removeEventListener('hashchange', applyHash); }, []); function toggleAlerts() { const next = !alertsOpen; setAlertsOpen(next); localStorage.setItem('inbox.alerts.open', String(next)); } function toggleReminders() { const next = !remindersOpen; setRemindersOpen(next); localStorage.setItem('inbox.reminders.open', String(next)); } const activeAlerts = alertCount?.total ?? 0; return (
} label="Alerts" count={activeAlerts} open={alertsOpen} onToggle={toggleAlerts} /> {alertsOpen ? (
) : null}
} label="Reminders" open={remindersOpen} onToggle={toggleReminders} /> {remindersOpen ? (
) : null}
); } function SectionHeader({ icon, label, count, open, onToggle, }: { icon: React.ReactNode; label: string; count?: number; open: boolean; onToggle: () => void; }) { return ( ); }