Merge pull request 'issue(47): added 10s auto-redirect countdown with pause and fixed discount issue' (#55) from issue-47 into main
Reviewed-on: https://10.10.0.4/AcuPedia/acupedia-store-ui/pulls/55 Reviewed-by: Amit Salunke <amit@noreply.localhost>
This commit is contained in:
commit
84765d4d46
14
src/App.tsx
14
src/App.tsx
|
|
@ -938,20 +938,6 @@ export default function App() {
|
|||
window.history.pushState({ paymentCompleted: true }, document.title, window.location.href);
|
||||
}
|
||||
|
||||
if (/Android|iPhone|iPad|iPod/i.test(navigator.userAgent)) {
|
||||
setTimeout(() => {
|
||||
if (/Android/i.test(navigator.userAgent)) {
|
||||
// Use Android Intent format to avoid blocked navigation in Android Chrome
|
||||
window.location.href = 'intent://#Intent;scheme=acupedia;package=com.anonymous.acupedia;end';
|
||||
setTimeout(() => {
|
||||
window.location.href = 'acupedia://';
|
||||
}, 500);
|
||||
} else {
|
||||
window.location.href = 'acupedia://';
|
||||
}
|
||||
}, 1500);
|
||||
}
|
||||
|
||||
setCart([]);
|
||||
setAppliedCoupon(null);
|
||||
await fetchUserProfile(userToken);
|
||||
|
|
|
|||
|
|
@ -216,6 +216,18 @@ export const CartDrawer: React.FC<CartDrawerProps> = ({
|
|||
: `$${activePricing.base_subtotal}`}
|
||||
</span>
|
||||
</div>
|
||||
{activePricing.renewal_discount_amount > 0 && (
|
||||
<div className="flex justify-between text-xs text-emerald-700 font-bold">
|
||||
<span>Early Renewal Discount (20%)</span>
|
||||
<span>
|
||||
-{currency === 'INR'
|
||||
? `₹${activePricing.renewal_discount_amount}`
|
||||
: currency === 'EUR'
|
||||
? `€${activePricing.renewal_discount_amount}`
|
||||
: `$${activePricing.renewal_discount_amount}`}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
{activePricing.bundle_discount_amount > 0 && (
|
||||
<div className="flex justify-between text-xs text-emerald-700 font-bold">
|
||||
<span>
|
||||
|
|
@ -247,6 +259,7 @@ export const CartDrawer: React.FC<CartDrawerProps> = ({
|
|||
</div>
|
||||
)}
|
||||
{activePricing.total_discounts > 0 &&
|
||||
!activePricing.renewal_discount_amount &&
|
||||
!activePricing.bundle_discount_amount &&
|
||||
!activePricing.coupon_discount_amount && (
|
||||
<div className="flex justify-between text-xs text-emerald-700 font-bold">
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import React, { useState } from 'react';
|
||||
import { XCircle, CheckCircle, Check, Download, RefreshCw, Smartphone } from 'lucide-react';
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { XCircle, CheckCircle, Check, Download, RefreshCw, Smartphone, PauseCircle } from 'lucide-react';
|
||||
import type { VerificationResult, UserProfile } from '../../types';
|
||||
import { openMobileApp, getAppDeepLinkUrls } from '../../utils/navigation';
|
||||
import { formatDeepLinkRoute } from '../../utils/navigation';
|
||||
|
||||
interface PaymentSuccessModalProps {
|
||||
verificationResult: VerificationResult;
|
||||
|
|
@ -23,18 +23,83 @@ export const PaymentSuccessModal: React.FC<PaymentSuccessModalProps> = ({
|
|||
appScheme,
|
||||
}) => {
|
||||
const [desktopNotice, setDesktopNotice] = useState(false);
|
||||
const [countdown, setCountdown] = useState<number>(10);
|
||||
const [isRedirectCancelled, setIsRedirectCancelled] = useState<boolean>(false);
|
||||
const [isRedirecting, setIsRedirecting] = useState<boolean>(false);
|
||||
|
||||
// Handler to reliably launch the Acupedia Mobile App across platforms
|
||||
const handleOpenApp = (e: React.MouseEvent) => {
|
||||
e.preventDefault();
|
||||
openMobileApp({ route: returnRoute, schemes: appScheme ? [appScheme] : undefined });
|
||||
// Enable 10-second auto-redirect countdown tile across all devices (iOS, Android, and web testing)
|
||||
const showCountdown = true;
|
||||
const route = formatDeepLinkRoute(returnRoute || 'modules');
|
||||
|
||||
// Launch mobile app across iOS, Android, and Desktop
|
||||
const launchMobileApp = () => {
|
||||
setIsRedirecting(true);
|
||||
const userAgent = navigator.userAgent || '';
|
||||
const isMobile = /Android|iPhone|iPad|iPod/i.test(userAgent);
|
||||
if (!isMobile) {
|
||||
const isAndroid = /Android/i.test(userAgent);
|
||||
const isIOS = /iPhone|iPad|iPod/i.test(userAgent);
|
||||
|
||||
if (isAndroid) {
|
||||
// Android Intent format for Chrome / modern Android browsers
|
||||
const intentUrl = `intent://${route}#Intent;scheme=acupedia;package=com.anonymous.acupedia;end`;
|
||||
window.location.href = intentUrl;
|
||||
|
||||
setTimeout(() => {
|
||||
window.location.href = `acupedia://${route}`;
|
||||
}, 500);
|
||||
setTimeout(() => {
|
||||
window.location.href = `myapp://${route}`;
|
||||
}, 1000);
|
||||
} else if (isIOS) {
|
||||
// iOS Safari and Chrome handle custom URI schemes directly
|
||||
const primaryScheme = appScheme || 'acupedia';
|
||||
window.location.href = `${primaryScheme}://${route}`;
|
||||
|
||||
// Fallback in case alternate scheme was registered in Expo
|
||||
setTimeout(() => {
|
||||
window.location.href = `acupedia://${route}`;
|
||||
}, 400);
|
||||
setTimeout(() => {
|
||||
window.location.href = `myapp://${route}`;
|
||||
}, 900);
|
||||
} else {
|
||||
// Desktop
|
||||
window.location.href = `acupedia://${route}`;
|
||||
setDesktopNotice(true);
|
||||
}
|
||||
};
|
||||
|
||||
// 10-second auto-redirect countdown for mobile & web app testing
|
||||
useEffect(() => {
|
||||
if (!showCountdown || isRedirectCancelled || isRedirecting) return;
|
||||
|
||||
if (countdown <= 0) {
|
||||
launchMobileApp();
|
||||
return;
|
||||
}
|
||||
|
||||
const timer = setInterval(() => {
|
||||
setCountdown((prev) => {
|
||||
if (prev <= 1) {
|
||||
clearInterval(timer);
|
||||
launchMobileApp();
|
||||
return 0;
|
||||
}
|
||||
return prev - 1;
|
||||
});
|
||||
}, 1000);
|
||||
|
||||
return () => clearInterval(timer);
|
||||
}, [countdown, showCountdown, isRedirectCancelled, isRedirecting]);
|
||||
|
||||
const handleDownloadInvoiceClick = () => {
|
||||
setIsRedirectCancelled(true);
|
||||
onDownloadInvoice(verificationResult.paymentId || '', verificationResult.invoiceUrl);
|
||||
};
|
||||
|
||||
const handleClose = () => {
|
||||
setIsRedirectCancelled(true);
|
||||
onClose();
|
||||
};
|
||||
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">
|
||||
|
|
@ -43,7 +108,7 @@ export const PaymentSuccessModal: React.FC<PaymentSuccessModalProps> = ({
|
|||
|
||||
{/* Close button */}
|
||||
<button
|
||||
onClick={onClose}
|
||||
onClick={handleClose}
|
||||
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" />
|
||||
|
|
@ -65,8 +130,67 @@ export const PaymentSuccessModal: React.FC<PaymentSuccessModalProps> = ({
|
|||
</p>
|
||||
</div>
|
||||
|
||||
{/* 📱 10-Second Auto-Redirect Tile */}
|
||||
{showCountdown && !isRedirectCancelled && (
|
||||
<div className="bg-gradient-to-r from-indigo-950/90 via-slate-900 to-indigo-950/90 border border-indigo-500/40 rounded-xl p-3 space-y-2 relative z-10 shadow-lg shadow-indigo-950/40 animate-in fade-in slide-in-from-top-2 duration-300">
|
||||
<div className="flex items-center justify-between gap-2.5">
|
||||
<div className="flex items-center gap-2.5 min-w-0">
|
||||
<div className="h-8 w-8 rounded-lg bg-indigo-500/20 border border-indigo-500/40 flex items-center justify-center text-indigo-400 flex-shrink-0">
|
||||
<Smartphone className="h-4 w-4 animate-pulse" />
|
||||
</div>
|
||||
<div className="min-w-0 text-left">
|
||||
<p className="text-xs font-bold text-white flex items-center gap-1.5">
|
||||
<span>Returning to Acupedia App</span>
|
||||
<span className="inline-flex items-center justify-center bg-indigo-600 text-white font-mono text-[10px] font-extrabold px-1.5 py-0.5 rounded-md min-w-[22px]">
|
||||
{countdown}s
|
||||
</span>
|
||||
</p>
|
||||
<p className="text-[10px] text-slate-400 font-medium">
|
||||
Redirecting automatically if no action taken
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setIsRedirectCancelled(true)}
|
||||
className="flex-shrink-0 px-2.5 py-1 bg-slate-800 hover:bg-slate-700/80 border border-slate-600/80 hover:border-slate-500 text-slate-200 hover:text-white text-[11px] font-bold rounded-lg transition-colors cursor-pointer flex items-center gap-1"
|
||||
title="Pause redirect and stay on page"
|
||||
>
|
||||
<PauseCircle className="h-3 w-3 text-indigo-400" />
|
||||
<span>Stay on Web</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Countdown progress bar */}
|
||||
<div className="w-full h-1.5 bg-slate-800/80 rounded-full overflow-hidden">
|
||||
<div
|
||||
className="h-full bg-gradient-to-r from-indigo-500 to-emerald-400 rounded-full transition-all duration-1000 ease-linear"
|
||||
style={{ width: `${(countdown / 10) * 100}%` }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Banner shown if redirect is cancelled */}
|
||||
{showCountdown && isRedirectCancelled && (
|
||||
<div className="bg-slate-950/70 border border-slate-800 rounded-xl px-3 py-2 flex items-center justify-between text-[11px] text-slate-400 relative z-10 animate-in fade-in duration-200">
|
||||
<span className="flex items-center gap-1.5">
|
||||
<span className="h-1.5 w-1.5 rounded-full bg-amber-400" />
|
||||
Auto-redirect paused. Take your time to download your invoice.
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={launchMobileApp}
|
||||
className="text-emerald-400 hover:text-emerald-300 font-bold ml-2 underline cursor-pointer flex-shrink-0"
|
||||
>
|
||||
Open App Now
|
||||
</button>
|
||||
</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">
|
||||
<div className="bg-slate-950 border border-slate-800/80 rounded-xl p-3.5 space-y-2.5 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:{' '}
|
||||
|
|
@ -82,14 +206,14 @@ export const PaymentSuccessModal: React.FC<PaymentSuccessModalProps> = ({
|
|||
<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"
|
||||
className="flex items-center gap-2 bg-slate-900 hover:bg-slate-800 text-white px-3 py-1.5 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">
|
||||
<svg className="w-3.5 h-3.5 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>
|
||||
<p className="text-[7px] text-slate-400 font-bold uppercase tracking-wider mb-0.5">Download on the</p>
|
||||
<p className="text-[11px] font-black text-slate-200 group-hover:text-white transition-colors">App Store</p>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
|
|
@ -97,14 +221,14 @@ export const PaymentSuccessModal: React.FC<PaymentSuccessModalProps> = ({
|
|||
<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"
|
||||
className="flex items-center gap-2 bg-slate-900 hover:bg-slate-800 text-white px-3 py-1.5 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">
|
||||
<svg className="w-3.5 h-3.5 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>
|
||||
<p className="text-[7px] text-slate-400 font-bold uppercase tracking-wider mb-0.5">Get it on</p>
|
||||
<p className="text-[11px] font-black text-slate-200 group-hover:text-white transition-colors">Google Play</p>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
|
|
@ -120,14 +244,9 @@ export const PaymentSuccessModal: React.FC<PaymentSuccessModalProps> = ({
|
|||
</span>
|
||||
{verificationResult.invoiceNumber && (
|
||||
<button
|
||||
onClick={() =>
|
||||
onDownloadInvoice(
|
||||
verificationResult.paymentId || '',
|
||||
verificationResult.invoiceUrl
|
||||
)
|
||||
}
|
||||
onClick={handleDownloadInvoiceClick}
|
||||
disabled={downloadingInvoice}
|
||||
className="text-indigo-400 hover:text-indigo-300 transition-colors p-0.5"
|
||||
className="text-indigo-400 hover:text-indigo-300 transition-colors p-0.5 cursor-pointer"
|
||||
title="Download Invoice PDF"
|
||||
>
|
||||
<Download className="h-3 w-3" />
|
||||
|
|
@ -175,14 +294,9 @@ export const PaymentSuccessModal: React.FC<PaymentSuccessModalProps> = ({
|
|||
<div className="space-y-2 relative z-10 mt-2">
|
||||
{verificationResult.invoiceNumber && (
|
||||
<button
|
||||
onClick={() =>
|
||||
onDownloadInvoice(
|
||||
verificationResult.paymentId || '',
|
||||
verificationResult.invoiceUrl
|
||||
)
|
||||
}
|
||||
onClick={handleDownloadInvoiceClick}
|
||||
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"
|
||||
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 cursor-pointer"
|
||||
>
|
||||
{downloadingInvoice ? (
|
||||
<RefreshCw className="h-3.5 w-3.5 animate-spin text-indigo-400" />
|
||||
|
|
@ -194,14 +308,13 @@ export const PaymentSuccessModal: React.FC<PaymentSuccessModalProps> = ({
|
|||
)}
|
||||
|
||||
{/* Open in App Button */}
|
||||
<a
|
||||
href={getAppDeepLinkUrls({ route: returnRoute, schemes: appScheme ? [appScheme] : undefined })[0]}
|
||||
onClick={handleOpenApp}
|
||||
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"
|
||||
<button
|
||||
onClick={launchMobileApp}
|
||||
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 cursor-pointer"
|
||||
>
|
||||
<Smartphone className="h-3.5 w-3.5 text-emerald-200" />
|
||||
Open in App / Library
|
||||
</a>
|
||||
</button>
|
||||
|
||||
{desktopNotice && (
|
||||
<div className="p-2.5 bg-slate-950 border border-emerald-900/40 rounded-lg text-center animate-in fade-in duration-200">
|
||||
|
|
@ -212,8 +325,8 @@ export const PaymentSuccessModal: React.FC<PaymentSuccessModalProps> = ({
|
|||
)}
|
||||
|
||||
<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"
|
||||
onClick={handleClose}
|
||||
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 cursor-pointer"
|
||||
>
|
||||
Return to Storefront
|
||||
</button>
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ export interface ModuleItem {
|
|||
priceEur: number;
|
||||
desc: string;
|
||||
color: string;
|
||||
isRenewal?: boolean;
|
||||
}
|
||||
|
||||
export interface UserSubscription {
|
||||
|
|
@ -54,6 +55,7 @@ export interface PricingCalculation {
|
|||
grand_total: number;
|
||||
total_amount?: number;
|
||||
currency: Currency;
|
||||
renewal_discount_amount?: number;
|
||||
coupon_applied?: string;
|
||||
coupon_discount_amount?: number;
|
||||
coupon_error?: string | null;
|
||||
|
|
|
|||
Loading…
Reference in New Issue