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
299 lines
16 KiB
TypeScript
299 lines
16 KiB
TypeScript
"use client";
|
|
|
|
import { useState, useEffect } from "react";
|
|
import { motion } from "framer-motion";
|
|
import {
|
|
Coins, Trophy, Zap, ShoppingBag, Sparkles, Utensils, Tag, History, Gift, QrCode, Loader2,
|
|
} from "lucide-react";
|
|
import type { LucideIcon } from "lucide-react";
|
|
import Link from "next/link";
|
|
import { useTheme } from "@/app/lib/ThemeContext";
|
|
import { useMember } from "@/app/lib/MemberContext";
|
|
import { apiGet } from "@/app/lib/clientApi";
|
|
import ImageLightbox from "@/app/components/ui/ImageLightbox";
|
|
import QRModal from "@/app/components/QRModal";
|
|
import VoucherSection from "@/app/store/VoucherSection";
|
|
import type { GalleryImage } from "@/app/components/ui/ImageGallery";
|
|
import type { CurrentEventConfig, EventProduct, MemberVoucherRow } from "@/app/lib/types";
|
|
|
|
const MotionLink = motion(Link);
|
|
|
|
const GRADS = [
|
|
"linear-gradient(145deg,#290a81 0%,#6d28d9 100%)",
|
|
"linear-gradient(145deg,#92400e 0%,#d97706 100%)",
|
|
"linear-gradient(145deg,#FF6B00 0%,#ff9e4d 100%)",
|
|
"linear-gradient(145deg,#0369a1 0%,#06b6d4 100%)",
|
|
"linear-gradient(145deg,#9d174d 0%,#ec4899 100%)",
|
|
"linear-gradient(145deg,#065f46 0%,#10b981 100%)",
|
|
];
|
|
const ICONS: LucideIcon[] = [Trophy, Utensils, ShoppingBag, Zap, Sparkles, Tag];
|
|
|
|
interface RewardItem {
|
|
id: string;
|
|
name: string;
|
|
/** server-formatted points price, e.g. "1,000 Points" (add-on amount stripped) */
|
|
priceDisplay: string;
|
|
/** raw add-on cash amount (RM), e.g. "5"; absent when the reward has no add-on cost */
|
|
addOnCost?: string;
|
|
/** real product image URL (matches member-portal); falls back to gradient + icon */
|
|
img?: string;
|
|
icon: LucideIcon;
|
|
imgGrad: string;
|
|
/** true when the reward's available stock is <= 0 (fully redeemed) */
|
|
soldOut: boolean;
|
|
}
|
|
|
|
function mapProduct(p: EventProduct, i: number): RewardItem {
|
|
const priceDisplay = p.priceDisplay ?? "";
|
|
const hasAddOn = typeof p.addOnCostLabel === "string" && p.addOnCostLabel.trim().length > 0;
|
|
// The mobile-api space-appends the raw add-on amount to priceDisplay ("1,000 Points 5");
|
|
// strip that suffix so the points price renders cleanly and the add-on is shown once, formatted.
|
|
const suffix = hasAddOn ? ` ${p.addOnCostLabel}` : "";
|
|
const basePrice = hasAddOn && priceDisplay.endsWith(suffix)
|
|
? priceDisplay.slice(0, priceDisplay.length - suffix.length)
|
|
: priceDisplay;
|
|
return {
|
|
id: String(p.uuid ?? i),
|
|
name: p.displayName ?? "Reward",
|
|
priceDisplay: basePrice,
|
|
addOnCost: hasAddOn ? p.addOnCostLabel!.trim() : undefined,
|
|
img: p.uploadPath || undefined,
|
|
icon: ICONS[i % ICONS.length],
|
|
imgGrad: GRADS[i % GRADS.length],
|
|
// Absent stock data → treat as available (unchanged rendering).
|
|
soldOut: typeof p.stockBalance === "number" ? p.stockBalance <= 0 : false,
|
|
};
|
|
}
|
|
|
|
const gridAnim = { hidden: {}, visible: { transition: { staggerChildren: 0.07 } } };
|
|
const cardAnim = {
|
|
hidden: { opacity: 0, y: 20, scale: 0.96 },
|
|
visible: { opacity: 1, y: 0, scale: 1, transition: { type: "spring" as const, stiffness: 320, damping: 26 } },
|
|
};
|
|
|
|
export default function StorePage() {
|
|
const { isDark } = useTheme();
|
|
const [balance, setBalance] = useState(0);
|
|
const [rewards, setRewards] = useState<RewardItem[]>([]);
|
|
const [vouchers, setVouchers] = useState<MemberVoucherRow[]>([]);
|
|
const [loading, setLoading] = useState(true);
|
|
/** presigned Taste Rewards "how to redeem" document URL; absent when no live event/doc */
|
|
const [redeemDocUrl, setRedeemDocUrl] = useState<string | undefined>();
|
|
const [showRedeemDoc, setShowRedeemDoc] = useState(false);
|
|
const [redeemImgLoaded, setRedeemImgLoaded] = useState(false);
|
|
const { member } = useMember();
|
|
const [qrOpen, setQrOpen] = useState(false);
|
|
|
|
useEffect(() => {
|
|
apiGet<{ balance: number }>("/api/points/balance").then((d) => setBalance(d.balance)).catch(() => {});
|
|
apiGet<CurrentEventConfig>("/api/event/current-config")
|
|
.then((c) => {
|
|
setRewards((c.currentEventTasteRewardsProductList ?? []).map(mapProduct));
|
|
setRedeemDocUrl(c.currentEventTasteRewards || undefined);
|
|
})
|
|
.catch(() => {})
|
|
.finally(() => setLoading(false));
|
|
apiGet<MemberVoucherRow[]>("/api/voucher")
|
|
// Expired and backoffice-disabled vouchers can never be redeemed again, so they are clutter here.
|
|
.then((d) => setVouchers(Array.isArray(d) ? d.filter((v) => v.reason !== "EXPIRED" && v.reason !== "NOT_ACTIVE") : []))
|
|
.catch(() => setVouchers([]));
|
|
}, []);
|
|
|
|
const redeemDoc: GalleryImage | null = redeemDocUrl
|
|
? {
|
|
id: "how-to-redeem",
|
|
title: "How to Redeem",
|
|
gradient: "linear-gradient(145deg, #C94D00 0%, #A83F00 100%)",
|
|
src: redeemDocUrl,
|
|
}
|
|
: null;
|
|
|
|
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 4px 24px rgba(0,0,0,0.35), inset 0 1px 0 rgba(255,255,255,0.06)" : "0 2px 16px rgba(0,0,0,0.07), 0 1px 3px rgba(0,0,0,0.04)",
|
|
divider: isDark ? "rgba(255,255,255,0.05)" : "rgba(0,0,0,0.06)",
|
|
};
|
|
|
|
return (
|
|
<div className="min-h-full" style={{ background: "var(--bg-primary)" }}>
|
|
<div className="pt-5 pb-6 space-y-5">
|
|
{/* How to redeem — shown up front so members see it without tapping; tap to enlarge.
|
|
Keeps a min-height until the image arrives so the page below doesn't jump. */}
|
|
{redeemDoc?.src && (
|
|
<motion.button
|
|
type="button"
|
|
onClick={() => setShowRedeemDoc(true)}
|
|
aria-label="Enlarge the redemption guide"
|
|
initial={{ opacity: 0, y: -12 }}
|
|
animate={{ opacity: 1, y: 0 }}
|
|
transition={{ type: "spring", stiffness: 320, damping: 26 }}
|
|
whileTap={{ scale: 0.99 }}
|
|
className="block rounded-2xl overflow-hidden mx-4 w-[calc(100%-2rem)] cursor-pointer"
|
|
style={{
|
|
background: t.card,
|
|
border: `1px solid ${t.border}`,
|
|
boxShadow: t.shadow,
|
|
minHeight: redeemImgLoaded ? undefined : "10rem",
|
|
}}
|
|
>
|
|
{/* eslint-disable-next-line @next/next/no-img-element -- presigned remote URL; natural ratio, no fixed dimensions. */}
|
|
<img
|
|
src={redeemDoc.src}
|
|
alt="How to redeem"
|
|
className="w-full h-auto block"
|
|
onLoad={() => setRedeemImgLoaded(true)}
|
|
onError={() => setRedeemImgLoaded(true)}
|
|
/>
|
|
</motion.button>
|
|
)}
|
|
|
|
{/* Title hero + balance */}
|
|
<motion.div
|
|
initial={{ opacity: 0, y: -12 }}
|
|
animate={{ opacity: 1, y: 0 }}
|
|
transition={{ type: "spring", stiffness: 320, damping: 26 }}
|
|
className="relative rounded-2xl overflow-hidden mx-4"
|
|
style={{ background: t.card, border: `1px solid ${t.border}`, boxShadow: t.shadow }}
|
|
>
|
|
<div className="absolute inset-0 wave-animate pointer-events-none" />
|
|
<div className="absolute inset-y-0 right-0 w-2/3 pointer-events-none" style={{ background: "radial-gradient(ellipse at right center, rgba(255,107,0,0.12) 0%, transparent 70%)" }} />
|
|
<div className="relative px-5 pt-5 pb-4">
|
|
{/* flex-wrap: at large text the wide-tracked eyebrow and the History link no longer fit on one
|
|
row, so History drops to its own line (still right-aligned) instead of crushing the eyebrow. */}
|
|
<div className="flex flex-wrap items-center justify-between gap-x-3 gap-y-2 mb-2">
|
|
<p className="text-xs font-black tracking-[0.2em] uppercase" style={{ color: "var(--orange-text)" }}>Taste Rewards+</p>
|
|
<MotionLink href="/store/history" whileTap={{ scale: 0.88 }} className="ml-auto flex-shrink-0 flex items-center gap-1.5 px-3 py-2 rounded-xl" style={{ background: isDark ? "rgba(255,255,255,0.06)" : "rgba(0,0,0,0.05)", border: `1px solid ${t.border}` }}>
|
|
<History strokeWidth={2} className="w-4 h-4" style={{ stroke: t.textSec }} />
|
|
<span className="text-sm font-semibold" style={{ color: t.textSec }}>History</span>
|
|
</MotionLink>
|
|
</div>
|
|
<h1 className="text-4xl font-black tracking-tight leading-none" style={{ color: "var(--orange-text)" }}>Rewards</h1>
|
|
<p className="text-sm mt-1.5" style={{ color: t.textMuted }}>Redeem points for exclusive perks</p>
|
|
|
|
<div className="flex items-center gap-2 mt-4 pt-4" style={{ borderTop: `1px solid ${t.divider}` }}>
|
|
<div className="w-8 h-8 rounded-xl flex items-center justify-center" style={{ background: "rgba(255,107,0,0.12)", border: "1px solid rgba(255,107,0,0.2)" }}>
|
|
<Coins strokeWidth={2} className="w-4 h-4 stroke-tastefullyOrange" />
|
|
</div>
|
|
<div>
|
|
<p className="text-xs font-semibold uppercase tracking-widest" style={{ color: t.textMuted }}>Your Balance</p>
|
|
<motion.p key={balance} initial={{ scale: 1.2, opacity: 0 }} animate={{ scale: 1, opacity: 1 }} transition={{ type: "spring", stiffness: 400, damping: 20 }} className="text-xl font-extrabold leading-none" style={{ color: "var(--orange-text)" }}>
|
|
{balance.toLocaleString()}<span className="text-xs font-semibold ml-1" style={{ color: t.textMuted }}>pts</span>
|
|
</motion.p>
|
|
</div>
|
|
</div>
|
|
|
|
{/* "How to redeem" — reopens the event's Taste Rewards document in the lightbox */}
|
|
{redeemDoc && (
|
|
<motion.button
|
|
onClick={() => setShowRedeemDoc(true)}
|
|
whileTap={{ scale: 0.97 }}
|
|
className="w-full mt-4 py-3 rounded-xl text-xs font-bold flex items-center justify-center gap-2"
|
|
style={{ background: "rgba(255,107,0,0.12)", border: "1px solid rgba(255,107,0,0.3)", color: "var(--orange-text)" }}
|
|
>
|
|
<QrCode strokeWidth={2} className="w-4 h-4" /> How to redeem
|
|
</motion.button>
|
|
)}
|
|
|
|
<motion.button
|
|
onClick={() => setQrOpen(true)}
|
|
whileTap={{ scale: 0.97 }}
|
|
className="w-full mt-3 py-3 rounded-xl text-xs font-bold flex items-center justify-center gap-2 text-white"
|
|
style={{ background: "linear-gradient(135deg,#C94D00,#A83F00)" }}
|
|
>
|
|
<QrCode strokeWidth={2} className="w-4 h-4" /> Redeem at counter
|
|
</motion.button>
|
|
</div>
|
|
</motion.div>
|
|
|
|
{/* Member vouchers — personal and actionable; sits above the product catalogue */}
|
|
<VoucherSection
|
|
vouchers={vouchers}
|
|
isDark={isDark}
|
|
/>
|
|
|
|
{/* Rewards grid */}
|
|
<div className="px-4">
|
|
<div className="flex items-center justify-between mb-3">
|
|
<p className="text-xs font-bold tracking-widest uppercase" style={{ color: t.textMuted }}>Available Rewards</p>
|
|
<span className="text-xs" style={{ color: t.textMuted }}>{rewards.length} items</span>
|
|
</div>
|
|
|
|
{loading ? (
|
|
<div className="flex justify-center py-12 rounded-2xl" style={{ background: t.card, border: `1px solid ${t.border}`, boxShadow: t.shadow }}>
|
|
<motion.div animate={{ rotate: 360 }} transition={{ repeat: Infinity, duration: 0.8, ease: "linear" }}>
|
|
<Loader2 strokeWidth={2} className="w-6 h-6 stroke-tastefullyOrange" />
|
|
</motion.div>
|
|
</div>
|
|
) : rewards.length === 0 ? (
|
|
<div className="flex flex-col items-center justify-center py-12 rounded-2xl text-center" style={{ background: t.card, border: `1px solid ${t.border}`, boxShadow: t.shadow }}>
|
|
<Gift strokeWidth={1.5} className="w-8 h-8 mb-2" style={{ stroke: t.textMuted }} />
|
|
<p className="text-sm font-semibold" style={{ color: t.text }}>No rewards yet</p>
|
|
<p className="text-xs mt-0.5 px-8" style={{ color: t.textMuted }}>Rewards appear when an event is live.</p>
|
|
</div>
|
|
) : (
|
|
<motion.div variants={gridAnim} initial="hidden" animate="visible" className="grid grid-cols-2 gap-3">
|
|
{rewards.map((item) => {
|
|
const Icon = item.icon;
|
|
return (
|
|
<motion.div key={item.id} variants={cardAnim} className="h-full">
|
|
<div className="flex flex-col h-full rounded-2xl overflow-hidden" style={{ background: t.card, border: `1px solid ${t.border}`, boxShadow: t.shadow, opacity: item.soldOut ? 0.55 : 1 }}>
|
|
<div
|
|
className="relative h-40 flex items-center justify-center flex-shrink-0"
|
|
style={{ background: item.img ? (isDark ? "rgba(255,255,255,0.04)" : "#f5f5f5") : item.imgGrad }}
|
|
>
|
|
{item.soldOut && (
|
|
<div
|
|
className="absolute top-2 right-2 z-10 px-2 py-1 rounded-lg text-xs font-bold tracking-wide uppercase"
|
|
style={{ background: "rgba(0,0,0,0.72)", color: "#fff", backdropFilter: "blur(4px)", border: "1px solid rgba(255,255,255,0.15)" }}
|
|
>
|
|
Fully Redeemed
|
|
</div>
|
|
)}
|
|
{item.img ? (
|
|
/* Real product image — entire image, no crop (matches member-portal) */
|
|
// eslint-disable-next-line @next/next/no-img-element -- arbitrary remote image URLs; next/image would require per-host remotePatterns config and fixed dimensions.
|
|
<img src={item.img} alt={item.name} className="w-full h-full object-contain p-3" />
|
|
) : (
|
|
<>
|
|
<div className="absolute inset-0" style={{ background: "radial-gradient(ellipse at 30% 30%, rgba(255,255,255,0.15) 0%, transparent 60%)" }} />
|
|
<Icon strokeWidth={1.6} className="w-14 h-14 stroke-white" style={{ filter: "drop-shadow(0 2px 8px rgba(0,0,0,0.4))" }} />
|
|
</>
|
|
)}
|
|
</div>
|
|
<div className="flex flex-col gap-2 p-3 flex-1">
|
|
<p className="text-xs font-bold leading-tight line-clamp-2" style={{ color: t.text, minHeight: "2.5em" }}>{item.name}</p>
|
|
{/* wrap the whole add-on to its own line when it doesn't fit; never break a label mid-token */}
|
|
<div className="flex flex-wrap items-center gap-x-1.5 gap-y-0.5 mt-auto">
|
|
<div className="flex items-center gap-1.5">
|
|
<Coins strokeWidth={2} className="w-3.5 h-3.5 stroke-tastefullyOrange flex-shrink-0" />
|
|
<span className="text-xs font-extrabold whitespace-nowrap" style={{ color: "var(--orange-text)" }}>{item.priceDisplay}</span>
|
|
</div>
|
|
{item.addOnCost && (
|
|
<span className="text-xs font-semibold whitespace-nowrap" style={{ color: t.textMuted }}>+ (RM {item.addOnCost})</span>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</motion.div>
|
|
);
|
|
})}
|
|
</motion.div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
|
|
<ImageLightbox image={showRedeemDoc ? redeemDoc : null} onClose={() => setShowRedeemDoc(false)} />
|
|
|
|
<QRModal
|
|
open={qrOpen}
|
|
onClose={() => setQrOpen(false)}
|
|
member={{ name: member?.name ?? "", id: member?.memberCode ?? "" }}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|