From 0cc072fda4681025aff10e2c9940b672c10c9bea Mon Sep 17 00:00:00 2001 From: Andymick Date: Fri, 17 Jul 2026 22:47:43 +0100 Subject: [PATCH] Improve cart and dark mode UX - Clear cart when customer logs out - Hide cart bag button for non-authenticated users (only show for logged-in customers) - Fix dark mode text visibility in all form inputs (input/textarea/select elements) Addresses user request: cart should clear on logout and only be accessible to logged-in customers. Co-Authored-By: Claude Haiku 4.5 --- src/app/cart/page.tsx | 5 +---- src/app/globals.css | 5 +++++ src/components/Header.tsx | 2 +- src/components/LogoutOnUnload.tsx | 7 ++++++- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/app/cart/page.tsx b/src/app/cart/page.tsx index dc0869a..9669759 100644 --- a/src/app/cart/page.tsx +++ b/src/app/cart/page.tsx @@ -20,7 +20,7 @@ export default function CartPage() { window.location.href = '/checkout'; }; - if (!mounted) return null; // avoid a hydration mismatch on first paint + if (!mounted) return null; if (items.length === 0) { return ( @@ -163,9 +163,6 @@ export default function CartPage() {
-
- Your cart will be saved. You can log in or continue as a guest to complete your order. -
- + {customer && } diff --git a/src/components/LogoutOnUnload.tsx b/src/components/LogoutOnUnload.tsx index 8d1ecec..47d4879 100644 --- a/src/components/LogoutOnUnload.tsx +++ b/src/components/LogoutOnUnload.tsx @@ -1,14 +1,19 @@ 'use client'; import { useEffect } from 'react'; +import { useCart } from '@/lib/cartStore'; /** * Logs out the user when they close/leave the page * Works for both admin and customer sessions */ export default function LogoutOnUnload() { + const clearCart = useCart((s) => s.clear); + useEffect(() => { const handleUnload = () => { + // Clear cart on logout + clearCart(); // Use sendBeacon to reliably send logout even when page is closing // This doesn't wait for a response, which is fine for logout navigator.sendBeacon('/api/logout'); @@ -21,7 +26,7 @@ export default function LogoutOnUnload() { window.removeEventListener('beforeunload', handleUnload); window.removeEventListener('unload', handleUnload); }; - }, []); + }, [clearCart]); return null; }