Compare commits
1 Commits
3dbbe11dfa
...
f3fb70d127
| Author | SHA1 | Date |
|---|---|---|
|
|
f3fb70d127 |
208
src/App.tsx
208
src/App.tsx
|
|
@ -19,7 +19,6 @@ import { AuthModal } from './components/auth/AuthModal';
|
||||||
import { ProfileDrawer } from './components/auth/ProfileDrawer';
|
import { ProfileDrawer } from './components/auth/ProfileDrawer';
|
||||||
import { PaymentSuccessModal } from './components/checkout/PaymentSuccessModal';
|
import { PaymentSuccessModal } from './components/checkout/PaymentSuccessModal';
|
||||||
import { PasswordUpdatedModal } from './components/auth/PasswordUpdatedModal';
|
import { PasswordUpdatedModal } from './components/auth/PasswordUpdatedModal';
|
||||||
import { openMobileApp, DEFAULT_RETURN_ROUTE } from './utils/navigation';
|
|
||||||
|
|
||||||
const getInitialTab = (): 'storefront' | 'subscriptions' => {
|
const getInitialTab = (): 'storefront' | 'subscriptions' => {
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
|
|
@ -44,6 +43,14 @@ export default function App() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const handlePopState = () => {
|
||||||
|
setActiveTab(getInitialTab());
|
||||||
|
};
|
||||||
|
window.addEventListener('popstate', handlePopState);
|
||||||
|
return () => window.removeEventListener('popstate', handlePopState);
|
||||||
|
}, []);
|
||||||
|
|
||||||
const [currency, setCurrency] = useState<Currency>('INR');
|
const [currency, setCurrency] = useState<Currency>('INR');
|
||||||
|
|
||||||
// Auth state
|
// Auth state
|
||||||
|
|
@ -99,29 +106,6 @@ export default function App() {
|
||||||
// Active payment state
|
// Active payment state
|
||||||
const [verificationResult, setVerificationResult] = useState<VerificationResult | null>(null);
|
const [verificationResult, setVerificationResult] = useState<VerificationResult | null>(null);
|
||||||
const [razorpayKeyId, setRazorpayKeyId] = useState<string>('');
|
const [razorpayKeyId, setRazorpayKeyId] = useState<string>('');
|
||||||
const [returnRoute, setReturnRoute] = useState<string>(DEFAULT_RETURN_ROUTE);
|
|
||||||
const [appScheme, setAppScheme] = useState<string | undefined>(undefined);
|
|
||||||
|
|
||||||
// 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) {
|
|
||||||
openMobileApp({ route: returnRoute, schemes: appScheme ? [appScheme] : undefined });
|
|
||||||
} else {
|
|
||||||
switchTab('subscriptions');
|
|
||||||
setVerificationResult(null);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setActiveTab(getInitialTab());
|
|
||||||
};
|
|
||||||
window.addEventListener('popstate', handlePopState);
|
|
||||||
return () => window.removeEventListener('popstate', handlePopState);
|
|
||||||
}, [verificationResult, returnRoute, appScheme]);
|
|
||||||
|
|
||||||
// Profile Update & Drawer State
|
// Profile Update & Drawer State
|
||||||
const [showProfileDrawer, setShowProfileDrawer] = useState<boolean>(false);
|
const [showProfileDrawer, setShowProfileDrawer] = useState<boolean>(false);
|
||||||
|
|
@ -146,67 +130,6 @@ export default function App() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Dynamic Curriculum Modules with Live Categories
|
|
||||||
const [curriculumModules, setCurriculumModules] = useState<ModuleItem[]>(CURRICULUM_MODULES);
|
|
||||||
|
|
||||||
const fetchModuleCategories = async () => {
|
|
||||||
try {
|
|
||||||
const res = await axios.get(`${API_BASE}/api/contents/modules`);
|
|
||||||
const apiModules: any[] = res.data?.modules || [];
|
|
||||||
if (apiModules.length > 0) {
|
|
||||||
const normalizeCategory = (cat?: string) => {
|
|
||||||
if (!cat) return null;
|
|
||||||
const c = cat.toLowerCase();
|
|
||||||
if (c === 'point' || c === 'points') return 'Points';
|
|
||||||
if (c === 'pattern' || c === 'patterns') return 'Pattern';
|
|
||||||
if (c === 'nutrition') return 'Nutrition';
|
|
||||||
if (c === 'therapeutics' || c === 'therapeutic') return 'Therapeutics';
|
|
||||||
return cat;
|
|
||||||
};
|
|
||||||
|
|
||||||
setCurriculumModules((prev) =>
|
|
||||||
prev.map((item) => {
|
|
||||||
const matched = apiModules.find((m) => {
|
|
||||||
const mCode = (m.code || '').toLowerCase();
|
|
||||||
const iCode = (item.code || '').toLowerCase();
|
|
||||||
if (mCode && iCode && mCode === iCode) return true;
|
|
||||||
const slug = (m.slug || '').toLowerCase();
|
|
||||||
const mName = (m.name || '').toLowerCase();
|
|
||||||
const iName = item.name.toLowerCase();
|
|
||||||
|
|
||||||
const cleanI = iName.replace('points:', '').replace('therapeutics:', '').split('(')[0].trim();
|
|
||||||
const cleanM = mName.replace('points:', '').replace('therapeutics:', '').split('(')[0].trim();
|
|
||||||
|
|
||||||
if (cleanI.includes('acu') && cleanM.includes('acupuncture') && !cleanI.includes('scalp') && !cleanI.includes('ear')) return true;
|
|
||||||
if (cleanI.includes('scalp') && cleanM.includes('scalp')) return true;
|
|
||||||
if (cleanI.includes('ear') && (cleanM.includes('ear') || slug.includes('auriculo'))) return true;
|
|
||||||
if (cleanI.includes('gyneco') && slug.includes('gyneco')) return true;
|
|
||||||
if (cleanI.includes('eight') && slug.includes('eight')) return true;
|
|
||||||
if (cleanI.includes('zang') && slug.includes('tcm-pattern')) return true;
|
|
||||||
if (cleanI.includes('qi') && slug.includes('qi')) return true;
|
|
||||||
if (cleanI.includes('pathogenic') && slug.includes('pathogenic')) return true;
|
|
||||||
if (cleanI.includes('six') && slug.includes('six')) return true;
|
|
||||||
if (cleanI.includes('four') && slug.includes('four')) return true;
|
|
||||||
if (cleanI.includes('three') && slug.includes('three')) return true;
|
|
||||||
if (cleanI.includes('five') && slug.includes('five')) return true;
|
|
||||||
if (cleanI.includes('food') && slug.includes('nutrition')) return true;
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
const updatedCat = normalizeCategory(matched?.metadata?.category || matched?.category);
|
|
||||||
if (updatedCat) {
|
|
||||||
return { ...item, category: updatedCat };
|
|
||||||
}
|
|
||||||
return item;
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Failed to load module categories:', err);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
const getLivePlan = (code: string) => {
|
const getLivePlan = (code: string) => {
|
||||||
return publicPlans.find(p => p.code === code || p.base_code === code);
|
return publicPlans.find(p => p.code === code || p.base_code === code);
|
||||||
};
|
};
|
||||||
|
|
@ -234,15 +157,6 @@ export default function App() {
|
||||||
const params = new URLSearchParams(window.location.search);
|
const params = new URLSearchParams(window.location.search);
|
||||||
const urlToken = params.get('token');
|
const urlToken = params.get('token');
|
||||||
const urlPlanCode = params.get('planCode');
|
const urlPlanCode = params.get('planCode');
|
||||||
const urlReturnRoute = params.get('returnRoute') || params.get('redirectPath') || params.get('redirect');
|
|
||||||
const urlScheme = params.get('scheme');
|
|
||||||
|
|
||||||
if (urlReturnRoute) {
|
|
||||||
setReturnRoute(urlReturnRoute);
|
|
||||||
}
|
|
||||||
if (urlScheme) {
|
|
||||||
setAppScheme(urlScheme);
|
|
||||||
}
|
|
||||||
|
|
||||||
let activeToken = userToken;
|
let activeToken = userToken;
|
||||||
|
|
||||||
|
|
@ -254,7 +168,7 @@ export default function App() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (urlPlanCode) {
|
if (urlPlanCode) {
|
||||||
const targetModule = curriculumModules.find(m => m.code === urlPlanCode);
|
const targetModule = CURRICULUM_MODULES.find(m => m.code === urlPlanCode);
|
||||||
if (targetModule) {
|
if (targetModule) {
|
||||||
setCart([targetModule]);
|
setCart([targetModule]);
|
||||||
setShowLockedByCategory(prev => ({
|
setShowLockedByCategory(prev => ({
|
||||||
|
|
@ -279,7 +193,6 @@ export default function App() {
|
||||||
});
|
});
|
||||||
|
|
||||||
fetchPublicPlans();
|
fetchPublicPlans();
|
||||||
fetchModuleCategories();
|
|
||||||
|
|
||||||
if (activeToken && !urlToken) {
|
if (activeToken && !urlToken) {
|
||||||
fetchUserProfile(activeToken);
|
fetchUserProfile(activeToken);
|
||||||
|
|
@ -391,33 +304,6 @@ export default function App() {
|
||||||
setAuthLoading(true);
|
setAuthLoading(true);
|
||||||
setAuthError(null);
|
setAuthError(null);
|
||||||
|
|
||||||
const trimmedEmail = authEmail.trim();
|
|
||||||
|
|
||||||
if (!trimmedEmail) {
|
|
||||||
setAuthError('Email address is required.');
|
|
||||||
setAuthLoading(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
||||||
if (!emailRegex.test(trimmedEmail)) {
|
|
||||||
setAuthError('Please enter a valid email address.');
|
|
||||||
setAuthLoading(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!authPassword) {
|
|
||||||
setAuthError('Password is required.');
|
|
||||||
setAuthLoading(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (authMode === 'register' && !authDisplayName.trim()) {
|
|
||||||
setAuthError('Display name is required.');
|
|
||||||
setAuthLoading(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (authMode === 'register' && authPhone && authPhone.trim()) {
|
if (authMode === 'register' && authPhone && authPhone.trim()) {
|
||||||
const phoneError = validatePhoneNumber(authPhone, authDialCode, authCountry);
|
const phoneError = validatePhoneNumber(authPhone, authDialCode, authCountry);
|
||||||
if (phoneError) {
|
if (phoneError) {
|
||||||
|
|
@ -445,26 +331,20 @@ export default function App() {
|
||||||
setAuthLoading(false);
|
setAuthLoading(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (/\p{Extended_Pictographic}/u.test(authPassword)) {
|
if (!/[^A-Za-z0-9\s]/.test(authPassword)) {
|
||||||
setAuthError('Password must not contain emojis.');
|
|
||||||
setAuthLoading(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!/[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?`~]/.test(authPassword)) {
|
|
||||||
setAuthError('Password must contain at least one special character.');
|
setAuthError('Password must contain at least one special character.');
|
||||||
setAuthLoading(false);
|
setAuthLoading(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const fullPhone = authPhone ? `${authDialCode}${authPhone}` : undefined;
|
const fullPhone = authPhone ? `${authDialCode}${authPhone}` : undefined;
|
||||||
const payload = authMode === 'login'
|
const payload = authMode === 'login'
|
||||||
? { email: trimmedEmail, password: authPassword }
|
? { email: authEmail, password: authPassword }
|
||||||
: {
|
: {
|
||||||
email: trimmedEmail,
|
email: authEmail,
|
||||||
password: authPassword,
|
password: authPassword,
|
||||||
full_name: authDisplayName.trim() || undefined,
|
full_name: authDisplayName || undefined,
|
||||||
phone_number: fullPhone,
|
phone_number: fullPhone,
|
||||||
country: authCountry
|
country: authCountry
|
||||||
};
|
};
|
||||||
|
|
@ -548,23 +428,9 @@ export default function App() {
|
||||||
setAuthError(null);
|
setAuthError(null);
|
||||||
setResetSuccessMessage(null);
|
setResetSuccessMessage(null);
|
||||||
|
|
||||||
const trimmedEmail = authEmail.trim();
|
|
||||||
if (!trimmedEmail) {
|
|
||||||
setAuthError('Email address is required.');
|
|
||||||
setAuthLoading(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
||||||
if (!emailRegex.test(trimmedEmail)) {
|
|
||||||
setAuthError('Please enter a valid email address.');
|
|
||||||
setAuthLoading(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await axios.post(`${API_BASE}/api/auth/forgot-password`, {
|
const res = await axios.post(`${API_BASE}/api/auth/forgot-password`, {
|
||||||
email: trimmedEmail
|
email: authEmail
|
||||||
});
|
});
|
||||||
setResetSuccessMessage(res.data.message || 'Verification code sent to your email.');
|
setResetSuccessMessage(res.data.message || 'Verification code sent to your email.');
|
||||||
setResetStep('verify');
|
setResetStep('verify');
|
||||||
|
|
@ -629,22 +495,6 @@ export default function App() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Keep cart items dynamic prices updated when publicPlans are loaded
|
|
||||||
useEffect(() => {
|
|
||||||
if (publicPlans.length > 0 && cart.length > 0) {
|
|
||||||
setCart(prev =>
|
|
||||||
prev.map(item => {
|
|
||||||
const live = getModulePrice(item);
|
|
||||||
return {
|
|
||||||
...item,
|
|
||||||
priceInr: live.priceInr,
|
|
||||||
priceUsd: live.priceUsd,
|
|
||||||
};
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}, [publicPlans]);
|
|
||||||
|
|
||||||
const calculatePricing = async () => {
|
const calculatePricing = async () => {
|
||||||
setLoadingPricing(true);
|
setLoadingPricing(true);
|
||||||
try {
|
try {
|
||||||
|
|
@ -662,15 +512,11 @@ export default function App() {
|
||||||
setPricingCalc(calcData);
|
setPricingCalc(calcData);
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
console.error('Pricing engine calculation error:', err);
|
console.error('Pricing engine calculation error:', err);
|
||||||
if (appliedCoupon) {
|
const errorMsg = err.response?.data?.detail || 'Invalid or expired coupon code.';
|
||||||
const errorMsg = err.response?.data?.detail || 'Invalid or expired coupon code.';
|
setPricingCalc((prev: any) => ({
|
||||||
setPricingCalc((prev: any) => ({
|
...(prev || {}),
|
||||||
...(prev || {}),
|
coupon_error: errorMsg
|
||||||
coupon_error: errorMsg,
|
}));
|
||||||
}));
|
|
||||||
} else {
|
|
||||||
setPricingCalc(null);
|
|
||||||
}
|
|
||||||
} finally {
|
} finally {
|
||||||
setLoadingPricing(false);
|
setLoadingPricing(false);
|
||||||
}
|
}
|
||||||
|
|
@ -896,13 +742,7 @@ export default function App() {
|
||||||
message: verifyRes.data.message || 'Payment verified successfully and module entitlements unlocked!'
|
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
|
||||||
// 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)) {
|
if (/Android|iPhone|iPad|iPod/i.test(navigator.userAgent)) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (/Android/i.test(navigator.userAgent)) {
|
if (/Android/i.test(navigator.userAgent)) {
|
||||||
|
|
@ -1007,7 +847,7 @@ export default function App() {
|
||||||
<div className="grid grid-cols-1 xl:grid-cols-3 gap-6 xl:gap-8">
|
<div className="grid grid-cols-1 xl:grid-cols-3 gap-6 xl:gap-8">
|
||||||
{/* 📦 Catalog Section */}
|
{/* 📦 Catalog Section */}
|
||||||
<CatalogSection
|
<CatalogSection
|
||||||
curriculumModules={curriculumModules}
|
curriculumModules={CURRICULUM_MODULES}
|
||||||
publicPlans={publicPlans}
|
publicPlans={publicPlans}
|
||||||
cart={cart}
|
cart={cart}
|
||||||
currency={currency}
|
currency={currency}
|
||||||
|
|
@ -1065,7 +905,7 @@ export default function App() {
|
||||||
setShowAuthModal(true);
|
setShowAuthModal(true);
|
||||||
}}
|
}}
|
||||||
onSwitchTab={switchTab}
|
onSwitchTab={switchTab}
|
||||||
curriculumModules={curriculumModules}
|
curriculumModules={CURRICULUM_MODULES}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|
@ -1117,8 +957,6 @@ export default function App() {
|
||||||
loggedInUser={loggedInUser}
|
loggedInUser={loggedInUser}
|
||||||
onDownloadInvoice={handleDownloadCheckoutInvoice}
|
onDownloadInvoice={handleDownloadCheckoutInvoice}
|
||||||
downloadingInvoice={downloadingModalInvoice}
|
downloadingInvoice={downloadingModalInvoice}
|
||||||
returnRoute={returnRoute}
|
|
||||||
appScheme={appScheme}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|
@ -1155,7 +993,7 @@ export default function App() {
|
||||||
setShowProfileDrawer(false);
|
setShowProfileDrawer(false);
|
||||||
switchTab('storefront');
|
switchTab('storefront');
|
||||||
}}
|
}}
|
||||||
curriculumModules={curriculumModules}
|
curriculumModules={CURRICULUM_MODULES}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{/* 🔐 Password Updated Success Modal */}
|
{/* 🔐 Password Updated Success Modal */}
|
||||||
|
|
|
||||||
|
|
@ -134,7 +134,7 @@ export const AuthModal: React.FC<AuthModalProps> = ({
|
||||||
{/* Forgot Password Flow */}
|
{/* Forgot Password Flow */}
|
||||||
{authMode === 'forgot' ? (
|
{authMode === 'forgot' ? (
|
||||||
resetStep === 'request' ? (
|
resetStep === 'request' ? (
|
||||||
<form onSubmit={onForgotPasswordRequest} noValidate className="space-y-4 text-left">
|
<form onSubmit={onForgotPasswordRequest} className="space-y-4 text-left">
|
||||||
<div className="space-y-1.5">
|
<div className="space-y-1.5">
|
||||||
<label className="text-[10px] uppercase font-black tracking-wider text-slate-500">
|
<label className="text-[10px] uppercase font-black tracking-wider text-slate-500">
|
||||||
Registered Email Address
|
Registered Email Address
|
||||||
|
|
@ -171,7 +171,7 @@ export const AuthModal: React.FC<AuthModalProps> = ({
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
) : (
|
) : (
|
||||||
<form onSubmit={onResetPasswordSubmit} noValidate className="space-y-4 text-left">
|
<form onSubmit={onResetPasswordSubmit} className="space-y-4 text-left">
|
||||||
<div className="space-y-1.5">
|
<div className="space-y-1.5">
|
||||||
<label className="text-[10px] uppercase font-black tracking-wider text-slate-500">
|
<label className="text-[10px] uppercase font-black tracking-wider text-slate-500">
|
||||||
6-Digit Verification Code (OTP)
|
6-Digit Verification Code (OTP)
|
||||||
|
|
@ -249,7 +249,7 @@ export const AuthModal: React.FC<AuthModalProps> = ({
|
||||||
)
|
)
|
||||||
) : (
|
) : (
|
||||||
/* Standard Login & Register Form */
|
/* Standard Login & Register Form */
|
||||||
<form onSubmit={onAuthSubmit} noValidate className="space-y-4 text-left">
|
<form onSubmit={onAuthSubmit} className="space-y-4 text-left">
|
||||||
{/* Common: Email */}
|
{/* Common: Email */}
|
||||||
<div className="space-y-1.5">
|
<div className="space-y-1.5">
|
||||||
<label className="text-[10px] uppercase font-black tracking-wider text-slate-500">
|
<label className="text-[10px] uppercase font-black tracking-wider text-slate-500">
|
||||||
|
|
|
||||||
|
|
@ -102,16 +102,11 @@ export const CartDrawer: React.FC<CartDrawerProps> = ({
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center gap-3">
|
<div className="flex items-center gap-3">
|
||||||
<span className="text-xs font-bold text-indigo-600">
|
<span className="text-xs font-bold text-indigo-600">
|
||||||
{(() => {
|
{currency === 'INR'
|
||||||
const calculatedItem = pricingCalc?.currency === currency
|
? `₹${item.priceInr}`
|
||||||
? pricingCalc?.cart_items?.find((ci: any) => ci.code === item.code)
|
: currency === 'EUR'
|
||||||
: null;
|
? `€${item.priceEur}`
|
||||||
const price = calculatedItem
|
: `$${item.priceUsd}`}
|
||||||
? calculatedItem.price
|
|
||||||
: (currency === 'INR' ? item.priceInr : currency === 'EUR' ? item.priceEur : item.priceUsd);
|
|
||||||
const symbol = currency === 'INR' ? '₹' : currency === 'EUR' ? '€' : '$';
|
|
||||||
return `${symbol}${price}`;
|
|
||||||
})()}
|
|
||||||
</span>
|
</span>
|
||||||
<button
|
<button
|
||||||
onClick={() => toggleCartItem(item)}
|
onClick={() => toggleCartItem(item)}
|
||||||
|
|
@ -178,13 +173,7 @@ export const CartDrawer: React.FC<CartDrawerProps> = ({
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Checkout Summary Calculations */}
|
{/* Checkout Summary Calculations */}
|
||||||
{loadingPricing && (!pricingCalc || pricingCalc.currency !== currency) && (
|
{pricingCalc && cart.length > 0 && (
|
||||||
<div className="flex items-center justify-center p-6 bg-slate-50 border border-slate-200/60 rounded-2xl gap-2 text-xs font-semibold text-slate-500">
|
|
||||||
<RefreshCw className="h-4 w-4 animate-spin text-indigo-600" />
|
|
||||||
<span>Calculating {currency} pricing...</span>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
{pricingCalc && pricingCalc.currency === currency && cart.length > 0 && (
|
|
||||||
<div className="space-y-3 bg-slate-50 border border-slate-200/60 p-4 rounded-2xl">
|
<div className="space-y-3 bg-slate-50 border border-slate-200/60 p-4 rounded-2xl">
|
||||||
<div className="flex justify-between text-xs text-slate-600 font-bold">
|
<div className="flex justify-between text-xs text-slate-600 font-bold">
|
||||||
<span>Base Subtotal</span>
|
<span>Base Subtotal</span>
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { XCircle, CheckCircle, Check, Download, RefreshCw, Smartphone } from 'lucide-react';
|
import { XCircle, CheckCircle, Check, Download, RefreshCw, Smartphone } from 'lucide-react';
|
||||||
import type { VerificationResult, UserProfile } from '../../types';
|
import type { VerificationResult, UserProfile } from '../../types';
|
||||||
import { openMobileApp, getAppDeepLinkUrls } from '../../utils/navigation';
|
|
||||||
|
|
||||||
interface PaymentSuccessModalProps {
|
interface PaymentSuccessModalProps {
|
||||||
verificationResult: VerificationResult;
|
verificationResult: VerificationResult;
|
||||||
|
|
@ -9,8 +8,6 @@ interface PaymentSuccessModalProps {
|
||||||
loggedInUser: UserProfile | null;
|
loggedInUser: UserProfile | null;
|
||||||
onDownloadInvoice: (paymentId: string, invoiceUrl?: string) => void;
|
onDownloadInvoice: (paymentId: string, invoiceUrl?: string) => void;
|
||||||
downloadingInvoice: boolean;
|
downloadingInvoice: boolean;
|
||||||
returnRoute?: string;
|
|
||||||
appScheme?: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const PaymentSuccessModal: React.FC<PaymentSuccessModalProps> = ({
|
export const PaymentSuccessModal: React.FC<PaymentSuccessModalProps> = ({
|
||||||
|
|
@ -19,8 +16,6 @@ export const PaymentSuccessModal: React.FC<PaymentSuccessModalProps> = ({
|
||||||
loggedInUser,
|
loggedInUser,
|
||||||
onDownloadInvoice,
|
onDownloadInvoice,
|
||||||
downloadingInvoice,
|
downloadingInvoice,
|
||||||
returnRoute,
|
|
||||||
appScheme,
|
|
||||||
}) => {
|
}) => {
|
||||||
const [desktopNotice, setDesktopNotice] = useState(false);
|
const [desktopNotice, setDesktopNotice] = useState(false);
|
||||||
|
|
||||||
|
|
@ -217,18 +212,15 @@ export const PaymentSuccessModal: React.FC<PaymentSuccessModalProps> = ({
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Open in App Button */}
|
{/* Open in App Button */}
|
||||||
{/* Open in App Button */}
|
<a
|
||||||
<a
|
href="acupedia://"
|
||||||
href={getAppDeepLinkUrls({ route: returnRoute, schemes: appScheme ? [appScheme] : undefined })[0]}
|
id="open-in-app-btn"
|
||||||
onClick={(e) => {
|
onClick={handleOpenApp}
|
||||||
e.preventDefault();
|
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"
|
||||||
openMobileApp({ route: returnRoute, schemes: appScheme ? [appScheme] : undefined });
|
>
|
||||||
}}
|
<Smartphone className="h-3.5 w-3.5 text-emerald-200" />
|
||||||
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 in App
|
||||||
>
|
</a>
|
||||||
<Smartphone className="h-3.5 w-3.5 text-emerald-200" />
|
|
||||||
Open in App / Library
|
|
||||||
</a>
|
|
||||||
|
|
||||||
{desktopNotice && (
|
{desktopNotice && (
|
||||||
<div className="p-2.5 bg-slate-950 border border-emerald-900/40 rounded-lg text-center animate-in fade-in duration-200">
|
<div className="p-2.5 bg-slate-950 border border-emerald-900/40 rounded-lg text-center animate-in fade-in duration-200">
|
||||||
|
|
|
||||||
|
|
@ -1,46 +0,0 @@
|
||||||
/**
|
|
||||||
* Generic Navigation & Deep-Linking Utility for Acupedia Storefront
|
|
||||||
*/
|
|
||||||
|
|
||||||
export const DEFAULT_APP_SCHEMES = ['acupedia', 'myapp'];
|
|
||||||
export const DEFAULT_RETURN_ROUTE = 'modules';
|
|
||||||
|
|
||||||
export interface MobileAppLaunchOptions {
|
|
||||||
route?: string;
|
|
||||||
schemes?: string[];
|
|
||||||
delayBetweenFallbacks?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cleanly format route for custom URI scheme (e.g. "/modules" -> "modules")
|
|
||||||
*/
|
|
||||||
export function formatDeepLinkRoute(route?: string): string {
|
|
||||||
if (!route) return DEFAULT_RETURN_ROUTE;
|
|
||||||
return route.replace(/^\/+/, '').trim() || DEFAULT_RETURN_ROUTE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate full deep-link URLs for supported schemes
|
|
||||||
*/
|
|
||||||
export function getAppDeepLinkUrls(options: MobileAppLaunchOptions = {}): string[] {
|
|
||||||
const route = formatDeepLinkRoute(options.route);
|
|
||||||
const schemes = options.schemes && options.schemes.length > 0 ? options.schemes : DEFAULT_APP_SCHEMES;
|
|
||||||
return schemes.map((scheme) => `${scheme}://${route}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generic function to launch the mobile app with progressive fallback across supported schemes
|
|
||||||
*/
|
|
||||||
export function openMobileApp(options: MobileAppLaunchOptions = {}): void {
|
|
||||||
const urls = getAppDeepLinkUrls(options);
|
|
||||||
if (urls.length === 0) return;
|
|
||||||
|
|
||||||
const [primaryUrl, ...fallbackUrls] = urls;
|
|
||||||
window.location.href = primaryUrl;
|
|
||||||
|
|
||||||
fallbackUrls.forEach((url, idx) => {
|
|
||||||
setTimeout(() => {
|
|
||||||
window.location.href = url;
|
|
||||||
}, (idx + 1) * (options.delayBetweenFallbacks || 500));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue