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
156 lines
6.8 KiB
TypeScript
156 lines
6.8 KiB
TypeScript
"use client";
|
|
|
|
import { useState } from "react";
|
|
import { motion } from "framer-motion";
|
|
import Link from "next/link";
|
|
import { Ticket, ChevronRight } from "lucide-react";
|
|
import type { MemberVoucherRow } from "@/app/lib/types";
|
|
import { humaniseReason } from "@/app/lib/voucherReason";
|
|
import VoucherModal from "@/app/store/VoucherModal";
|
|
|
|
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 } },
|
|
};
|
|
|
|
// One Redeem control, two elements: a Link when the voucher is redeemable, a button when
|
|
// it is blocked only by an incomplete profile. Shared styling so the two never drift.
|
|
const redeemControlClass =
|
|
"flex items-center justify-center gap-1 w-full py-2.5 px-3 rounded-xl text-sm font-bold";
|
|
const redeemControlStyle = {
|
|
background: "rgba(255,107,0,0.12)",
|
|
border: "1px solid rgba(255,107,0,0.3)",
|
|
color: "var(--orange-text)",
|
|
};
|
|
|
|
interface VoucherSectionProps {
|
|
vouchers: MemberVoucherRow[];
|
|
isDark: boolean;
|
|
}
|
|
|
|
/**
|
|
* Personal, actionable voucher list shown above the Rewards product grid.
|
|
* Renders nothing when the member has no vouchers — this section must not
|
|
* add empty-state noise to a page every member sees.
|
|
*/
|
|
export default function VoucherSection({ vouchers, isDark }: VoucherSectionProps) {
|
|
const [selected, setSelected] = useState<MemberVoucherRow | null>(null);
|
|
if (vouchers.length === 0) return 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)",
|
|
};
|
|
|
|
return (
|
|
<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 }}>
|
|
Your Vouchers
|
|
</p>
|
|
<span className="text-xs" style={{ color: t.textMuted }}>{vouchers.length} total</span>
|
|
</div>
|
|
|
|
<motion.div variants={gridAnim} initial="hidden" animate="visible" className="space-y-3">
|
|
{vouchers.map((voucher) => {
|
|
const name = voucher.name.trim();
|
|
return (
|
|
// Two columns: image/icon on the left; title, amount, hint and the Redeem button
|
|
// stacked on the right. Nothing is forced into a single row, so a long title wraps
|
|
// instead of being cut off.
|
|
<motion.div
|
|
key={voucher.uuid}
|
|
variants={cardAnim}
|
|
className="flex items-start gap-3 rounded-2xl p-3"
|
|
style={{ background: t.card, border: `1px solid ${t.border}`, boxShadow: t.shadow }}
|
|
>
|
|
{/* The details button below is the accessible control; this duplicate target is
|
|
for sighted taps only, so it stays out of the tab order and the a11y tree. */}
|
|
<button
|
|
type="button"
|
|
tabIndex={-1}
|
|
aria-hidden="true"
|
|
onClick={() => setSelected(voucher)}
|
|
className="w-20 h-20 rounded-xl flex items-center justify-center flex-shrink-0 overflow-hidden"
|
|
style={{
|
|
background: voucher.imageUrl
|
|
? (isDark ? "rgba(255,255,255,0.04)" : "#f5f5f5")
|
|
: "linear-gradient(145deg,#C94D00 0%,#A83F00 100%)",
|
|
}}
|
|
>
|
|
{voucher.imageUrl ? (
|
|
// Arbitrary remote image URLs; next/image would require per-host
|
|
// remotePatterns config and fixed dimensions. Matches the reward
|
|
// grid's img/fallback treatment (app/store/page.tsx).
|
|
// eslint-disable-next-line @next/next/no-img-element
|
|
<img src={voucher.imageUrl} alt={name} className="w-full h-full object-contain p-1" />
|
|
) : (
|
|
<Ticket
|
|
strokeWidth={1.8}
|
|
className="w-8 h-8 stroke-white"
|
|
style={{ filter: "drop-shadow(0 2px 8px rgba(0,0,0,0.4))" }}
|
|
/>
|
|
)}
|
|
</button>
|
|
|
|
<div className="flex-1 min-w-0 flex flex-col gap-2.5">
|
|
<button
|
|
type="button"
|
|
aria-haspopup="dialog"
|
|
aria-label={`View details: ${name}`}
|
|
onClick={() => setSelected(voucher)}
|
|
className="text-left"
|
|
>
|
|
<span className="block text-base font-bold leading-snug break-words" style={{ color: t.text }}>
|
|
{name}
|
|
</span>
|
|
<span className="block text-sm mt-0.5" style={{ color: t.textSec }}>
|
|
{voucher.currencySymbol ?? ""}{voucher.amount}
|
|
</span>
|
|
{/* Under the amount rather than in the control slot, so a profile-incomplete
|
|
voucher can show its reason and still offer the button. */}
|
|
{!voucher.redeemable && (
|
|
<span className="block text-xs mt-0.5" style={{ color: t.textMuted }}>
|
|
{humaniseReason(voucher.reason)}
|
|
</span>
|
|
)}
|
|
</button>
|
|
|
|
{voucher.redeemable ? (
|
|
<Link href={`/vouchers/${voucher.uuid}`} className={redeemControlClass} style={redeemControlStyle}>
|
|
Redeem
|
|
<ChevronRight strokeWidth={2.2} className="w-3.5 h-3.5" />
|
|
</Link>
|
|
) : voucher.reason === "PROFILE_INCOMPLETE" ? (
|
|
// An incomplete profile is the one ineligibility the member can fix right now,
|
|
// so the button stays. It opens the same voucher modal as tapping the card —
|
|
// which carries the complete-profile message — rather than navigating to a
|
|
// voucher they cannot yet redeem. Every other reason renders no control.
|
|
<button
|
|
type="button"
|
|
onClick={() => setSelected(voucher)}
|
|
className={redeemControlClass}
|
|
style={redeemControlStyle}
|
|
>
|
|
Redeem
|
|
<ChevronRight strokeWidth={2.2} className="w-3.5 h-3.5" />
|
|
</button>
|
|
) : null}
|
|
</div>
|
|
</motion.div>
|
|
);
|
|
})}
|
|
</motion.div>
|
|
|
|
<VoucherModal voucher={selected} onClose={() => setSelected(null)} />
|
|
</div>
|
|
);
|
|
}
|