Fix navbar/discount/invoice bugs from manual QA, add VAT breakdown, shipping-address override, checkout persistence, redesigned mobile menu

Bug fixes:
- Navbar login/logout state now updates immediately (custom ep-auth-changed
  event) instead of requiring a hard reload
- Status-change email links were broken by an un-encoded "#" in the order
  number; fixed for all 4 status emails
- Cart discount code: manual input field restored (was removed entirely)
- Quote-label underline now scales with the label's actual text width
- Number Ranges admin list now shows the invoice prefix/counter columns

Pricing & VAT:
- Prices show the real per-product VAT rate ("inkl. X% MwSt.") instead of
  a generic disclosure
- Cart/checkout/confirmation totals show the actual € amount of VAT
  included, broken down per rate when a cart spans more than one
  (new lib/taxBreakdown.ts, shared with the invoice PDF's own math)
- Account order pages gained product thumbnails and the same VAT breakdown

Low-stock warning: a "Nur noch wenige verfügbar" badge/hint across the
shop grid, spotlight, and add-to-cart variant pickers, driven by the
existing lowStockThreshold field (still never exposes raw stock counts).

Invoice PDFs: product thumbnails on every line item, a plain "Netto"
label (rate was redundant, already stated on the MwSt. line below), no
more duplicate USt-IdNr. in the header, and — for a Stornorechnung
specifically — an explicit "Versand" line that was previously only
folded silently into the tax totals.

Checkout:
- Optional deviating shipping address (separate from the billing address
  used for the invoice), with its own toggle + address form
- Full checkout draft persistence (name/address/shipping/payment
  selections) survives navigating away and back, via localStorage
- Invoice PDF shows a third "Lieferadresse" block when the shipping
  address differs from billing

Mobile navigation: fullscreen panel with a circular reveal animation from
the hamburger's corner, replacing the old in-flow accordion drawer; no
login CTA inside it (redundant with the always-visible header icon).

Admin-facing (Payload backend, mirrored where the frontend has a ported
copy of the same renderer): dashboard rebuilt as individual cards, split
into 3 task queues (received/processing/returns) instead of 2, revenue
and order counts now exclude cancelled/returned orders immediately, and
the low-stock alert links to the specific affected product(s) instead of
the unfiltered list. A new immediate email notifies the shop owner the
moment an order comes in, instead of only via the daily digest.

Testimonials admin list now groups by page instead of interleaving all
three grids' entries. ~45 English admin field descriptions translated to
German for consistency.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Marco
2026-07-22 22:52:15 +00:00
parent 7a9fed6f95
commit 43944d8cc8
39 changed files with 1435 additions and 306 deletions
+168 -124
View File
@@ -4,7 +4,9 @@ import { useEffect, useMemo, useRef, useState } from "react";
import Link from "next/link";
import Image from "next/image";
import { usePathname } from "next/navigation";
import { AnimatePresence, motion } from "motion/react";
import { useCartCount } from "../lib/cart";
import { AUTH_CHANGED_EVENT } from "../lib/auth";
import { NewsletterModal } from "./NewsletterModal";
import { useCartFly } from "./CartFly";
@@ -82,28 +84,29 @@ function isNavLinkActive(href: string, pathname: string, activeSection: string):
// and reading the session cookie there (next/headers' cookies()) would
// force the entire site into per-request dynamic rendering just for this.
// `loggedIn === null` is the brief "not checked yet" state on first paint.
function AccountLink({ variant }: { variant: "icon" | "mobile" }) {
function AccountLink() {
const [loggedIn, setLoggedIn] = useState<boolean | null>(null);
useEffect(() => {
fetch("/api/account/me")
.then((res) => setLoggedIn(res.ok))
.catch(() => setLoggedIn(false));
function checkAuth() {
fetch("/api/account/me")
.then((res) => setLoggedIn(res.ok))
.catch(() => setLoggedIn(false));
}
checkAuth();
// Navbar lives in the root layout and never unmounts across
// navigations, so this effect only ever runs once on its own —
// router.refresh() (called after login/logout) re-fetches Server
// Component data but doesn't re-run an already-mounted Client
// Component's effects. AUTH_CHANGED_EVENT is dispatched explicitly by
// every login/logout call site (see dispatchAuthChanged() in
// ../lib/auth) so this stays in sync without a hard reload.
window.addEventListener(AUTH_CHANGED_EVENT, checkAuth);
return () => window.removeEventListener(AUTH_CHANGED_EVENT, checkAuth);
}, []);
const href = loggedIn ? "/konto/bestellungen" : "/konto/login";
if (variant === "mobile") {
return (
<Link
href={href}
className="min-h-11 flex items-center justify-center px-6 py-4 rounded-sm border border-[#868686] text-h4 font-bold text-text-primary hover:border-brand hover:text-brand active:scale-[0.97] transition-all"
>
{loggedIn ? "Mein Konto" : "Anmelden"}
</Link>
);
}
return (
<Link
href={href}
@@ -327,6 +330,32 @@ export function Navbar({ singleActiveProduct }: { singleActiveProduct: boolean }
return () => document.removeEventListener("keydown", onKeyDown);
}, [mobileOpen]);
// Background scroll lock while the fullscreen panel is open — same
// wheel/touchmove interception as NewsletterModal.tsx (see that
// component's own comment on why this approach over overflow:hidden or
// position:fixed on body). Needed now that the panel actually covers the
// viewport instead of pushing page content down in normal flow.
useEffect(() => {
if (!mobileOpen) return;
const isInsidePanel = (target: EventTarget | null) =>
target instanceof Node && !!panelRef.current?.contains(target);
const onWheel = (e: WheelEvent) => {
if (!isInsidePanel(e.target)) e.preventDefault();
};
const onTouchMove = (e: TouchEvent) => {
if (!isInsidePanel(e.target)) e.preventDefault();
};
document.addEventListener("wheel", onWheel, { passive: false });
document.addEventListener("touchmove", onTouchMove, { passive: false });
return () => {
document.removeEventListener("wheel", onWheel);
document.removeEventListener("touchmove", onTouchMove);
};
}, [mobileOpen]);
const closeMobile = () => setMobileOpen(false);
return (
@@ -345,18 +374,11 @@ export function Navbar({ singleActiveProduct }: { singleActiveProduct: boolean }
// position itself.
<>
<header
// min-h-, not a fixed h- — the fixed height used to cap this flex
// column at exactly 6.25rem regardless of content. The top row below
// has shrink-0 (always fills all 6.25rem on its own), so the mobile
// drawer panel — the column's only other child — had zero room left.
// Flex items default to `min-height: auto` (their own content size),
// which normally would've still forced the column taller — but the
// panel's own `overflow-hidden` (needed for its open/close animation)
// resets that automatic minimum to 0 per spec, so flexbox was free to
// crush it to a literal 0px box instead of pushing the header taller.
// The hamburger icon itself was never the problem — it toggled to "X"
// correctly; the panel it opens was rendering at zero height beneath it.
className={`sticky top-0 z-50 w-full min-h-[6.25rem] flex flex-col transition-[background-color,backdrop-filter] duration-300 ${
// The mobile panel used to be a child of this element and needed the
// header itself to be a flexible column that could grow for it — it's
// now a fixed-position sibling instead (see that panel's own comment
// on why), so this is back to a plain fixed-height bar.
className={`sticky top-0 z-50 w-full h-[6.25rem] transition-[background-color,backdrop-filter] duration-300 ${
scrolled || mobileOpen
? "bg-bg-base/80 backdrop-blur-md"
: "bg-bg-base"
@@ -453,7 +475,7 @@ export function Navbar({ singleActiveProduct }: { singleActiveProduct: boolean }
(below lg). Grouped so spacing stays consistent as individual
children hide/show across the three breakpoint tiers. */}
<div className="flex items-center gap-2">
<AccountLink variant="icon" />
<AccountLink />
<CartLink />
{/* CTA buttons — inline from md (768px) up, i.e. through both
@@ -513,104 +535,126 @@ export function Navbar({ singleActiveProduct }: { singleActiveProduct: boolean }
</div>
</div>
{/* Mobile drawer panel — toggleable below lg (see hamburger above).
`grid-rows-[0fr]/[1fr]` (not a guessed max-h-[Nrem]) is what
actually animates the open/close height — a CSS grid row sized in
`fr` units transitions smoothly between 0 and its content's real
height with no fixed cap to guess/outgrow, the modern replacement
for the old max-height-accordion trick. `overflow-hidden` has to
live on the *inner* div, not this one — collapsing a 0fr grid row
already clips its content on its own, and this outer element is
also where the opacity/translate fade below is applied, which
must NOT itself be clipped (a translateY sliding a hidden/clipped
element in doesn't read as a fade-in, just a hard cut). */}
<div
id="mobile-nav-panel"
ref={panelRef}
className={`lg:hidden grid w-full transition-[grid-template-rows] duration-300 ease-in-out ${
mobileOpen ? "grid-rows-[1fr]" : "grid-rows-[0fr]"
}`}
>
<div
className={`overflow-hidden transition-[opacity,transform] duration-300 ease-out ${
mobileOpen ? "opacity-100 translate-y-0 delay-100" : "opacity-0 -translate-y-2"
}`}
>
<nav className="flex flex-col gap-6 px-8 pt-2 pb-6">
{navLinks.map((link) => {
const isActive = isNavLinkActive(link.href, pathname, activeSection);
const isHomeAnchor = link.href.startsWith("#") && pathname === "/";
const resolvedHref = link.href.startsWith("#") && pathname !== "/" ? `/${link.href}` : link.href;
return link.href.startsWith("#") ? (
<Link
key={link.href}
href={resolvedHref}
onClick={
isHomeAnchor
? (e) => {
e.preventDefault();
closeMobile();
const el = document.getElementById(link.href.slice(1));
if (el) {
const top = el.getBoundingClientRect().top + window.scrollY - NAVBAR_HEIGHT;
smoothScrollTo(top);
}
history.replaceState(null, "", link.href);
}
: closeMobile
}
className="min-h-11 flex flex-col justify-center gap-1 text-h4 font-semibold text-text-primary w-fit"
>
{link.label}
<span
className={`h-[2px] bg-brand transition-opacity duration-200 ${
isActive ? "w-10 opacity-100" : "w-10 opacity-0"
}`}
/>
</Link>
) : (
<Link
key={link.href}
href={link.href}
onClick={closeMobile}
className="min-h-11 flex items-center text-h4 font-semibold text-text-primary"
>
{link.label}
</Link>
);
})}
</nav>
<div className="flex flex-col gap-3 px-8 pb-8">
{/* md:hidden — these two duplicate the inline CTA pair that's
already visible in the header itself from md (768px) up (see
"Trailing controls" above); only genuinely missing below
that, where the inline pair is hidden and the drawer is
these buttons' only way to reach them. */}
<button
type="button"
onClick={() => {
closeMobile();
setNewsletterOpen(true);
}}
className="md:hidden min-h-11 flex items-center justify-center px-6 py-4 rounded-sm border border-[#868686] text-h4 font-bold text-text-primary hover:border-brand hover:text-brand active:scale-[0.97] transition-all"
>
Newsletter
</button>
<Link
href="/challenge"
onClick={closeMobile}
className="md:hidden min-h-11 flex items-center justify-center px-6 py-4 rounded-sm bg-brand text-h4 font-bold text-text-primary hover:bg-brand-hover active:scale-[0.97] transition-all"
>
7-Tage-Challenge
</Link>
<div onClick={closeMobile}>
<AccountLink variant="mobile" />
</div>
</div>
</div>
</div>
</header>
{/* Fullscreen mobile panel — a sibling of <header>, deliberately NOT
nested inside it (same reason as NewsletterModal, see the
top-of-file comment: `mobileOpen` gives the header its own
backdrop-blur, which would make it a new containing block for any
`position: fixed` descendant and break the panel's fixed-to-
viewport positioning). Circular clip-path reveal expanding from
the hamburger's own corner (top-right) — the growing circle
naturally sweeps toward the opposite corner (bottom-left) last,
reading as the diagonal wipe this is going for without needing a
literal diagonal clip polygon. `vmax` (not %) for the radius so
full coverage holds regardless of viewport aspect ratio. */}
<AnimatePresence>
{mobileOpen && (
<motion.div
id="mobile-nav-panel"
ref={panelRef}
className="lg:hidden fixed inset-0 z-40 bg-bg-base overflow-y-auto"
initial={{ clipPath: "circle(0vmax at 100% 0%)" }}
animate={{ clipPath: "circle(150vmax at 100% 0%)" }}
exit={{ clipPath: "circle(0vmax at 100% 0%)" }}
transition={{ duration: 0.5, ease: [0.22, 1, 0.36, 1] }}
>
<div className="flex flex-col min-h-full pt-[6.25rem]">
<nav className="flex flex-col flex-1 items-center justify-center gap-6 px-8 py-10 text-center">
{navLinks.map((link, i) => {
const isActive = isNavLinkActive(link.href, pathname, activeSection);
const isHomeAnchor = link.href.startsWith("#") && pathname === "/";
const resolvedHref = link.href.startsWith("#") && pathname !== "/" ? `/${link.href}` : link.href;
// Staggered fade+rise entrance, timed to land after the
// clip-path reveal has visibly opened up — same
// "fancy but restrained" register as the rest of this
// codebase's motion usage (Reveal.tsx et al.), not a
// separate animation language just for this panel.
const linkMotionProps = {
initial: { opacity: 0, y: 12 },
animate: { opacity: 1, y: 0 },
transition: { delay: 0.15 + i * 0.05, duration: 0.3, ease: "easeOut" as const },
};
return link.href.startsWith("#") ? (
<motion.div key={link.href} {...linkMotionProps}>
<Link
href={resolvedHref}
onClick={
isHomeAnchor
? (e) => {
e.preventDefault();
closeMobile();
const el = document.getElementById(link.href.slice(1));
if (el) {
const top = el.getBoundingClientRect().top + window.scrollY - NAVBAR_HEIGHT;
smoothScrollTo(top);
}
history.replaceState(null, "", link.href);
}
: closeMobile
}
className="min-h-11 flex flex-col justify-center gap-1 text-h-feature font-semibold text-text-primary w-fit"
style={{ fontFamily: "var(--font-lora)" }}
>
{link.label}
<span
className={`h-[2px] bg-brand transition-opacity duration-200 ${
isActive ? "w-10 opacity-100" : "w-10 opacity-0"
}`}
/>
</Link>
</motion.div>
) : (
<motion.div key={link.href} {...linkMotionProps}>
<Link
href={link.href}
onClick={closeMobile}
className="min-h-11 flex items-center text-h-feature font-semibold text-text-primary"
style={{ fontFamily: "var(--font-lora)" }}
>
{link.label}
</Link>
</motion.div>
);
})}
</nav>
<motion.div
initial={{ opacity: 0, y: 12 }}
animate={{ opacity: 1, y: 0 }}
transition={{ delay: 0.15 + navLinks.length * 0.05, duration: 0.3, ease: "easeOut" }}
className="flex flex-col gap-3 px-8 pb-16 pt-10"
>
{/* md:hidden — these two duplicate the inline CTA pair that's
already visible in the header itself from md (768px) up (see
"Trailing controls" above); only genuinely missing below
that, where the inline pair is hidden and the panel is
these buttons' only way to reach them. No login/account CTA
here (removed — Nutzer-Entscheidung: that's already reachable
via the account icon in the header itself, outside this
panel, no need to duplicate it inside). */}
<button
type="button"
onClick={() => {
closeMobile();
setNewsletterOpen(true);
}}
className="md:hidden min-h-11 flex items-center justify-center px-6 py-4 rounded-sm border border-[#868686] text-h4 font-bold text-text-primary hover:border-brand hover:text-brand active:scale-[0.97] transition-all"
>
Newsletter
</button>
<Link
href="/challenge"
onClick={closeMobile}
className="md:hidden min-h-11 flex items-center justify-center px-6 py-4 rounded-sm bg-brand text-h4 font-bold text-text-primary hover:bg-brand-hover active:scale-[0.97] transition-all"
>
7-Tage-Challenge
</Link>
</motion.div>
</div>
</motion.div>
)}
</AnimatePresence>
<NewsletterModal open={newsletterOpen} onClose={() => setNewsletterOpen(false)} />
</>
);