Files
co-lite/solvway-customer-portal/app/components/AppHeader.tsx
T
ngqileandClaude Opus 5.5 5ee51d1913 chore: copy kept Tastefully modules and portals into Co-Lite
Backend modules from tastefully 8bd93d15: core-libs, core-session,
api-gateway, mobile-api, services-auth, services-system,
services-counter, services-member, services-log, services-email.
solvway-admin-portal from babyboo f64d096ea, solvway-customer-portal
from tastefully 8bd93d15. Copied as tracked files only.

Literal secrets replaced with environment placeholders:
- services-email: SMTP_PASSWORD, MAILGUN_API_KEY, SENDGRID_API_KEY,
  MAILJET_API_KEY, MAILJET_SECRET_KEY (optional, empty default)
- services-system: JUMIO_TOKEN, JUMIO_SECRET (optional)
- services-auth: USER_AUTH_API_SECRET (required); commented JWT secret removed
- core-libs: JWT_TOKEN default removed (required), XXL_JOB_TOKEN default
  removed, ipgeolocation key read from IPGEOLOCATION_API_KEY
- services-system EkycAppConfig: commented Jumio credentials removed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
2026-11-26 15:55:45 +08:00

122 lines
4.9 KiB
TypeScript

"use client";
import { motion, AnimatePresence } from "framer-motion";
import Link from "next/link";
import { usePathname, useRouter } from "next/navigation";
import { Sun, Moon, ArrowLeft } from "lucide-react";
import { useTheme } from "@/app/lib/ThemeContext";
import TastefullyLogo from "@/app/components/TastefullyLogo";
const EXACT_SUB_PAGES: Record<string, string> = {
"/store/history": "Points History",
"/settings/profile": "My Profile",
"/settings/change-password": "Change Password",
"/settings/transactions": "Transactions",
"/settings/referral": "Referral",
// Pages opened from a Home tile: back arrow + title, never the logo (TASTE-148).
"/draw": "Lucky Draw",
"/attendance": "Attendance",
"/goodie-bag": "Welcome Gift",
"/stage": "Stage",
"/floorplan": "Floor Plan",
};
function getSubTitle(pathname: string): string | null {
if (pathname in EXACT_SUB_PAGES) return EXACT_SUB_PAGES[pathname];
return null;
}
const AUTH_PATHS = new Set(["/login", "/register", "/forgot-password", "/register/verify", "/reset-password"]);
export default function AppHeader() {
const pathname = usePathname();
const router = useRouter();
const { isDark, toggle } = useTheme();
if (AUTH_PATHS.has(pathname)) return null;
const subTitle = getSubTitle(pathname);
const isSubPage = Boolean(subTitle);
const borderColor = isDark ? "rgba(255,255,255,0.06)" : "rgba(0,0,0,0.06)";
const cardBg = isDark ? "rgba(255,255,255,0.05)" : "rgba(0,0,0,0.04)";
const cardBorder = isDark ? "rgba(255,255,255,0.08)" : "rgba(0,0,0,0.07)";
const cardShadow = isDark ? "0 1px 6px rgba(0,0,0,0.25)" : "0 1px 4px rgba(0,0,0,0.05)";
const textColor = isDark ? "#FFFFFF" : "#1a1a1a";
const textSec = isDark ? "rgba(255,255,255,0.8)" : "#5C5C5C";
return (
<header
className="flex items-center justify-between px-4 min-h-14 flex-shrink-0 z-40 pt-[env(safe-area-inset-top)]"
style={{
background: "var(--bg-primary)",
borderBottom: `1px solid ${borderColor}`,
}}
>
{/* Left — logo or back + title */}
<AnimatePresence mode="wait">
{isSubPage ? (
<motion.div
key="sub"
className="flex items-center gap-2.5"
initial={{ opacity: 0, x: -10 }}
animate={{ opacity: 1, x: 0 }}
exit={{ opacity: 0, x: -10 }}
transition={{ type: "spring", stiffness: 380, damping: 28 }}
>
<motion.button
onClick={() => router.back()}
aria-label="Back"
whileTap={{ scale: 0.88 }}
transition={{ type: "spring", stiffness: 420, damping: 24 }}
className="w-8 h-8 rounded-xl flex items-center justify-center"
style={{ background: cardBg, border: `1px solid ${cardBorder}`, boxShadow: cardShadow }}
>
<ArrowLeft strokeWidth={2} className="w-4 h-4" style={{ stroke: textColor }} />
</motion.button>
<span className="text-sm font-bold" style={{ color: textColor }}>{subTitle}</span>
</motion.div>
) : (
<motion.div
key="logo"
initial={{ opacity: 0, x: -10 }}
animate={{ opacity: 1, x: 0 }}
exit={{ opacity: 0, x: -10 }}
transition={{ type: "spring", stiffness: 380, damping: 28 }}
>
<Link href="/" aria-label="Go to home" className="inline-flex items-center">
<TastefullyLogo className={pathname === "/" ? "h-[30px] w-auto" : "h-6 w-auto"} />
</Link>
</motion.div>
)}
</AnimatePresence>
{/* Right — theme toggle (always present) */}
<motion.button
onClick={toggle}
aria-label={isDark ? "Switch to light mode" : "Switch to dark mode"}
whileTap={{ scale: 0.88, rotate: isDark ? -20 : 20 }}
transition={{ type: "spring", stiffness: 400, damping: 22 }}
className="w-9 h-9 rounded-xl flex items-center justify-center"
style={{ background: cardBg, border: `1px solid ${cardBorder}`, boxShadow: cardShadow }}
>
<AnimatePresence mode="wait">
{isDark ? (
<motion.div key="sun"
initial={{ scale: 0, rotate: -90 }} animate={{ scale: 1, rotate: 0 }}
exit={{ scale: 0, rotate: 90 }} transition={{ duration: 0.16 }}>
<Sun strokeWidth={2} className="w-4 h-4 stroke-tastefullyOrange" />
</motion.div>
) : (
<motion.div key="moon"
initial={{ scale: 0, rotate: 90 }} animate={{ scale: 1, rotate: 0 }}
exit={{ scale: 0, rotate: -90 }} transition={{ duration: 0.16 }}>
<Moon strokeWidth={2} className="w-4 h-4" style={{ stroke: textSec }} />
</motion.div>
)}
</AnimatePresence>
</motion.button>
</header>
);
}