Merge pull request 'Issue#7 : fix(checkout) ensure "Open in App" button reliably launches mobile app' (#13) from fix/issue-7-open-in-app into main
Reviewed-on: https://10.10.0.4/AcuPedia/acupedia-store-ui/pulls/13
This commit is contained in:
commit
b01e5bbdf9
11
src/App.tsx
11
src/App.tsx
|
|
@ -675,9 +675,18 @@ export default function App() {
|
|||
message: verifyRes.data.message || 'Payment verified successfully and module entitlements unlocked!'
|
||||
});
|
||||
|
||||
// If on mobile browser, automatically attempt to redirect to mobile app after successful payment
|
||||
if (/Android|iPhone|iPad|iPod/i.test(navigator.userAgent)) {
|
||||
setTimeout(() => {
|
||||
window.location.href = 'acupedia://';
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import React from 'react';
|
||||
import React, { useState } from 'react';
|
||||
import { XCircle, CheckCircle, Check, Download, RefreshCw, Smartphone } from 'lucide-react';
|
||||
import type { VerificationResult, UserProfile } from '../../types';
|
||||
|
||||
|
|
@ -17,6 +17,42 @@ export const PaymentSuccessModal: React.FC<PaymentSuccessModalProps> = ({
|
|||
onDownloadInvoice,
|
||||
downloadingInvoice,
|
||||
}) => {
|
||||
const [desktopNotice, setDesktopNotice] = useState(false);
|
||||
|
||||
// Handler to reliably launch the Acupedia Mobile App across platforms (Android, iOS, and Desktop)
|
||||
const handleOpenApp = (e: React.MouseEvent) => {
|
||||
e.preventDefault();
|
||||
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';
|
||||
window.location.href = intentUrl;
|
||||
|
||||
// Fallback to custom URI schemes in case intent fails or Expo uses alternate scheme
|
||||
setTimeout(() => {
|
||||
window.location.href = 'acupedia://';
|
||||
}, 500);
|
||||
setTimeout(() => {
|
||||
window.location.href = 'myapp://';
|
||||
}, 1000);
|
||||
} else if (isIOS) {
|
||||
// iOS Safari and Chrome handle custom URI schemes directly
|
||||
window.location.href = 'acupedia://';
|
||||
|
||||
// Fallback in case Expo uses default 'myapp://' scheme
|
||||
setTimeout(() => {
|
||||
window.location.href = 'myapp://';
|
||||
}, 500);
|
||||
} 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
|
||||
setDesktopNotice(true);
|
||||
}
|
||||
};
|
||||
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">
|
||||
|
|
@ -175,14 +211,25 @@ export const PaymentSuccessModal: React.FC<PaymentSuccessModalProps> = ({
|
|||
</button>
|
||||
)}
|
||||
|
||||
{/* Open in App Button */}
|
||||
<a
|
||||
href="acupedia://"
|
||||
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"
|
||||
id="open-in-app-btn"
|
||||
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"
|
||||
>
|
||||
<Smartphone className="h-3.5 w-3.5 text-emerald-200" />
|
||||
Open Acupedia Mobile App
|
||||
Open in App
|
||||
</a>
|
||||
|
||||
{desktopNotice && (
|
||||
<div className="p-2.5 bg-slate-950 border border-emerald-900/40 rounded-lg text-center animate-in fade-in duration-200">
|
||||
<p className="text-[11px] text-emerald-400 font-medium">
|
||||
📱 Attempted to launch Acupedia App. If you are on desktop, please open the Acupedia App on your mobile device to view your unlocked content.
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<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"
|
||||
|
|
|
|||
Loading…
Reference in New Issue