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
317 lines
13 KiB
TypeScript
317 lines
13 KiB
TypeScript
"use client";
|
|
|
|
import { useState, useRef } from "react";
|
|
import { motion, useAnimation, AnimatePresence } from "framer-motion";
|
|
import { Sparkles, Trophy, RotateCcw, ChevronRight, Star } from "lucide-react";
|
|
import GlassCard from "@/app/components/ui/GlassCard";
|
|
import GlowOverlay from "@/app/components/ui/GlowOverlay";
|
|
|
|
const PRIZES = [
|
|
{ label: "🏆 Grand Prize", sub: "Staycation Package", tier: "legendary", color: "#FF6B00" },
|
|
{ label: "✈️ Travel Voucher", sub: "RM 500 Flight Credit", tier: "epic", color: "#a855f7" },
|
|
{ label: "🍽️ Dining Pass", sub: "6-course Fine Dining", tier: "rare", color: "#290a81" },
|
|
{ label: "🎁 Goodie Bag", sub: "Exclusive Merch Set", tier: "common", color: "#3b82f6" },
|
|
{ label: "⚡ Bonus Points", sub: "+500 Loyalty Tokens", tier: "common", color: "#22c55e" },
|
|
{ label: "🥂 Bottle Service", sub: "Premium Champagne Table", tier: "epic", color: "#ec4899" },
|
|
{ label: "🎫 Next Event", sub: "Free VIP Pass", tier: "rare", color: "#f59e0b" },
|
|
{ label: "💎 Diamond Tier", sub: "Lifetime Membership", tier: "legendary", color: "#06b6d4" },
|
|
];
|
|
|
|
const WHEEL_SEGMENTS = 8;
|
|
const SEGMENT_ANGLE = 360 / WHEEL_SEGMENTS;
|
|
|
|
const tierGlow: Record<string, string> = {
|
|
legendary: "0 0 40px rgba(255,107,0,0.8), 0 0 80px rgba(255,107,0,0.4)",
|
|
epic: "0 0 30px rgba(168,85,247,0.7), 0 0 60px rgba(168,85,247,0.3)",
|
|
rare: "0 0 25px rgba(41,10,129,0.7), 0 0 50px rgba(41,10,129,0.3)",
|
|
common: "0 0 16px rgba(255,255,255,0.2)",
|
|
};
|
|
|
|
type Phase = "idle" | "spinning" | "reveal" | "done";
|
|
|
|
/**
|
|
* SpinWheel — archived lucky draw component.
|
|
*
|
|
* A self-contained spin-the-wheel UI with:
|
|
* - Prize wheel SVG with 8 segments
|
|
* - Ticket counter (3 spins)
|
|
* - Animated spin with framer-motion
|
|
* - Prize reveal + tier glow
|
|
* - Win history list
|
|
*
|
|
* Usage:
|
|
* import SpinWheel from "@/app/components/archive/SpinWheel";
|
|
* <SpinWheel />
|
|
*/
|
|
export default function SpinWheel() {
|
|
const [phase, setPhase] = useState<Phase>("idle");
|
|
const [result, setResult] = useState<(typeof PRIZES)[0] | null>(null);
|
|
const [tickets] = useState(3);
|
|
const [usedTickets, setUsed] = useState(0);
|
|
const [history, setHistory] = useState<(typeof PRIZES)[0][]>([]);
|
|
const controls = useAnimation();
|
|
const totalRotationRef = useRef(0);
|
|
|
|
const canSpin = usedTickets < tickets && phase === "idle";
|
|
|
|
const spin = async () => {
|
|
if (!canSpin) return;
|
|
setPhase("spinning");
|
|
|
|
const winIndex = Math.floor(Math.random() * PRIZES.length);
|
|
const baseSpins = 5 + Math.floor(Math.random() * 4);
|
|
const targetAngle = baseSpins * 360 + winIndex * SEGMENT_ANGLE;
|
|
totalRotationRef.current += targetAngle;
|
|
|
|
await controls.start({
|
|
rotate: totalRotationRef.current,
|
|
transition: {
|
|
duration: 4 + Math.random() * 1.5,
|
|
ease: [0.15, 0.85, 0.35, 1.0],
|
|
},
|
|
});
|
|
|
|
setResult(PRIZES[winIndex]);
|
|
setPhase("reveal");
|
|
setTimeout(() => {
|
|
setUsed((u) => u + 1);
|
|
setHistory((h) => [PRIZES[winIndex], ...h]);
|
|
setPhase("done");
|
|
}, 800);
|
|
};
|
|
|
|
const reset = () => {
|
|
setPhase("idle");
|
|
setResult(null);
|
|
};
|
|
|
|
return (
|
|
<div className="relative min-h-full px-4 pt-4 pb-6 overflow-hidden">
|
|
<GlowOverlay color="accent" size="lg" className="absolute top-0 left-1/2 -translate-x-1/2 opacity-35" />
|
|
<GlowOverlay color="orange" size="md" className="absolute bottom-32 -right-16 opacity-20" />
|
|
|
|
{/* Header */}
|
|
<motion.div
|
|
initial={{ opacity: 0, y: -10 }}
|
|
animate={{ opacity: 1, y: 0 }}
|
|
transition={{ type: "spring", stiffness: 320, damping: 26 }}
|
|
className="mb-4"
|
|
>
|
|
<h1 className="text-xl font-bold text-white">
|
|
Lucky <span className="text-tastefullyOrange glow-text-orange">Draw</span>
|
|
</h1>
|
|
<p className="text-xs text-white/60 mt-0.5">Spin the wheel — every spin is a chance to win big</p>
|
|
</motion.div>
|
|
|
|
{/* Ticket counter */}
|
|
<div className="flex items-center gap-2 mb-5">
|
|
{Array.from({ length: tickets }).map((_, i) => (
|
|
<motion.div
|
|
key={i}
|
|
initial={{ scale: 0 }}
|
|
animate={{ scale: 1 }}
|
|
transition={{ delay: i * 0.08, type: "spring", stiffness: 400, damping: 20 }}
|
|
className="flex items-center gap-1 px-2.5 py-1.5 rounded-xl text-xs font-bold"
|
|
style={{
|
|
background: i < usedTickets ? "rgba(255,255,255,0.04)" : "rgba(255,107,0,0.15)",
|
|
border: `1px solid ${i < usedTickets ? "rgba(255,255,255,0.06)" : "rgba(255,107,0,0.3)"}`,
|
|
color: i < usedTickets ? "rgba(255,255,255,0.2)" : "#FF6B00",
|
|
textDecoration: i < usedTickets ? "line-through" : "none",
|
|
}}
|
|
>
|
|
<Star strokeWidth={i < usedTickets ? 1 : 2} className="w-3 h-3" />
|
|
Ticket {i + 1}
|
|
</motion.div>
|
|
))}
|
|
</div>
|
|
|
|
{/* Wheel */}
|
|
<div className="flex flex-col items-center mb-6">
|
|
<div className="relative">
|
|
{/* Pointer */}
|
|
<div className="absolute top-0 left-1/2 -translate-x-1/2 -translate-y-2 z-20 flex flex-col items-center">
|
|
<div
|
|
className="w-0 h-0"
|
|
style={{
|
|
borderLeft: "10px solid transparent",
|
|
borderRight: "10px solid transparent",
|
|
borderTop: "18px solid #FF6B00",
|
|
filter: "drop-shadow(0 0 6px rgba(255,107,0,0.8))",
|
|
}}
|
|
/>
|
|
</div>
|
|
|
|
{/* Wheel container */}
|
|
<motion.div
|
|
animate={controls}
|
|
className="relative w-64 h-64 rounded-full"
|
|
style={{
|
|
transformOrigin: "center center",
|
|
boxShadow:
|
|
phase === "reveal" && result
|
|
? tierGlow[result.tier]
|
|
: "0 0 40px rgba(41,10,129,0.4)",
|
|
}}
|
|
>
|
|
{/* SVG wheel */}
|
|
<svg viewBox="0 0 200 200" className="w-full h-full">
|
|
{PRIZES.map((prize, i) => {
|
|
const startAngle = (i * SEGMENT_ANGLE - 90) * (Math.PI / 180);
|
|
const endAngle = ((i + 1) * SEGMENT_ANGLE - 90) * (Math.PI / 180);
|
|
const x1 = 100 + 98 * Math.cos(startAngle);
|
|
const y1 = 100 + 98 * Math.sin(startAngle);
|
|
const x2 = 100 + 98 * Math.cos(endAngle);
|
|
const y2 = 100 + 98 * Math.sin(endAngle);
|
|
const mx = 100 + 68 * Math.cos((startAngle + endAngle) / 2);
|
|
const my = 100 + 68 * Math.sin((startAngle + endAngle) / 2);
|
|
const textAngle = ((startAngle + endAngle) / 2) * (180 / Math.PI);
|
|
|
|
return (
|
|
<g key={i}>
|
|
<path
|
|
d={`M 100 100 L ${x1} ${y1} A 98 98 0 0 1 ${x2} ${y2} Z`}
|
|
fill={i % 2 === 0 ? `${prize.color}33` : `${prize.color}22`}
|
|
stroke={prize.color}
|
|
strokeWidth="0.5"
|
|
opacity="0.9"
|
|
/>
|
|
<text
|
|
x={mx}
|
|
y={my}
|
|
textAnchor="middle"
|
|
dominantBaseline="middle"
|
|
fontSize="7.5"
|
|
fill="white"
|
|
opacity="0.9"
|
|
transform={`rotate(${textAngle + 90}, ${mx}, ${my})`}
|
|
style={{ fontWeight: 700 }}
|
|
>
|
|
{prize.label.slice(0, 12)}
|
|
</text>
|
|
</g>
|
|
);
|
|
})}
|
|
|
|
{/* Center hub */}
|
|
<circle cx="100" cy="100" r="16" fill="#1a1a1a" stroke="rgba(255,255,255,0.15)" strokeWidth="1" />
|
|
<circle cx="100" cy="100" r="10" fill="#FF6B00" opacity="0.8" />
|
|
</svg>
|
|
</motion.div>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Result reveal */}
|
|
<AnimatePresence>
|
|
{result && (phase === "reveal" || phase === "done") && (
|
|
<motion.div
|
|
initial={{ opacity: 0, scale: 0.85, y: 20 }}
|
|
animate={{ opacity: 1, scale: 1, y: 0 }}
|
|
exit={{ opacity: 0, scale: 0.9 }}
|
|
transition={{ type: "spring", stiffness: 380, damping: 22 }}
|
|
className="mb-4"
|
|
>
|
|
<div
|
|
className="rounded-3xl p-5 text-center"
|
|
style={{
|
|
background: `linear-gradient(135deg, ${result.color}25 0%, rgba(26,26,26,0.95) 100%)`,
|
|
border: `1px solid ${result.color}40`,
|
|
boxShadow: tierGlow[result.tier],
|
|
}}
|
|
>
|
|
<motion.div
|
|
animate={{ rotate: [0, -8, 8, -4, 4, 0] }}
|
|
transition={{ duration: 0.6, delay: 0.1 }}
|
|
className="text-4xl mb-2"
|
|
>
|
|
{result.label.slice(0, 2)}
|
|
</motion.div>
|
|
<h3 className="text-lg font-extrabold text-white">{result.label.slice(3)}</h3>
|
|
<p className="text-sm text-white/50 mt-0.5">{result.sub}</p>
|
|
<span
|
|
className="inline-block mt-2 px-3 py-1 rounded-full text-xs font-bold uppercase tracking-widest"
|
|
style={{ background: `${result.color}25`, color: result.color, border: `1px solid ${result.color}40` }}
|
|
>
|
|
{result.tier}
|
|
</span>
|
|
</div>
|
|
</motion.div>
|
|
)}
|
|
</AnimatePresence>
|
|
|
|
{/* Spin / reset button */}
|
|
<div className="flex gap-2.5">
|
|
<motion.button
|
|
onClick={spin}
|
|
disabled={!canSpin}
|
|
whileTap={canSpin ? { scale: 0.95 } : undefined}
|
|
transition={{ type: "spring", stiffness: 400, damping: 26 }}
|
|
className="flex-1 py-4 rounded-2xl font-bold text-sm tracking-wide flex items-center justify-center gap-2 disabled:opacity-40"
|
|
style={{
|
|
background: canSpin
|
|
? "linear-gradient(135deg, #FF6B00 0%, rgba(255,107,0,0.7) 100%)"
|
|
: "rgba(255,255,255,0.05)",
|
|
boxShadow: canSpin ? "0 8px 24px rgba(255,107,0,0.35)" : "none",
|
|
color: canSpin ? "#fff" : "rgba(255,255,255,0.3)",
|
|
}}
|
|
>
|
|
<Sparkles strokeWidth={2} className="w-4 h-4" />
|
|
{phase === "spinning" ? "Spinning…" : "Spin the Wheel"}
|
|
</motion.button>
|
|
|
|
{phase === "done" && (
|
|
<motion.button
|
|
onClick={reset}
|
|
whileTap={{ scale: 0.9 }}
|
|
initial={{ opacity: 0, scale: 0.8 }}
|
|
animate={{ opacity: 1, scale: 1 }}
|
|
transition={{ type: "spring", stiffness: 400, damping: 24 }}
|
|
className="px-4 rounded-2xl glass-card flex items-center justify-center"
|
|
>
|
|
<RotateCcw strokeWidth={2} className="w-4 h-4 stroke-white/50" />
|
|
</motion.button>
|
|
)}
|
|
</div>
|
|
|
|
{/* Spin history */}
|
|
{history.length > 0 && (
|
|
<motion.section
|
|
initial={{ opacity: 0, y: 10 }}
|
|
animate={{ opacity: 1, y: 0 }}
|
|
transition={{ type: "spring", stiffness: 300, damping: 26 }}
|
|
className="mt-5"
|
|
>
|
|
<div className="flex items-center gap-2 mb-3">
|
|
<Trophy strokeWidth={2} className="w-4 h-4 stroke-white/50" />
|
|
<h2 className="text-sm font-semibold text-white/70">Your Wins</h2>
|
|
</div>
|
|
<div className="space-y-2">
|
|
{history.map((h, i) => (
|
|
<motion.div
|
|
key={i}
|
|
initial={{ opacity: 0, x: -12 }}
|
|
animate={{ opacity: 1, x: 0 }}
|
|
transition={{ delay: i * 0.05, type: "spring", stiffness: 320, damping: 26 }}
|
|
>
|
|
<GlassCard variant="default" className="flex items-center gap-3 px-4 py-3">
|
|
<span className="text-xl">{h.label.slice(0, 2)}</span>
|
|
<div className="flex-1">
|
|
<p className="text-xs font-semibold text-white">{h.label.slice(3)}</p>
|
|
<p className="text-xs text-white/60">{h.sub}</p>
|
|
</div>
|
|
<span
|
|
className="text-xs font-bold uppercase tracking-widest px-2 py-0.5 rounded-full"
|
|
style={{ background: `${h.color}20`, color: h.color }}
|
|
>
|
|
{h.tier}
|
|
</span>
|
|
<ChevronRight strokeWidth={1.5} className="w-4 h-4 stroke-white/20" />
|
|
</GlassCard>
|
|
</motion.div>
|
|
))}
|
|
</div>
|
|
</motion.section>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|