diff --git a/src/App.tsx b/src/App.tsx index f8b6c95..a0eb2dc 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -6,7 +6,7 @@ import { getCountryRuleByName } from './constants/countries'; import type { ModuleItem, Currency, UserProfile, VerificationResult, PublicPlan } from './types'; import { API_BASE } from './services/api'; import { loadRazorpayScript } from './services/razorpay'; -import { validatePhoneNumber, isValidPhoneNumber, validatePassword, parsePhoneNumber, formatE164Phone } from './utils/validation'; +import { validatePhoneNumber, isValidPhoneNumber, validatePassword, parsePhoneNumber, formatE164Phone, validateEmail } from './utils/validation'; // Modular Subcomponents import { StoreHeader } from './components/layout/StoreHeader'; @@ -442,15 +442,9 @@ export default function App() { 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.'); + const emailErr = validateEmail(trimmedEmail); + if (emailErr) { + setAuthError(emailErr); setAuthLoading(false); return; } @@ -586,15 +580,9 @@ export default function App() { 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.'); + const emailErr = validateEmail(trimmedEmail); + if (emailErr) { + setAuthError(emailErr); setAuthLoading(false); return; } @@ -1179,6 +1167,10 @@ export default function App() { setShowProfileDrawer(false); switchTab('storefront'); }} + onViewSubscriptions={() => { + setShowProfileDrawer(false); + switchTab('subscriptions'); + }} curriculumModules={curriculumModules} onDownloadInvoice={handleDownloadCheckoutInvoice} /> diff --git a/src/components/auth/AuthModal.tsx b/src/components/auth/AuthModal.tsx index e501cc3..3ec79c8 100644 --- a/src/components/auth/AuthModal.tsx +++ b/src/components/auth/AuthModal.tsx @@ -4,7 +4,6 @@ import { Phone, Globe, Eye, EyeOff, LogIn, UserPlus } from 'lucide-react'; import { COUNTRY_CODES, getCountryRuleByName } from '../../constants/countries'; -import { cleanPhoneInput } from '../../utils/validation'; import { PhoneInput } from '../common/PhoneInput'; interface AuthModalProps { @@ -292,9 +291,11 @@ export const AuthModal: React.FC = ({ dialCode={authDialCode} phone={authPhone} country={authCountry} + clearOnDialCodeChange={true} onDialCodeChange={(newCode, newCountry) => { setAuthDialCode(newCode); setAuthCountry(newCountry); + setAuthPhone(''); }} onPhoneChange={(newPhone) => { setAuthPhone(newPhone); @@ -319,11 +320,13 @@ export const AuthModal: React.FC = ({ value={authCountry} onChange={(e) => { const newCountry = e.target.value; - setAuthCountry(newCountry); - const rule = getCountryRuleByName(newCountry); - if (rule) { - setAuthDialCode(rule.code); - setAuthPhone(cleanPhoneInput(authPhone, rule.maxLength, false)); + if (newCountry !== authCountry) { + setAuthCountry(newCountry); + const rule = getCountryRuleByName(newCountry); + if (rule) { + setAuthDialCode(rule.code); + } + setAuthPhone(''); } }} className="w-full bg-slate-950 border border-slate-800 rounded-xl px-4 py-2.5 text-sm font-semibold text-white focus:outline-none focus:border-indigo-500 appearance-none" diff --git a/src/components/catalog/CatalogSection.tsx b/src/components/catalog/CatalogSection.tsx index 377122c..100f62b 100644 --- a/src/components/catalog/CatalogSection.tsx +++ b/src/components/catalog/CatalogSection.tsx @@ -549,7 +549,7 @@ export const CatalogSection: React.FC = ({ diff --git a/src/components/common/PhoneInput.tsx b/src/components/common/PhoneInput.tsx index b3c92c8..9cb7dd3 100644 --- a/src/components/common/PhoneInput.tsx +++ b/src/components/common/PhoneInput.tsx @@ -12,6 +12,7 @@ export interface PhoneInputProps { disabled?: boolean; theme?: 'dark' | 'light'; id?: string; + clearOnDialCodeChange?: boolean; } export const PhoneInput: React.FC = ({ @@ -24,6 +25,7 @@ export const PhoneInput: React.FC = ({ disabled = false, theme = 'dark', id = 'phone-input', + clearOnDialCodeChange = false, }) => { let activeRule = getCountryRuleByDialCode(dialCode); if (!activeRule && country) { @@ -40,8 +42,9 @@ export const PhoneInput: React.FC = ({ if (onDialCodeChange) { onDialCodeChange(newCode, newCountry); } - // Also clamp phone digits to new country's maxLength - if (rule) { + if (clearOnDialCodeChange) { + onPhoneChange(''); + } else if (rule) { onPhoneChange(cleanPhoneInput(phone, rule.maxLength, false)); } }; diff --git a/src/components/layout/StoreHeader.tsx b/src/components/layout/StoreHeader.tsx index 94a0026..d5c2547 100644 --- a/src/components/layout/StoreHeader.tsx +++ b/src/components/layout/StoreHeader.tsx @@ -18,85 +18,116 @@ export const StoreHeader: React.FC = ({ onOpenAuth, }) => { return ( -
-
-
onSwitchTab('storefront')} - className="flex items-center gap-3 cursor-pointer group" - > -
- -
-
-

- ACUPEDIA -

-

TCM PLATFORM

+
+
+
+
onSwitchTab('storefront')} + className="flex items-center gap-3 cursor-pointer group" + > +
+ +
+
+

+ ACUPEDIA +

+

TCM PLATFORM

+
+ + {/* Desktop Navigation Tabs */} +
- {/* Navigation Tabs */} - +
+ {loggedInUser ? ( + + ) : ( +
+ + +
+ )} +
-
- {loggedInUser ? ( - - ) : ( -
- - -
- )} -
+ {/* Mobile Navigation Tabs */} +
); }; diff --git a/src/utils/validation.ts b/src/utils/validation.ts index 65af684..cf26d48 100644 --- a/src/utils/validation.ts +++ b/src/utils/validation.ts @@ -235,3 +235,24 @@ export const validatePassword = (password: string, fieldName = 'Password'): stri return null; }; +/** + * RFC 5322 & RFC 1035 compliant email validation regex. + * Disallows invalid domain characters (e.g. + in domain like +gmail+.com, consecutive dots, leading/trailing hyphens) + * while properly accepting plus-addressing in local-part (e.g. sanskar+sarak@gmail.com). + */ +export const EMAIL_REGEX = /^[a-zA-Z0-9_%+-]+(?:\.[a-zA-Z0-9_%+-]+)*@[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?)*\.[a-zA-Z]{2,}$/; + +export const validateEmail = (email?: string | null): string | null => { + if (!email || !email.trim()) { + return 'Email address is required.'; + } + if (!EMAIL_REGEX.test(email.trim())) { + return 'Please enter a valid email address.'; + } + return null; +}; + +export const isValidEmail = (email?: string | null): boolean => { + return validateEmail(email) === null; +}; +