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
192 lines
8.2 KiB
TypeScript
192 lines
8.2 KiB
TypeScript
"use client";
|
|
|
|
import { useEffect, useRef } from "react";
|
|
import { motion, AnimatePresence } from "framer-motion";
|
|
import Link from "next/link";
|
|
import { Ticket, X, ChevronRight } from "lucide-react";
|
|
import type { MemberVoucherRow } from "@/app/lib/types";
|
|
import { humaniseReason } from "@/app/lib/voucherReason";
|
|
import { useT } from "@/app/lib/i18n/MessagesProvider";
|
|
|
|
interface VoucherModalProps {
|
|
/** The voucher to show; null keeps the modal closed. */
|
|
voucher: MemberVoucherRow | null;
|
|
onClose: () => void;
|
|
}
|
|
|
|
/**
|
|
* Full details for one voucher: image, title, amount, description and its action.
|
|
* The /store card only has room for a summary, so this is where a member reads what
|
|
* the voucher is actually for. A voucher blocked only by an incomplete profile shows the
|
|
* complete-profile message and button right here, in the same design, so the card, its Redeem
|
|
* button and this modal all lead to one place. Presentation only — theming comes from CSS
|
|
* variables, and the caller owns which voucher is open.
|
|
*/
|
|
export default function VoucherModal({ voucher, onClose }: VoucherModalProps) {
|
|
const t = useT();
|
|
const panelRef = useRef<HTMLDivElement>(null);
|
|
const open = voucher !== null;
|
|
|
|
// Escape closes; focus moves into the dialog and returns to the card that opened it.
|
|
useEffect(() => {
|
|
if (!open) return;
|
|
const previouslyFocused = document.activeElement as HTMLElement | null;
|
|
panelRef.current?.focus();
|
|
const onKey = (e: KeyboardEvent) => {
|
|
if (e.key === "Escape") onClose();
|
|
};
|
|
document.addEventListener("keydown", onKey);
|
|
return () => {
|
|
document.removeEventListener("keydown", onKey);
|
|
previouslyFocused?.focus?.();
|
|
};
|
|
}, [open, onClose]);
|
|
|
|
const name = voucher?.name.trim() ?? "";
|
|
const description = voucher?.description?.trim() ?? "";
|
|
// Many vouchers carry no description, or just repeat their name — don't show that twice.
|
|
const showDescription = description.length > 0 && description.toLowerCase() !== name.toLowerCase();
|
|
|
|
return (
|
|
<AnimatePresence>
|
|
{voucher && (
|
|
<>
|
|
<motion.div
|
|
key="voucher-backdrop"
|
|
data-testid="voucher-modal-backdrop"
|
|
initial={{ opacity: 0 }}
|
|
animate={{ opacity: 1 }}
|
|
exit={{ opacity: 0 }}
|
|
transition={{ duration: 0.2 }}
|
|
onClick={onClose}
|
|
className="fixed inset-0 z-[100]"
|
|
style={{ background: "rgba(0,0,0,0.6)", backdropFilter: "blur(6px)" }}
|
|
/>
|
|
<div className="fixed inset-0 z-[101] flex items-center justify-center px-4 pointer-events-none">
|
|
<motion.div
|
|
key="voucher-panel"
|
|
ref={panelRef}
|
|
role="dialog"
|
|
aria-modal="true"
|
|
aria-labelledby="voucher-modal-title"
|
|
tabIndex={-1}
|
|
initial={{ opacity: 0, scale: 0.9, y: 24 }}
|
|
animate={{ opacity: 1, scale: 1, y: 0 }}
|
|
exit={{ opacity: 0, scale: 0.94, y: 16 }}
|
|
transition={{ type: "spring", stiffness: 380, damping: 28 }}
|
|
className="relative rounded-3xl overflow-hidden w-full max-w-sm max-h-[88dvh] overflow-y-auto pointer-events-auto outline-none"
|
|
style={{
|
|
background: "var(--bg-primary)",
|
|
border: "1px solid var(--border-color)",
|
|
boxShadow: "0 12px 40px rgba(0,0,0,0.25)",
|
|
}}
|
|
>
|
|
<button
|
|
type="button"
|
|
aria-label="Close"
|
|
onClick={onClose}
|
|
className="absolute top-3 right-3 z-10 w-10 h-10 rounded-full flex items-center justify-center"
|
|
style={{ background: "rgba(0,0,0,0.35)", border: "1px solid rgba(255,255,255,0.25)" }}
|
|
>
|
|
<X strokeWidth={2.2} className="w-5 h-5 stroke-white" />
|
|
</button>
|
|
|
|
{/* Image — whole picture, no crop; ticket icon on the brand gradient when there is none */}
|
|
{voucher.imageUrl ? (
|
|
<div className="flex items-center justify-center p-4" style={{ background: "var(--bg-card-alt)" }}>
|
|
{/* Arbitrary remote image URLs; next/image would need per-host remotePatterns
|
|
config and fixed dimensions. Same treatment as the card. */}
|
|
{/* eslint-disable-next-line @next/next/no-img-element */}
|
|
<img src={voucher.imageUrl} alt={name} className="w-full h-auto max-h-60 object-contain" />
|
|
</div>
|
|
) : (
|
|
<div
|
|
className="h-40 flex items-center justify-center"
|
|
style={{ background: "linear-gradient(145deg,#C94D00 0%,#A83F00 100%)" }}
|
|
>
|
|
<Ticket
|
|
strokeWidth={1.4}
|
|
className="w-16 h-16 stroke-white"
|
|
style={{ filter: "drop-shadow(0 4px 12px rgba(0,0,0,0.4))" }}
|
|
/>
|
|
</div>
|
|
)}
|
|
|
|
<div className="px-5 pt-4 pb-5" style={{ background: "var(--bg-primary)" }}>
|
|
<h2
|
|
id="voucher-modal-title"
|
|
className="text-xl font-extrabold tracking-tight leading-snug break-words"
|
|
style={{ color: "var(--text-primary)" }}
|
|
>
|
|
{name}
|
|
</h2>
|
|
<p className="text-lg font-bold mt-1" style={{ color: "var(--orange-text)" }}>
|
|
{voucher.currencySymbol ?? ""}{voucher.amount}
|
|
</p>
|
|
|
|
{showDescription && (
|
|
<p
|
|
data-testid="voucher-description"
|
|
className="text-sm leading-relaxed mt-3 whitespace-pre-line break-words"
|
|
style={{ color: "var(--text-secondary)" }}
|
|
>
|
|
{description}
|
|
</p>
|
|
)}
|
|
|
|
{voucher.reason === "PROFILE_INCOMPLETE" && (
|
|
<p
|
|
className="text-sm font-semibold leading-relaxed mt-3 rounded-xl px-3 py-2.5"
|
|
style={{
|
|
color: "var(--orange-text)",
|
|
background: "rgba(255,107,0,0.1)",
|
|
border: "1px solid rgba(255,107,0,0.25)",
|
|
}}
|
|
>
|
|
{t("UpdateProfileGetRewardsMessage")}
|
|
</p>
|
|
)}
|
|
|
|
<div className="mt-5">
|
|
{voucher.redeemable ? (
|
|
<Link
|
|
href={`/vouchers/${voucher.uuid}`}
|
|
onClick={onClose}
|
|
className="flex items-center justify-center gap-1 w-full py-3.5 rounded-xl font-bold text-base text-white"
|
|
style={{ background: "linear-gradient(135deg,#C94D00,#A83F00)" }}
|
|
>
|
|
Redeem
|
|
<ChevronRight strokeWidth={2.4} className="w-4 h-4" />
|
|
</Link>
|
|
) : voucher.reason === "PROFILE_INCOMPLETE" ? (
|
|
<Link
|
|
href="/settings/profile"
|
|
onClick={onClose}
|
|
className="flex items-center justify-center gap-1 w-full py-3.5 rounded-xl font-bold text-base text-white"
|
|
style={{ background: "linear-gradient(135deg,#C94D00,#A83F00)" }}
|
|
>
|
|
{t("CompleteProfile")}
|
|
<ChevronRight strokeWidth={2.4} className="w-4 h-4" />
|
|
</Link>
|
|
) : (
|
|
// Not redeemable and nothing the member can do about it: muted, not hidden,
|
|
// so the modal still ends in a clear answer ("Already redeemed", …).
|
|
<button
|
|
type="button"
|
|
disabled
|
|
className="w-full py-3.5 rounded-xl font-bold text-base cursor-not-allowed"
|
|
style={{ background: "var(--bg-card-alt)", color: "var(--text-muted)", border: "1px solid var(--border-color)" }}
|
|
>
|
|
{humaniseReason(voucher.reason)}
|
|
</button>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</motion.div>
|
|
</div>
|
|
</>
|
|
)}
|
|
</AnimatePresence>
|
|
);
|
|
}
|