acupedia-store-ui/src/components/checkout/PaymentSuccessModal.tsx

206 lines
10 KiB
TypeScript

import React from 'react';
import { XCircle, CheckCircle, Check, Download, RefreshCw, Smartphone } from 'lucide-react';
import type { VerificationResult, UserProfile } from '../../types';
import { openMobileApp, getAppDeepLinkUrls } from '../../utils/navigation';
interface PaymentSuccessModalProps {
verificationResult: VerificationResult;
onClose: () => void;
loggedInUser: UserProfile | null;
onDownloadInvoice: (paymentId: string, invoiceUrl?: string) => void;
downloadingInvoice: boolean;
returnRoute?: string;
appScheme?: string;
}
export const PaymentSuccessModal: React.FC<PaymentSuccessModalProps> = ({
verificationResult,
onClose,
loggedInUser,
onDownloadInvoice,
downloadingInvoice,
returnRoute,
appScheme,
}) => {
return (
<div className="fixed inset-0 z-[100] flex items-center justify-center p-4 bg-slate-950/75 backdrop-blur-md transition-all duration-300">
<div className="relative w-full max-w-xl bg-slate-900 border border-slate-800 rounded-2xl p-5 md:p-6 space-y-4 shadow-2xl text-slate-100 overflow-hidden animate-in fade-in zoom-in-95 duration-200">
{/* Ambient Background Glow */}
<div className="absolute -top-10 left-1/2 -translate-x-1/2 w-48 h-48 bg-emerald-500/10 rounded-full blur-3xl pointer-events-none" />
{/* Close button */}
<button
onClick={onClose}
className="absolute top-3 right-3 h-7 w-7 rounded-full bg-slate-800 hover:bg-slate-700/80 flex items-center justify-center text-slate-400 hover:text-slate-200 transition-colors"
>
<XCircle className="h-4 w-4" />
</button>
{/* Glowing animated green checkmark */}
<div className="text-center space-y-2 relative z-10">
<div
className="inline-flex items-center justify-center h-12 w-12 rounded-full bg-emerald-950/80 border border-emerald-500/30 text-emerald-400 shadow-[0_0_20px_rgba(16,185,129,0.25)] animate-bounce"
style={{ animationDuration: '2.5s' }}
>
<CheckCircle className="h-7 w-7" />
</div>
<h3 className="text-lg font-black tracking-tight text-white">
Thank You for Your Purchase!
</h3>
<p className="text-[10px] text-emerald-400 font-extrabold uppercase tracking-wider bg-emerald-950/50 border border-emerald-800/60 px-3 py-1 rounded-full inline-block">
Clinical Modules Unlocked Successfully
</p>
</div>
{/* Content: Mobile App Access Onboarding */}
<div className="bg-slate-950 border border-slate-800/80 rounded-xl p-4 space-y-3 relative z-10">
<p className="text-[11px] text-slate-300 leading-relaxed font-semibold text-center">
Your subscription entitlements are active! Access your content inside the{' '}
<span className="text-indigo-400 font-bold">Acupedia Mobile App</span>. Log in with:{' '}
<span className="text-white underline font-bold">
{loggedInUser?.email || 'your registered email'}
</span>
.
</p>
{/* App download badges */}
<div className="flex justify-center items-center gap-2.5">
{/* Apple App Store */}
<a
href="#appstore"
onClick={(e) => e.preventDefault()}
className="flex items-center gap-2 bg-slate-900 hover:bg-slate-800 text-white px-3.5 py-2 rounded-lg border border-slate-800 hover:border-slate-700 transition-all duration-300 shadow-sm group"
>
<svg className="w-4 h-4 fill-current text-slate-300 group-hover:text-white transition-colors" viewBox="0 0 24 24">
<path d="M18.71,19.5 C17.88,20.74 17,21.95 15.66,21.97 C14.32,22 13.89,21.18 12.37,21.18 C10.84,21.18 10.37,21.95 9.1,22 C7.79,22.05 6.8,20.68 5.96,19.48 C4.25,17 2.94,12.45 4.7,9.39 C5.57,7.87 7.13,6.91 8.82,6.88 C10.1,6.86 11.32,7.75 12.11,7.75 C12.89,7.75 14.37,6.68 15.92,6.84 C16.57,6.87 18.39,7.1 19.56,8.82 C19.47,8.88 17.39,10.1 17.41,12.63 C17.44,15.65 20.06,16.66 20.1,16.67 C20.08,16.74 19.67,18.11 18.71,19.5 M15.97,4.17 C16.63,3.37 17.07,2.28 16.95,1 C16,1.04 14.9,1.6 14.24,2.38 C13.68,3.04 13.19,4.14 13.34,5.39 C14.39,5.47 15.4,4.88 15.97,4.17 Z" />
</svg>
<div className="text-left leading-none">
<p className="text-[8px] text-slate-400 font-bold uppercase tracking-wider mb-0.5">Download on the</p>
<p className="text-xs font-black text-slate-200 group-hover:text-white transition-colors">App Store</p>
</div>
</a>
{/* Google Play Store */}
<a
href="#playstore"
onClick={(e) => e.preventDefault()}
className="flex items-center gap-2 bg-slate-900 hover:bg-slate-800 text-white px-3.5 py-2 rounded-lg border border-slate-800 hover:border-slate-700 transition-all duration-300 shadow-sm group"
>
<svg className="w-4 h-4 fill-current text-slate-300 group-hover:text-white transition-colors" viewBox="0 0 24 24">
<path d="M3,5.27V18.73L16.55,12L3,5.27M17.87,11.33L21,12.92C21.67,13.25 21.67,13.75 21,14.08L17.87,15.67L15,12L17.87,11.33M3,3C3.58,3 4.2,3.22 4.67,3.58L16,11.08L13.13,12L3,3M3,21L13.13,12L16,12.92L4.67,20.42C4.2,20.78 3.58,21 3,21Z" />
</svg>
<div className="text-left leading-none">
<p className="text-[8px] text-slate-400 font-bold uppercase tracking-wider mb-0.5">Get it on</p>
<p className="text-xs font-black text-slate-200 group-hover:text-white transition-colors">Google Play</p>
</div>
</a>
</div>
</div>
{/* Details listing: ID, Invoice, Amount, Items */}
<div className="bg-slate-950/60 border border-slate-800/80 rounded-xl p-3.5 space-y-2.5 text-[11px] relative z-10">
<div className="flex justify-between items-center text-slate-400 font-semibold">
<span>Invoice</span>
<div className="flex items-center gap-1.5">
<span className="text-white font-mono font-bold bg-slate-800 px-2 py-0.5 rounded text-[10px] border border-slate-700/50">
{verificationResult.invoiceNumber}
</span>
{verificationResult.invoiceNumber && (
<button
onClick={() =>
onDownloadInvoice(
verificationResult.paymentId || '',
verificationResult.invoiceUrl
)
}
disabled={downloadingInvoice}
className="text-indigo-400 hover:text-indigo-300 transition-colors p-0.5"
title="Download Invoice PDF"
>
<Download className="h-3 w-3" />
</button>
)}
</div>
</div>
<div className="flex justify-between items-center text-slate-400 font-semibold">
<span>Payment ID</span>
<span className="text-white font-mono font-bold bg-slate-800 px-2 py-0.5 rounded text-[10px] border border-slate-700/50">
{verificationResult.paymentId}
</span>
</div>
<div className="flex justify-between items-center text-slate-400 font-semibold">
<span>Amount Paid</span>
<span className="text-indigo-400 font-extrabold text-xs">
{verificationResult.currency === 'INR'
? `₹${verificationResult.amount}`
: verificationResult.currency === 'EUR'
? `€${verificationResult.amount}`
: `$${verificationResult.amount}`}
</span>
</div>
<div className="h-px bg-slate-800/85" />
<div className="space-y-1 text-left">
<span className="text-[9px] text-slate-500 font-bold uppercase tracking-wider block">
Unlocked Modules
</span>
<div className="flex flex-wrap gap-1">
{verificationResult.items?.map((itemName: string, idx: number) => (
<span
key={idx}
className="bg-indigo-950/50 text-indigo-300 border border-indigo-900/60 text-[9px] font-bold px-2 py-0.5 rounded-md flex items-center gap-1 shadow-sm"
>
<Check className="h-2 w-2 text-indigo-400" /> {itemName}
</span>
))}
</div>
</div>
</div>
{/* Action buttons */}
<div className="space-y-2 relative z-10 mt-2">
{verificationResult.invoiceNumber && (
<button
onClick={() =>
onDownloadInvoice(
verificationResult.paymentId || '',
verificationResult.invoiceUrl
)
}
disabled={downloadingInvoice}
className="w-full h-9 bg-slate-800 hover:bg-slate-700/80 border border-slate-700 text-white font-bold text-xs rounded-lg transition-all duration-300 flex items-center justify-center gap-2 shadow-md"
>
{downloadingInvoice ? (
<RefreshCw className="h-3.5 w-3.5 animate-spin text-indigo-400" />
) : (
<Download className="h-3.5 w-3.5 text-indigo-400" />
)}
{downloadingInvoice ? 'Downloading...' : 'Download Invoice PDF'}
</button>
)}
<a
href={getAppDeepLinkUrls({ route: returnRoute, schemes: appScheme ? [appScheme] : undefined })[0]}
onClick={(e) => {
e.preventDefault();
openMobileApp({ route: returnRoute, schemes: appScheme ? [appScheme] : undefined });
}}
className="w-full h-9 bg-emerald-600 hover:bg-emerald-500 text-white font-bold text-xs rounded-lg transition-all duration-300 flex items-center justify-center gap-2 shadow-md shadow-emerald-600/10 no-underline decoration-0 cursor-pointer"
>
<Smartphone className="h-3.5 w-3.5 text-emerald-200" />
Open in App / Library
</a>
<button
onClick={onClose}
className="w-full h-9 bg-indigo-600 hover:bg-indigo-500 text-white font-bold text-xs rounded-lg transition-all duration-300 flex items-center justify-center gap-2 shadow-md shadow-indigo-600/10"
>
Return to Storefront
</button>
</div>
</div>
</div>
);
};