diff --git a/src/app/(dashboard)/inbox/page.tsx b/src/app/(dashboard)/inbox/page.tsx index 16ee965..7ec3895 100644 --- a/src/app/(dashboard)/inbox/page.tsx +++ b/src/app/(dashboard)/inbox/page.tsx @@ -12,6 +12,10 @@ import { toast } from "sonner"; import { WifiOff } from "lucide-react"; import { cn } from "@/lib/utils"; +// Remembers the agent's show/hide choice for the desktop contact panel +// across reloads and sessions (device-scoped, like the theme prefs). +const CONTACT_PANEL_STORAGE_KEY = "wacrm:inbox:contact-panel-open"; + export default function InboxPage() { const router = useRouter(); const searchParams = useSearchParams(); @@ -39,6 +43,36 @@ export default function InboxPage() { */ const [resyncToken, setResyncToken] = useState(0); + /** + * Whether the desktop contact sidebar (tags / deals / notes) is shown. + * Defaults to `true` (the historical behaviour) and is restored from + * localStorage after mount. We deliberately do NOT read localStorage in + * the initializer: the server renders with `true`, so reading a stored + * `false` synchronously would produce a hydration mismatch. The effect + * below reconciles to the stored value right after mount instead. + */ + const [contactPanelOpen, setContactPanelOpen] = useState(true); + useEffect(() => { + try { + const stored = localStorage.getItem(CONTACT_PANEL_STORAGE_KEY); + if (stored !== null) setContactPanelOpen(stored === "true"); + } catch { + // localStorage can throw in private-browsing / sandboxed contexts. + } + }, []); + + const handleToggleContactPanel = useCallback(() => { + setContactPanelOpen((prev) => { + const next = !prev; + try { + localStorage.setItem(CONTACT_PANEL_STORAGE_KEY, String(next)); + } catch { + // Persistence is best-effort; ignore storage failures. + } + return next; + }); + }, []); + // Fire the deep-link auto-select exactly once per URL — subsequent // list refreshes (realtime, manual refetch) must not snap the user // back to the deep-linked conversation if they've already clicked @@ -570,13 +604,20 @@ export default function InboxPage() { onBack={handleCloseConversation} resyncToken={resyncToken} onRefresh={handleManualRefresh} + contactPanelOpen={contactPanelOpen} + onToggleContactPanel={handleToggleContactPanel} /> - {/* Right panel: Contact sidebar — desktop only. */} -