diff --git a/package-lock.json b/package-lock.json index 3499fd6..f5ad8ea 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "1.0.0", "dependencies": { "axios": "^1.7.0", + "libphonenumber-js": "^1.13.16", "lucide-react": "^0.460.0", "react": "^19.0.0", "react-dom": "^19.0.0" @@ -3455,6 +3456,12 @@ "node": ">= 0.8.0" } }, + "node_modules/libphonenumber-js": { + "version": "1.13.16", + "resolved": "https://registry.npmjs.org/libphonenumber-js/-/libphonenumber-js-1.13.16.tgz", + "integrity": "sha512-tIOCM9yx2Go6d5/ZANe0K+G4AZek1Ymx81HxQpf19Sri4zMP95eQbKdnUGHAvFQ4nx0PeLhFqvAfisTADXj3tQ==", + "license": "MIT" + }, "node_modules/lightningcss": { "version": "1.32.0", "resolved": "https://registry.npmjs.org/lightningcss/-/lightningcss-1.32.0.tgz", diff --git a/package.json b/package.json index 52b54af..14dab7a 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ }, "dependencies": { "axios": "^1.7.0", + "libphonenumber-js": "^1.13.16", "lucide-react": "^0.460.0", "react": "^19.0.0", "react-dom": "^19.0.0" diff --git a/src/App.tsx b/src/App.tsx index 41721d8..a08dd5a 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -20,20 +20,27 @@ import { ProfileDrawer } from './components/auth/ProfileDrawer'; import { PaymentSuccessModal } from './components/checkout/PaymentSuccessModal'; import { PasswordUpdatedModal } from './components/auth/PasswordUpdatedModal'; import { BillingPhoneModal } from './components/checkout/BillingPhoneModal'; +import { LoggedOutView } from './components/auth/LoggedOutView'; import { openMobileApp, DEFAULT_RETURN_ROUTE } from './utils/navigation'; -const getInitialTab = (): 'storefront' | 'subscriptions' => { +const getInitialTab = (): 'storefront' | 'subscriptions' | 'logged-out' => { if (typeof window !== 'undefined') { const path = window.location.pathname.toLowerCase(); + if (path.includes('/logged-out')) return 'logged-out'; if (path.includes('/subscriptions')) return 'subscriptions'; + + const params = new URLSearchParams(window.location.search); + if (params.get('logged_out') === 'true' || params.get('status') === 'logged-out') { + return 'logged-out'; + } } return 'storefront'; }; export default function App() { - const [activeTab, setActiveTab] = useState<'storefront' | 'subscriptions'>(getInitialTab); + const [activeTab, setActiveTab] = useState<'storefront' | 'subscriptions' | 'logged-out'>(getInitialTab); - const switchTab = (tab: 'storefront' | 'subscriptions') => { + const switchTab = (tab: 'storefront' | 'subscriptions' | 'logged-out') => { setActiveTab(tab); if (typeof window !== 'undefined') { const isStorePrefix = window.location.pathname.startsWith('/store'); @@ -159,60 +166,89 @@ export default function App() { const res = await axios.get(`${API_BASE}/api/plans`); if (Array.isArray(res.data)) { setPublicPlans(res.data); + fetchModuleCategories(res.data); } } catch (err) { console.error('Failed to load public plans:', err); } }; - // Dynamic Curriculum Modules with Live Categories + // Dynamic Curriculum Modules with Live Categories const [curriculumModules, setCurriculumModules] = useState(CURRICULUM_MODULES); - const fetchModuleCategories = async () => { + const fetchModuleCategories = async (plansList?: PublicPlan[]) => { try { const res = await axios.get(`${API_BASE}/api/contents/modules`); const apiModules: any[] = res.data?.modules || []; + const currentPlans = plansList && plansList.length > 0 ? plansList : publicPlans; if (apiModules.length > 0) { - const normalizeCategory = (cat?: string) => { + const normalizeCategory = (cat?: string): string | null => { if (!cat) return null; - const c = cat.toLowerCase(); + const c = cat.toLowerCase().trim(); if (c === 'point' || c === 'points') return 'Points'; - if (c === 'pattern' || c === 'patterns') return 'Pattern'; + if (c === 'pattern' || c === 'patterns' || c === 'five-elements') return 'Pattern'; if (c === 'nutrition') return 'Nutrition'; if (c === 'therapeutics' || c === 'therapeutic') return 'Therapeutics'; - return cat; + if (c === 'lifetime') return 'Lifetime'; + return cat.charAt(0).toUpperCase() + cat.slice(1); }; setCurriculumModules((prev) => prev.map((item) => { - const matched = apiModules.find((m) => { - const mCode = (m.code || '').toLowerCase(); + // 1. If item maps directly to a plan with single module slug, match by that slug + const matchedPlan = currentPlans.find((p) => p.code === item.code || p.base_code === item.code); + let matched: any = null; + if (matchedPlan) { + const slugs: string[] = matchedPlan.module_slugs || (matchedPlan.modules || []).map((m: any) => m.slug).filter(Boolean); + if (slugs.length === 1) { + const targetSlug = slugs[0].toLowerCase(); + matched = apiModules.find((m) => (m.slug || '').toLowerCase() === targetSlug); + } + } + + // 2. Direct code match + if (!matched) { const iCode = (item.code || '').toLowerCase(); - if (mCode && iCode && mCode === iCode) return true; - const slug = (m.slug || '').toLowerCase(); - const mName = (m.name || '').toLowerCase(); + matched = apiModules.find((m) => (m.code || '').toLowerCase() === iCode); + } + + // 3. Normalized semantic match without collisions + if (!matched) { 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; - }); + matched = apiModules.find((m) => { + const mSlug = (m.slug || '').toLowerCase(); + const mName = (m.name || '').toLowerCase(); + const cleanM = mName.replace('points:', '').replace('therapeutics:', '').split('(')[0].trim(); - const updatedCat = normalizeCategory(matched?.metadata?.category || matched?.category); + if (cleanI.includes('scalp') && (cleanM.includes('scalp') || mSlug.includes('scalp'))) return true; + + // Disambiguate Ear Reflexology / Auriculotherapy vs Ear Acupuncture + if (cleanI.includes('reflexology') || item.code === 'THERAPEUTICS_EAR') { + return mSlug.includes('auriculo') || cleanM.includes('reflexology') || mSlug.includes('reflexology'); + } + if (cleanI.includes('ear') || item.code === 'POINTS_EAR') { + return mSlug.includes('ear-acupuncture') || (cleanM.includes('ear') && !mSlug.includes('auriculo') && !cleanM.includes('reflexology')); + } + + if (cleanI.includes('acu') && cleanM.includes('acupuncture') && !cleanI.includes('scalp') && !cleanI.includes('ear')) return true; + if (cleanI.includes('gyneco') && mSlug.includes('gyneco')) return true; + if (cleanI.includes('eight') && mSlug.includes('eight')) return true; + if (cleanI.includes('zang') && mSlug.includes('tcm-pattern')) return true; + if (cleanI.includes('qi') && mSlug.includes('qi')) return true; + if (cleanI.includes('pathogenic') && mSlug.includes('pathogenic')) return true; + if (cleanI.includes('six') && mSlug.includes('six')) return true; + if (cleanI.includes('four') && mSlug.includes('four')) return true; + if (cleanI.includes('three') && mSlug.includes('three')) return true; + if (cleanI.includes('five') && mSlug.includes('five')) return true; + if (cleanI.includes('food') && mSlug.includes('nutrition')) return true; + return false; + }); + } + + const rawCat = matched?.category || matched?.metadata?.category || matched?.metadata?.kind; + const updatedCat = normalizeCategory(rawCat); if (updatedCat) { return { ...item, category: updatedCat }; } @@ -261,6 +297,12 @@ export default function App() { const urlPlanCode = params.get('planCode'); const urlReturnRoute = params.get('returnRoute') || params.get('redirectPath') || params.get('redirect'); const urlScheme = params.get('scheme'); + const shouldOpenLogin = params.get('login') === 'true' || params.get('auth') === 'login'; + + if (shouldOpenLogin) { + setAuthMode('login'); + setShowAuthModal(true); + } if (urlReturnRoute) { setReturnRoute(urlReturnRoute); @@ -292,10 +334,15 @@ export default function App() { } } - if (urlToken || urlPlanCode) { + if (urlToken || urlPlanCode || shouldOpenLogin) { const isStorePrefix = window.location.pathname.startsWith('/store'); const basePath = isStorePrefix ? '/store/' : '/'; - const cleanPath = activeTab === 'subscriptions' ? `${basePath}subscriptions` : basePath; + const cleanPath = + activeTab === 'subscriptions' + ? `${basePath}subscriptions` + : activeTab === 'logged-out' + ? `${basePath}logged-out` + : basePath; window.history.replaceState({}, document.title, cleanPath); } @@ -374,13 +421,14 @@ export default function App() { setAppliedCoupon(null); setCouponCode(''); setPricingCalc(null); - switchTab('storefront'); handleCloseProfileDrawer(); setProfileDisplayName(''); setProfilePhone(''); setProfileCountry('India'); setProfileError(null); setProfileSuccess(false); + setShowAuthModal(false); + switchTab('logged-out'); }; const handleUpdateProfile = async (e: React.FormEvent) => { @@ -399,7 +447,7 @@ export default function App() { setProfileSaving(false); return; } - cleanedPhoneToSave = formatE164Phone(parsed.dialCode, parsed.localDigits); + cleanedPhoneToSave = formatE164Phone(parsed.dialCode, parsed.localDigits, profileCountry); } try { @@ -492,8 +540,7 @@ export default function App() { setAuthLoading(false); return; } - const rawDigits = authPhone.replace(/\D/g, ''); - fullPhone = `${authDialCode}${rawDigits}`; + fullPhone = formatE164Phone(authDialCode, authPhone, authCountry); } const endpoint = authMode === 'login' ? '/api/auth/login' : '/api/auth/register'; @@ -530,6 +577,9 @@ export default function App() { setAuthEmail(''); setAuthDisplayName(''); setAuthPhone(''); + if (activeTab === 'logged-out') { + switchTab('storefront'); + } setShowPasswordChange(false); setChangeOldPassword(''); setChangeNewPassword(''); @@ -909,7 +959,7 @@ export default function App() { // Sanitize contact for Razorpay: strictly E.164 (+) const parsedContact = parsePhoneNumber(loggedInUser?.phone_number, loggedInUser?.country || 'India'); - const sanitizedContact = formatE164Phone(parsedContact.dialCode, parsedContact.localDigits); + const sanitizedContact = formatE164Phone(parsedContact.dialCode, parsedContact.localDigits, loggedInUser?.country || 'India'); const rzpOptions = { key: razorpayKeyId, @@ -1095,6 +1145,14 @@ export default function App() { /> + ) : activeTab === 'logged-out' ? ( + { + switchTab('storefront'); + setAuthMode('login'); + setShowAuthModal(true); + }} + /> ) : ( /* ๐Ÿงพ Tab: User Personal Subscriptions Ledger */ void; +} + +export const LoggedOutView: React.FC = ({ + onLoginAgain, +}) => { + const isStorePrefix = + typeof window !== 'undefined' && window.location.pathname.startsWith('/store'); + const basePath = isStorePrefix ? '/store/' : '/'; + const loginUrl = `${basePath}?login=true`; + const loginDisplayUrl = + typeof window !== 'undefined' + ? `${window.location.origin}${loginUrl}` + : loginUrl; + + return ( +
+
+ {/* Status Badge Icon */} +
+ +
+ + {/* Title & Description */} +

+ Successfully Logged Out +

+

+ You have been securely signed out of your AcuPedia session. Thank you for using our platform. +

+ + {/* Security Notice */} +
+ +

+ For security, please close your browser window if you are using a shared or public device. +

+
+ + {/* Actions */} + + + {/* Option to login in again via URL (explicit link for user / copy) */} + +
+
+ ); +}; + diff --git a/src/components/auth/ProfileDrawer.tsx b/src/components/auth/ProfileDrawer.tsx index ee98edd..f4a8b86 100644 --- a/src/components/auth/ProfileDrawer.tsx +++ b/src/components/auth/ProfileDrawer.tsx @@ -101,7 +101,7 @@ export const ProfileDrawer: React.FC = ({ const handleLocalPhoneChange = (newLocal: string) => { setLocalPhone(newLocal); - setProfilePhone(newLocal ? formatE164Phone(dialCode, newLocal) : ''); + setProfilePhone(newLocal ? formatE164Phone(dialCode, newLocal, profileCountry) : ''); }; const handleDialCodeChange = (newCode: string, newCountry: string) => { @@ -111,7 +111,7 @@ export const ProfileDrawer: React.FC = ({ setCurrency(rule.currency); const clamped = cleanPhoneInput(localPhone, rule.maxLength, false); setLocalPhone(clamped); - setProfilePhone(formatE164Phone(newCode, clamped)); + setProfilePhone(formatE164Phone(newCode, clamped, newCountry)); }; const handleCountrySelectChange = (newCountry: string) => { @@ -121,7 +121,7 @@ export const ProfileDrawer: React.FC = ({ setCurrency(rule.currency); const clamped = cleanPhoneInput(localPhone, rule.maxLength, false); setLocalPhone(clamped); - setProfilePhone(formatE164Phone(rule.code, clamped)); + setProfilePhone(formatE164Phone(rule.code, clamped, newCountry)); }; if (!isOpen || !loggedInUser) return null; diff --git a/src/components/catalog/CatalogSection.tsx b/src/components/catalog/CatalogSection.tsx index 100f62b..f942b3d 100644 --- a/src/components/catalog/CatalogSection.tsx +++ b/src/components/catalog/CatalogSection.tsx @@ -176,7 +176,7 @@ export const CatalogSection: React.FC = ({ onClick={() => setShowLockedByCategory(prev => ({ ...prev, Pattern: !prev.Pattern }))} className="text-[9px] bg-slate-100 hover:bg-slate-200 text-slate-700 border border-slate-200 font-bold px-1.5 py-0.5 rounded transition-colors whitespace-nowrap shrink-0" > - {showLockedByCategory.Pattern ? 'Hide Locked' : 'Show Locked'} ({curriculumModules.filter(m => m.category === 'Pattern' && !isModuleUnlocked(m.code)).length}) + {showLockedByCategory.Pattern ? 'Hide Locked' : 'Show Locked'} ({curriculumModules.filter(m => (m.category === 'Pattern' || m.category === 'Patterns') && !isModuleUnlocked(m.code)).length}) @@ -191,7 +191,7 @@ export const CatalogSection: React.FC = ({
{(() => { - const items = curriculumModules.filter(m => m.category === 'Pattern'); + const items = curriculumModules.filter(m => m.category === 'Pattern' || m.category === 'Patterns'); const visible = items.filter(sub => { const isUnlocked = isModuleUnlocked(sub.code); const live = getModulePrice(sub); diff --git a/src/components/checkout/BillingPhoneModal.tsx b/src/components/checkout/BillingPhoneModal.tsx index d0e2418..925a61f 100644 --- a/src/components/checkout/BillingPhoneModal.tsx +++ b/src/components/checkout/BillingPhoneModal.tsx @@ -53,7 +53,7 @@ export const BillingPhoneModal: React.FC = ({ } setSaving(true); - const e164 = formatE164Phone(dialCode, phone); + const e164 = formatE164Phone(dialCode, phone, country); try { const success = await onSavePhone(e164, country); if (success) { diff --git a/src/components/common/PhoneInput.tsx b/src/components/common/PhoneInput.tsx index 311cddb..38d8ad2 100644 --- a/src/components/common/PhoneInput.tsx +++ b/src/components/common/PhoneInput.tsx @@ -27,24 +27,24 @@ export const PhoneInput: React.FC = ({ id = 'phone-input', clearOnDialCodeChange = false, }) => { - let activeRule = getCountryRuleByDialCode(dialCode); - if (!activeRule && country) { - activeRule = getCountryRuleByName(country); + // Prioritize country name if available, fallback to dial code + let activeRule = country ? getCountryRuleByName(country) : undefined; + if (!activeRule && dialCode) { + activeRule = getCountryRuleByDialCode(dialCode, country); } if (!activeRule) { activeRule = getCountryRuleByDialCode('+91')!; } - const handleDialCodeSelect = (e: React.ChangeEvent) => { - const newCode = e.target.value; - const rule = getCountryRuleByDialCode(newCode); - const newCountry = rule ? rule.country : (country || 'India'); + const handleCountrySelect = (e: React.ChangeEvent) => { + const selectedCountryName = e.target.value; + const rule = getCountryRuleByName(selectedCountryName); if (onDialCodeChange) { - onDialCodeChange(newCode, newCountry); + onDialCodeChange(rule.code, rule.country); } if (clearOnDialCodeChange) { onPhoneChange(''); - } else if (rule) { + } else { onPhoneChange(cleanPhoneInput(phone, rule.maxLength, false)); } }; @@ -58,7 +58,7 @@ export const PhoneInput: React.FC = ({ const sorted = [...COUNTRY_CODES].sort((a, b) => b.code.length - a.code.length); const matched = sorted.find((c) => trimmed.startsWith(c.code)); if (matched) { - if (onDialCodeChange && matched.code !== dialCode) { + if (onDialCodeChange && (matched.code !== dialCode || matched.country !== country)) { onDialCodeChange(matched.code, matched.country); } const rest = trimmed.slice(matched.code.length).replace(/\D/g, ''); @@ -108,11 +108,11 @@ export const PhoneInput: React.FC = ({ return (
- {/* Country Code Dropdown */} -
+ {/* Country Code Dropdown: keyed by unique country name to avoid +1 (US vs CA) collisions */} +