Files
co-lite/solvway-customer-portal/app/settings/page.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

183 lines
7.7 KiB
TypeScript

"use client";
import { useState } from "react";
import { motion } from "framer-motion";
import Link from "next/link";
import { useRouter } from "next/navigation";
import {
Sun, Moon, LogOut, ChevronRight,
Coins, Users, Pencil, Loader2, KeyRound,
} from "lucide-react";
import { useTheme } from "@/app/lib/ThemeContext";
import { useMember } from "@/app/lib/MemberContext";
import { apiPost } from "@/app/lib/clientApi";
import MemberAvatar from "@/app/components/ui/MemberAvatar";
const MotionLink = motion(Link);
const ACCOUNT_ROWS = [
{ icon: Pencil, label: "My Profile", sub: "Edit your personal details", href: "/settings/profile" },
{ icon: KeyRound, label: "Change Password", sub: "Update your sign-in password", href: "/settings/change-password" },
{ icon: Coins, label: "Point Transactions", sub: "Redemptions & history", href: "/settings/transactions" },
{ icon: Users, label: "Referral", sub: "Invite friends & earn rewards", href: "/settings/referral" },
];
export default function SettingsPage() {
const { isDark, toggle } = useTheme();
const { member } = useMember();
const router = useRouter();
const [signingOut, setSigningOut] = useState(false);
const handleSignOut = async () => {
setSigningOut(true);
try {
await apiPost("/api/auth/logout");
} catch {
/* ignore — clear client state regardless */
}
router.replace("/login");
};
const t = {
text: isDark ? "#FFFFFF" : "#1a1a1a",
textSec: isDark ? "rgba(255,255,255,0.8)" : "#5C5C5C",
textMuted: isDark ? "rgba(255,255,255,0.6)" : "#6B6B6B",
card: isDark ? "rgba(255,255,255,0.06)" : "#FFFFFF",
border: isDark ? "rgba(255,255,255,0.08)" : "rgba(0,0,0,0.07)",
shadow: isDark ? "0 8px 32px rgba(0,0,0,0.4)" : "0 2px 20px rgba(0,0,0,0.06)",
divider: isDark ? "rgba(255,255,255,0.05)" : "rgba(0,0,0,0.05)",
};
const card = { background: t.card, border: `1px solid ${t.border}`, boxShadow: t.shadow, borderRadius: "1.25rem" };
return (
<div className="min-h-full px-4 pt-5 pb-28 space-y-4" style={{ background: "var(--bg-primary)" }}>
{/* Header */}
<motion.div initial={{ opacity: 0, y: -10 }} animate={{ opacity: 1, y: 0 }} transition={{ type: "spring", stiffness: 320, damping: 26 }}>
<p className="text-xs font-semibold tracking-widest uppercase mb-1" style={{ color: "var(--orange-text)" }}>Profile</p>
<h1 className="text-xl font-extrabold" style={{ color: t.text }}>Settings</h1>
</motion.div>
{/* Profile card */}
<motion.div
initial={{ opacity: 0, y: 12 }}
animate={{ opacity: 1, y: 0 }}
transition={{ delay: 0.06, type: "spring", stiffness: 320, damping: 26 }}
style={card}
className="flex items-center gap-4 p-4"
>
<MemberAvatar className="w-16 h-16 rounded-2xl" />
<div>
<p className="font-bold text-base uppercase" style={{ color: t.text }}>{member?.name ?? "—"}</p>
<p className="text-xs font-mono mt-0.5" style={{ color: t.textMuted }}>{member?.memberCode ?? ""}</p>
<p className="text-xs mt-0.5" style={{ color: t.textSec }}>{member?.phone ?? ""}</p>
</div>
</motion.div>
{/* Your Account */}
<motion.div
initial={{ opacity: 0, y: 12 }}
animate={{ opacity: 1, y: 0 }}
transition={{ delay: 0.09, type: "spring", stiffness: 320, damping: 26 }}
style={{ ...card, padding: 0, overflow: "hidden" }}
>
<p className="px-4 pt-4 pb-2 text-xs font-bold tracking-widest uppercase" style={{ color: t.textMuted }}>
Your Account
</p>
{ACCOUNT_ROWS.map(({ icon: Icon, label, sub, href }) => (
<MotionLink
key={label}
href={href}
whileTap={{ scale: 0.98 }}
className="flex items-center gap-3 px-4 py-3"
style={{ borderTop: `1px solid ${t.divider}`, display: "flex" }}
>
<div className="w-9 h-9 rounded-xl flex items-center justify-center flex-shrink-0" style={{ background: "rgba(255,107,0,0.08)", border: `1px solid rgba(255,107,0,0.15)` }}>
<Icon strokeWidth={2} className="w-4 h-4 stroke-tastefullyOrange" />
</div>
<div className="flex-1 text-left">
<p className="text-sm font-semibold" style={{ color: t.text }}>{label}</p>
<p className="text-xs" style={{ color: t.textMuted }}>{sub}</p>
</div>
<ChevronRight strokeWidth={1.8} className="w-4 h-4 flex-shrink-0" style={{ stroke: t.textMuted }} />
</MotionLink>
))}
</motion.div>
{/* Appearance */}
<motion.div
initial={{ opacity: 0, y: 12 }}
animate={{ opacity: 1, y: 0 }}
transition={{ delay: 0.12, type: "spring", stiffness: 320, damping: 26 }}
style={{ ...card, padding: 0, overflow: "hidden" }}
>
<p className="px-4 pt-4 pb-2 text-xs font-bold tracking-widest uppercase" style={{ color: t.textMuted }}>
Appearance
</p>
<div className="px-4 pb-4 flex items-center justify-between">
<div className="flex items-center gap-3">
<div className="w-9 h-9 rounded-xl flex items-center justify-center" style={{ background: "rgba(255,107,0,0.1)" }}>
{isDark
? <Moon strokeWidth={2} className="w-4 h-4 stroke-tastefullyOrange" />
: <Sun strokeWidth={2} className="w-4 h-4 stroke-tastefullyOrange" />
}
</div>
<div>
<p className="text-sm font-semibold" style={{ color: t.text }}>Dark Mode</p>
<p className="text-xs" style={{ color: t.textMuted }}>{isDark ? "Currently on" : "Currently off"}</p>
</div>
</div>
<motion.button
onClick={toggle}
whileTap={{ scale: 0.93 }}
transition={{ type: "spring", stiffness: 420, damping: 26 }}
className="relative w-11 h-6 rounded-full flex-shrink-0"
style={{ background: isDark ? "#FF6B00" : "rgba(0,0,0,0.12)" }}
>
<motion.div
animate={{ x: isDark ? 20 : 2 }}
transition={{ type: "spring", stiffness: 500, damping: 30 }}
className="absolute top-1 w-4 h-4 rounded-full bg-white"
style={{ boxShadow: "0 1px 4px rgba(0,0,0,0.2)" }}
/>
</motion.button>
</div>
</motion.div>
{/* Sign out */}
<motion.div
initial={{ opacity: 0, y: 12 }}
animate={{ opacity: 1, y: 0 }}
transition={{ delay: 0.24, type: "spring", stiffness: 320, damping: 26 }}
>
<motion.button
onClick={handleSignOut}
disabled={signingOut}
whileTap={{ scale: 0.97 }}
className="w-full flex items-center justify-center gap-2 py-3.5 rounded-2xl text-sm font-semibold"
style={{
background: "rgba(239,68,68,0.08)",
border: "1px solid rgba(239,68,68,0.2)",
color: "#ef4444",
opacity: signingOut ? 0.7 : 1,
}}
>
{signingOut ? (
<motion.div animate={{ rotate: 360 }} transition={{ repeat: Infinity, duration: 0.8, ease: "linear" }}>
<Loader2 strokeWidth={2} className="w-4 h-4" />
</motion.div>
) : (
<LogOut strokeWidth={2} className="w-4 h-4" />
)}
{signingOut ? "Signing Out…" : "Sign Out"}
</motion.button>
</motion.div>
{/* App version */}
<p className="text-center text-xs pb-2" style={{ color: t.textMuted }}>
Tastefully Events · v1.0.0 · © {new Date().getFullYear()}
</p>
</div>
);
}