From 3f536986de5ebcc6fae9561267989e000d4fc434 Mon Sep 17 00:00:00 2001 From: ShivaniKhaire Date: Mon, 5 Oct 2026 14:23:21 +0530 Subject: [PATCH 1/2] fix(checkout): redirect back navigation to library after module purchase (#12) --- src/App.tsx | 43 +++++++++++++++---- .../checkout/PaymentSuccessModal.tsx | 25 +++++++++-- 2 files changed, 56 insertions(+), 12 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 8c5ec65..a3c2ef6 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -41,14 +41,6 @@ export default function App() { } }; - useEffect(() => { - const handlePopState = () => { - setActiveTab(getInitialTab()); - }; - window.addEventListener('popstate', handlePopState); - return () => window.removeEventListener('popstate', handlePopState); - }, []); - const [currency, setCurrency] = useState('INR'); // Auth state @@ -105,6 +97,30 @@ export default function App() { const [verificationResult, setVerificationResult] = useState(null); const [razorpayKeyId, setRazorpayKeyId] = useState(''); + // Handle browser back button navigation + useEffect(() => { + const handlePopState = () => { + // If purchase was completed and user presses the Back button, + // redirect them to the mobile app's All Modules / Library instead of Subscription page + if (verificationResult && verificationResult.status === 'success') { + const isMobile = /Android|iPhone|iPad|iPod/i.test(navigator.userAgent); + if (isMobile) { + window.location.href = 'acupedia://modules'; + setTimeout(() => { + window.location.href = 'myapp://modules'; + }, 500); + } else { + switchTab('subscriptions'); + setVerificationResult(null); + } + return; + } + setActiveTab(getInitialTab()); + }; + window.addEventListener('popstate', handlePopState); + return () => window.removeEventListener('popstate', handlePopState); + }, [verificationResult]); + // Profile Update & Drawer State const [showProfileDrawer, setShowProfileDrawer] = useState(false); const [profileDisplayName, setProfileDisplayName] = useState(''); @@ -658,9 +674,18 @@ export default function App() { message: verifyRes.data.message || 'Payment verified successfully and module entitlements unlocked!' }); + // Push a history state so that pressing browser/device Back button will be intercepted + // by popstate and redirected to All Modules / Library instead of returning to the Subscription page + if (typeof window !== 'undefined') { + window.history.pushState({ paymentCompleted: true }, document.title, window.location.href); + } + if (/Android|iPhone|iPad|iPod/i.test(navigator.userAgent)) { setTimeout(() => { - window.location.href = 'acupedia://'; + window.location.href = 'acupedia://modules'; + setTimeout(() => { + window.location.href = 'myapp://modules'; + }, 500); }, 1500); } diff --git a/src/components/checkout/PaymentSuccessModal.tsx b/src/components/checkout/PaymentSuccessModal.tsx index f665a26..5684b44 100644 --- a/src/components/checkout/PaymentSuccessModal.tsx +++ b/src/components/checkout/PaymentSuccessModal.tsx @@ -176,11 +176,30 @@ export const PaymentSuccessModal: React.FC = ({ )} { + e.preventDefault(); + const userAgent = navigator.userAgent || ''; + const isAndroid = /Android/i.test(userAgent); + const isIOS = /iPhone|iPad|iPod/i.test(userAgent); + if (isAndroid) { + window.location.href = 'acupedia://modules'; + setTimeout(() => { + window.location.href = 'myapp://modules'; + }, 500); + } else if (isIOS) { + window.location.href = 'acupedia://modules'; + setTimeout(() => { + window.location.href = 'myapp://modules'; + }, 500); + } else { + window.location.href = 'acupedia://modules'; + } + }} + 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" > - Open Acupedia Mobile App + Open in App / Library