From 854a412717a743681eadbe2e76b07768af0d6d83 Mon Sep 17 00:00:00 2001 From: Urvish Date: Wed, 14 Oct 2026 16:03:29 +0530 Subject: [PATCH] issue(47): added 10s auto-redirect countdown with pause and fixed discount issue --- src/App.tsx | 14 -- src/components/cart/CartDrawer.tsx | 13 ++ .../checkout/PaymentSuccessModal.tsx | 199 +++++++++++++----- src/types/index.ts | 3 + 4 files changed, 159 insertions(+), 70 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index c812df5..c1e81f6 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -903,20 +903,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); diff --git a/src/components/cart/CartDrawer.tsx b/src/components/cart/CartDrawer.tsx index 9c7c244..bb989e4 100644 --- a/src/components/cart/CartDrawer.tsx +++ b/src/components/cart/CartDrawer.tsx @@ -196,6 +196,18 @@ export const CartDrawer: React.FC = ({ : `$${pricingCalc.base_subtotal}`} + {pricingCalc.renewal_discount_amount > 0 && ( +
+ Early Renewal Discount (20%) + + -{currency === 'INR' + ? `₹${pricingCalc.renewal_discount_amount}` + : currency === 'EUR' + ? `€${pricingCalc.renewal_discount_amount}` + : `$${pricingCalc.renewal_discount_amount}`} + +
+ )} {pricingCalc.bundle_discount_amount > 0 && (
Bundle Discount @@ -221,6 +233,7 @@ export const CartDrawer: React.FC = ({
)} {pricingCalc.total_discounts > 0 && + !pricingCalc.renewal_discount_amount && !pricingCalc.bundle_discount_amount && !pricingCalc.coupon_discount_amount && (
diff --git a/src/components/checkout/PaymentSuccessModal.tsx b/src/components/checkout/PaymentSuccessModal.tsx index 75ce43f..aa77ade 100644 --- a/src/components/checkout/PaymentSuccessModal.tsx +++ b/src/components/checkout/PaymentSuccessModal.tsx @@ -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,41 +23,84 @@ export const PaymentSuccessModal: React.FC = ({ appScheme, }) => { const [desktopNotice, setDesktopNotice] = useState(false); + const [countdown, setCountdown] = useState(10); + const [isRedirectCancelled, setIsRedirectCancelled] = useState(false); + const [isRedirecting, setIsRedirecting] = useState(false); - // Handler to reliably launch the Acupedia Mobile App across platforms (Android, iOS, and Desktop) - const handleOpenApp = (e: React.MouseEvent) => { - e.preventDefault(); + // 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 isAndroid = /Android/i.test(userAgent); const isIOS = /iPhone|iPad|iPod/i.test(userAgent); if (isAndroid) { - // Android Chrome requires an Intent URI format to launch apps by package and scheme reliably - const intentUrl = 'intent://#Intent;scheme=acupedia;package=com.anonymous.acupedia;end'; + // Android Intent format for Chrome / modern Android browsers + const intentUrl = `intent://${route}#Intent;scheme=acupedia;package=com.anonymous.acupedia;end`; window.location.href = intentUrl; - // Fallback to custom URI schemes in case intent fails or Expo uses alternate scheme setTimeout(() => { - window.location.href = 'acupedia://'; + window.location.href = `acupedia://${route}`; }, 500); setTimeout(() => { - window.location.href = 'myapp://'; + window.location.href = `myapp://${route}`; }, 1000); } else if (isIOS) { // iOS Safari and Chrome handle custom URI schemes directly - window.location.href = 'acupedia://'; + const primaryScheme = appScheme || 'acupedia'; + window.location.href = `${primaryScheme}://${route}`; - // Fallback in case Expo uses default 'myapp://' scheme + // Fallback in case alternate scheme was registered in Expo setTimeout(() => { - window.location.href = 'myapp://'; - }, 500); + window.location.href = `acupedia://${route}`; + }, 400); + setTimeout(() => { + window.location.href = `myapp://${route}`; + }, 900); } else { - // On desktop browsers, try opening the registered custom scheme - window.location.href = 'acupedia://'; - // Show helpful desktop feedback informing the user how to access content on mobile + // 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 (
@@ -66,7 +109,7 @@ export const PaymentSuccessModal: React.FC = ({ {/* Close button */}
+ {/* 📱 10-Second Auto-Redirect Tile */} + {showCountdown && !isRedirectCancelled && ( +
+
+
+
+ +
+
+

+ Returning to Acupedia App + + {countdown}s + +

+

+ Redirecting automatically if no action taken +

+
+
+ + +
+ + {/* Countdown progress bar */} +
+
+
+
+ )} + + {/* Banner shown if redirect is cancelled */} + {showCountdown && isRedirectCancelled && ( +
+ + + Auto-redirect paused. Take your time to download your invoice. + + +
+ )} + {/* Content: Mobile App Access Onboarding */} -
+

Your subscription entitlements are active! Access your content inside the{' '} Acupedia Mobile App. Log in with:{' '} @@ -105,14 +207,14 @@ export const PaymentSuccessModal: React.FC = ({ 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" > - +

@@ -120,14 +222,14 @@ export const PaymentSuccessModal: React.FC = ({ 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" > - +
-

Get it on

-

Google Play

+

Get it on

+

Google Play

@@ -143,14 +245,9 @@ export const PaymentSuccessModal: React.FC = ({ {verificationResult.invoiceNumber && ( {desktopNotice && (
@@ -239,8 +326,8 @@ export const PaymentSuccessModal: React.FC = ({ )} diff --git a/src/types/index.ts b/src/types/index.ts index b8a5891..0726d27 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -9,6 +9,7 @@ export interface ModuleItem { priceEur: number; desc: string; color: string; + isRenewal?: boolean; } export interface UserSubscription { @@ -47,6 +48,8 @@ export interface PricingCalculation { grand_total: number; total_amount?: number; currency: Currency; + renewal_discount_amount?: number; + bundle_discount_amount?: number; applied_coupon?: { code: string; discount_type: 'percentage' | 'fixed'; -- 2.34.1