Compare commits
No commits in common. "a1c127e684ed7a0f37d9037fb8b64ce3847a04b7" and "b865f57e4d3c7b496628c86f4d161b2cd7320134" have entirely different histories.
a1c127e684
...
b865f57e4d
30
src/App.tsx
30
src/App.tsx
|
|
@ -6,7 +6,7 @@ import { getCountryRuleByName } from './constants/countries';
|
||||||
import type { ModuleItem, Currency, UserProfile, VerificationResult, PublicPlan } from './types';
|
import type { ModuleItem, Currency, UserProfile, VerificationResult, PublicPlan } from './types';
|
||||||
import { API_BASE } from './services/api';
|
import { API_BASE } from './services/api';
|
||||||
import { loadRazorpayScript } from './services/razorpay';
|
import { loadRazorpayScript } from './services/razorpay';
|
||||||
import { validatePhoneNumber, isValidPhoneNumber, validatePassword, parsePhoneNumber, formatE164Phone, validateEmail } from './utils/validation';
|
import { validatePhoneNumber, isValidPhoneNumber, validatePassword, parsePhoneNumber, formatE164Phone } from './utils/validation';
|
||||||
|
|
||||||
// Modular Subcomponents
|
// Modular Subcomponents
|
||||||
import { StoreHeader } from './components/layout/StoreHeader';
|
import { StoreHeader } from './components/layout/StoreHeader';
|
||||||
|
|
@ -442,9 +442,15 @@ export default function App() {
|
||||||
|
|
||||||
const trimmedEmail = authEmail.trim();
|
const trimmedEmail = authEmail.trim();
|
||||||
|
|
||||||
const emailErr = validateEmail(trimmedEmail);
|
if (!trimmedEmail) {
|
||||||
if (emailErr) {
|
setAuthError('Email address is required.');
|
||||||
setAuthError(emailErr);
|
setAuthLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||||
|
if (!emailRegex.test(trimmedEmail)) {
|
||||||
|
setAuthError('Please enter a valid email address.');
|
||||||
setAuthLoading(false);
|
setAuthLoading(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -580,9 +586,15 @@ export default function App() {
|
||||||
setResetSuccessMessage(null);
|
setResetSuccessMessage(null);
|
||||||
|
|
||||||
const trimmedEmail = authEmail.trim();
|
const trimmedEmail = authEmail.trim();
|
||||||
const emailErr = validateEmail(trimmedEmail);
|
if (!trimmedEmail) {
|
||||||
if (emailErr) {
|
setAuthError('Email address is required.');
|
||||||
setAuthError(emailErr);
|
setAuthLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||||
|
if (!emailRegex.test(trimmedEmail)) {
|
||||||
|
setAuthError('Please enter a valid email address.');
|
||||||
setAuthLoading(false);
|
setAuthLoading(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -1167,10 +1179,6 @@ export default function App() {
|
||||||
setShowProfileDrawer(false);
|
setShowProfileDrawer(false);
|
||||||
switchTab('storefront');
|
switchTab('storefront');
|
||||||
}}
|
}}
|
||||||
onViewSubscriptions={() => {
|
|
||||||
setShowProfileDrawer(false);
|
|
||||||
switchTab('subscriptions');
|
|
||||||
}}
|
|
||||||
curriculumModules={curriculumModules}
|
curriculumModules={curriculumModules}
|
||||||
onDownloadInvoice={handleDownloadCheckoutInvoice}
|
onDownloadInvoice={handleDownloadCheckoutInvoice}
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import {
|
||||||
Phone, Globe, Eye, EyeOff, LogIn, UserPlus
|
Phone, Globe, Eye, EyeOff, LogIn, UserPlus
|
||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
import { COUNTRY_CODES, getCountryRuleByName } from '../../constants/countries';
|
import { COUNTRY_CODES, getCountryRuleByName } from '../../constants/countries';
|
||||||
|
import { cleanPhoneInput } from '../../utils/validation';
|
||||||
import { PhoneInput } from '../common/PhoneInput';
|
import { PhoneInput } from '../common/PhoneInput';
|
||||||
|
|
||||||
interface AuthModalProps {
|
interface AuthModalProps {
|
||||||
|
|
@ -291,11 +292,9 @@ export const AuthModal: React.FC<AuthModalProps> = ({
|
||||||
dialCode={authDialCode}
|
dialCode={authDialCode}
|
||||||
phone={authPhone}
|
phone={authPhone}
|
||||||
country={authCountry}
|
country={authCountry}
|
||||||
clearOnDialCodeChange={true}
|
|
||||||
onDialCodeChange={(newCode, newCountry) => {
|
onDialCodeChange={(newCode, newCountry) => {
|
||||||
setAuthDialCode(newCode);
|
setAuthDialCode(newCode);
|
||||||
setAuthCountry(newCountry);
|
setAuthCountry(newCountry);
|
||||||
setAuthPhone('');
|
|
||||||
}}
|
}}
|
||||||
onPhoneChange={(newPhone) => {
|
onPhoneChange={(newPhone) => {
|
||||||
setAuthPhone(newPhone);
|
setAuthPhone(newPhone);
|
||||||
|
|
@ -320,13 +319,11 @@ export const AuthModal: React.FC<AuthModalProps> = ({
|
||||||
value={authCountry}
|
value={authCountry}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
const newCountry = e.target.value;
|
const newCountry = e.target.value;
|
||||||
if (newCountry !== authCountry) {
|
setAuthCountry(newCountry);
|
||||||
setAuthCountry(newCountry);
|
const rule = getCountryRuleByName(newCountry);
|
||||||
const rule = getCountryRuleByName(newCountry);
|
if (rule) {
|
||||||
if (rule) {
|
setAuthDialCode(rule.code);
|
||||||
setAuthDialCode(rule.code);
|
setAuthPhone(cleanPhoneInput(authPhone, rule.maxLength, false));
|
||||||
}
|
|
||||||
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"
|
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"
|
||||||
|
|
|
||||||
|
|
@ -549,7 +549,7 @@ export const CatalogSection: React.FC<CatalogSectionProps> = ({
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => setShowLockedByCategory(prev => ({ ...prev, Lifetime: true }))}
|
onClick={() => setShowLockedByCategory(prev => ({ ...prev, Lifetime: true }))}
|
||||||
className="mt-1 text-xs text-amber-900 hover:text-amber-950 font-bold hover:underline cursor-pointer"
|
className="mt-1 text-xs text-amber-900 hover:text-black font-bold hover:underline cursor-pointer"
|
||||||
>
|
>
|
||||||
Click here to show locked pass
|
Click here to show locked pass
|
||||||
</button>
|
</button>
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ export interface PhoneInputProps {
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
theme?: 'dark' | 'light';
|
theme?: 'dark' | 'light';
|
||||||
id?: string;
|
id?: string;
|
||||||
clearOnDialCodeChange?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const PhoneInput: React.FC<PhoneInputProps> = ({
|
export const PhoneInput: React.FC<PhoneInputProps> = ({
|
||||||
|
|
@ -25,7 +24,6 @@ export const PhoneInput: React.FC<PhoneInputProps> = ({
|
||||||
disabled = false,
|
disabled = false,
|
||||||
theme = 'dark',
|
theme = 'dark',
|
||||||
id = 'phone-input',
|
id = 'phone-input',
|
||||||
clearOnDialCodeChange = false,
|
|
||||||
}) => {
|
}) => {
|
||||||
let activeRule = getCountryRuleByDialCode(dialCode);
|
let activeRule = getCountryRuleByDialCode(dialCode);
|
||||||
if (!activeRule && country) {
|
if (!activeRule && country) {
|
||||||
|
|
@ -42,9 +40,8 @@ export const PhoneInput: React.FC<PhoneInputProps> = ({
|
||||||
if (onDialCodeChange) {
|
if (onDialCodeChange) {
|
||||||
onDialCodeChange(newCode, newCountry);
|
onDialCodeChange(newCode, newCountry);
|
||||||
}
|
}
|
||||||
if (clearOnDialCodeChange) {
|
// Also clamp phone digits to new country's maxLength
|
||||||
onPhoneChange('');
|
if (rule) {
|
||||||
} else if (rule) {
|
|
||||||
onPhoneChange(cleanPhoneInput(phone, rule.maxLength, false));
|
onPhoneChange(cleanPhoneInput(phone, rule.maxLength, false));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -18,116 +18,85 @@ export const StoreHeader: React.FC<StoreHeaderProps> = ({
|
||||||
onOpenAuth,
|
onOpenAuth,
|
||||||
}) => {
|
}) => {
|
||||||
return (
|
return (
|
||||||
<header className="w-full bg-[#0A0A0E] text-slate-300 border-b border-slate-800 px-4 sm:px-6 py-3 sm:py-4 shadow-lg flex-shrink-0">
|
<header className="w-full bg-[#0A0A0E] text-slate-300 border-b border-slate-800 px-6 py-4 flex items-center justify-between shadow-lg flex-shrink-0">
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center gap-6">
|
||||||
<div className="flex items-center gap-6">
|
<div
|
||||||
<div
|
onClick={() => onSwitchTab('storefront')}
|
||||||
onClick={() => onSwitchTab('storefront')}
|
className="flex items-center gap-3 cursor-pointer group"
|
||||||
className="flex items-center gap-3 cursor-pointer group"
|
>
|
||||||
>
|
<div className="h-10 w-10 rounded-xl bg-gradient-to-tr from-indigo-500 to-cyan-400 flex items-center justify-center shadow-md shadow-indigo-500/20 group-hover:scale-105 transition-transform">
|
||||||
<div className="h-10 w-10 rounded-xl bg-gradient-to-tr from-indigo-500 to-cyan-400 flex items-center justify-center shadow-md shadow-indigo-500/20 group-hover:scale-105 transition-transform">
|
<Sparkles className="h-5 w-5 text-white" />
|
||||||
<Sparkles className="h-5 w-5 text-white" />
|
</div>
|
||||||
</div>
|
<div>
|
||||||
<div>
|
<h1 className="text-base font-black tracking-tight text-white flex items-center gap-1">
|
||||||
<h1 className="text-base font-black tracking-tight text-white flex items-center gap-1">
|
ACUPEDIA
|
||||||
ACUPEDIA
|
</h1>
|
||||||
</h1>
|
<p className="text-[9px] text-slate-400 font-bold tracking-widest uppercase">TCM PLATFORM</p>
|
||||||
<p className="text-[9px] text-slate-400 font-bold tracking-widest uppercase">TCM PLATFORM</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Desktop Navigation Tabs */}
|
|
||||||
<nav className="hidden sm:flex items-center bg-slate-900/80 border border-slate-800 rounded-xl p-1 gap-1">
|
|
||||||
<button
|
|
||||||
onClick={() => onSwitchTab('storefront')}
|
|
||||||
className={`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-bold transition-colors ${
|
|
||||||
activeTab === 'storefront'
|
|
||||||
? 'bg-indigo-600 text-white shadow-sm'
|
|
||||||
: 'text-slate-400 hover:text-slate-200'
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
<BookOpen className="h-3.5 w-3.5" /> Storefront
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
onClick={() => onSwitchTab('subscriptions')}
|
|
||||||
className={`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-bold transition-colors ${
|
|
||||||
activeTab === 'subscriptions'
|
|
||||||
? 'bg-indigo-600 text-white shadow-sm'
|
|
||||||
: 'text-slate-400 hover:text-slate-200'
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
<CheckCircle className="h-3.5 w-3.5" /> My Subscriptions
|
|
||||||
{loggedInUser?.active_subscriptions && loggedInUser.active_subscriptions.length > 0 && (
|
|
||||||
<span className="bg-indigo-900 text-indigo-200 text-[10px] px-1.5 py-0.2 rounded-full ml-0.5">
|
|
||||||
{loggedInUser.active_subscriptions.length}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</button>
|
|
||||||
</nav>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex items-center gap-3">
|
{/* Navigation Tabs */}
|
||||||
{loggedInUser ? (
|
<nav className="hidden sm:flex items-center bg-slate-900/80 border border-slate-800 rounded-xl p-1 gap-1">
|
||||||
<button
|
<button
|
||||||
onClick={onOpenProfile}
|
onClick={() => onSwitchTab('storefront')}
|
||||||
className="flex items-center gap-3 hover:text-white transition-colors group focus:outline-none"
|
className={`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-bold transition-colors ${
|
||||||
>
|
activeTab === 'storefront'
|
||||||
<div className="text-right hidden sm:block">
|
? 'bg-indigo-600 text-white shadow-sm'
|
||||||
<p className="text-xs font-bold text-white truncate max-w-[150px]">
|
: 'text-slate-400 hover:text-slate-200'
|
||||||
{loggedInUser.display_name || loggedInUser.email}
|
}`}
|
||||||
</p>
|
>
|
||||||
</div>
|
<BookOpen className="h-3.5 w-3.5" /> Storefront
|
||||||
<div className="h-9 w-9 rounded-lg bg-indigo-950/60 border border-indigo-500/30 flex items-center justify-center text-indigo-400 font-bold text-sm group-hover:border-indigo-400 transition-colors">
|
</button>
|
||||||
{(loggedInUser.display_name || loggedInUser.email || 'U')[0].toUpperCase()}
|
<button
|
||||||
</div>
|
onClick={() => onSwitchTab('subscriptions')}
|
||||||
</button>
|
className={`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-bold transition-colors ${
|
||||||
) : (
|
activeTab === 'subscriptions'
|
||||||
<div className="flex gap-2">
|
? 'bg-indigo-600 text-white shadow-sm'
|
||||||
<button
|
: 'text-slate-400 hover:text-slate-200'
|
||||||
onClick={() => onOpenAuth('login')}
|
}`}
|
||||||
className="flex items-center justify-center gap-1.5 px-3 py-1.5 rounded-xl text-xs font-bold bg-slate-800 hover:bg-slate-700 text-slate-300 transition-colors"
|
>
|
||||||
>
|
<CheckCircle className="h-3.5 w-3.5" /> My Subscriptions
|
||||||
<LogIn className="h-3.5 w-3.5" /> Login
|
{loggedInUser?.active_subscriptions && loggedInUser.active_subscriptions.length > 0 && (
|
||||||
</button>
|
<span className="bg-indigo-900 text-indigo-200 text-[10px] px-1.5 py-0.2 rounded-full ml-0.5">
|
||||||
<button
|
{loggedInUser.active_subscriptions.length}
|
||||||
onClick={() => onOpenAuth('register')}
|
</span>
|
||||||
className="flex items-center justify-center gap-1.5 px-3 py-1.5 rounded-xl text-xs font-bold bg-indigo-600 hover:bg-indigo-500 text-white transition-colors shadow shadow-indigo-600/10"
|
)}
|
||||||
>
|
</button>
|
||||||
<UserPlus className="h-3.5 w-3.5" /> Join
|
</nav>
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Mobile Navigation Tabs */}
|
<div className="flex items-center gap-3">
|
||||||
<nav className="sm:hidden flex items-center bg-slate-900/90 border border-slate-800 rounded-xl p-1 mt-3 gap-1 w-full">
|
{loggedInUser ? (
|
||||||
<button
|
<button
|
||||||
onClick={() => onSwitchTab('storefront')}
|
onClick={onOpenProfile}
|
||||||
className={`flex-1 flex items-center justify-center gap-1.5 px-3 py-2 rounded-lg text-xs font-bold transition-colors ${
|
className="flex items-center gap-3 hover:text-white transition-colors group focus:outline-none"
|
||||||
activeTab === 'storefront'
|
>
|
||||||
? 'bg-indigo-600 text-white shadow-sm'
|
<div className="text-right hidden sm:block">
|
||||||
: 'text-slate-400 hover:text-slate-200'
|
<p className="text-xs font-bold text-white truncate max-w-[150px]">
|
||||||
}`}
|
{loggedInUser.display_name || loggedInUser.email}
|
||||||
>
|
</p>
|
||||||
<BookOpen className="h-3.5 w-3.5" /> Storefront
|
</div>
|
||||||
</button>
|
<div className="h-9 w-9 rounded-lg bg-indigo-950/60 border border-indigo-500/30 flex items-center justify-center text-indigo-400 font-bold text-sm group-hover:border-indigo-400 transition-colors">
|
||||||
<button
|
{(loggedInUser.display_name || loggedInUser.email || 'U')[0].toUpperCase()}
|
||||||
onClick={() => onSwitchTab('subscriptions')}
|
</div>
|
||||||
className={`flex-1 flex items-center justify-center gap-1.5 px-3 py-2 rounded-lg text-xs font-bold transition-colors ${
|
</button>
|
||||||
activeTab === 'subscriptions'
|
) : (
|
||||||
? 'bg-indigo-600 text-white shadow-sm'
|
<div className="flex gap-2">
|
||||||
: 'text-slate-400 hover:text-slate-200'
|
<button
|
||||||
}`}
|
onClick={() => onOpenAuth('login')}
|
||||||
>
|
className="flex items-center justify-center gap-1.5 px-3 py-1.5 rounded-xl text-xs font-bold bg-slate-800 hover:bg-slate-700 text-slate-300 transition-colors"
|
||||||
<CheckCircle className="h-3.5 w-3.5" /> My Subscriptions
|
>
|
||||||
{loggedInUser?.active_subscriptions && loggedInUser.active_subscriptions.length > 0 && (
|
<LogIn className="h-3.5 w-3.5" /> Login
|
||||||
<span className="bg-indigo-900 text-indigo-200 text-[10px] px-1.5 py-0.2 rounded-full ml-1 font-semibold">
|
</button>
|
||||||
{loggedInUser.active_subscriptions.length}
|
<button
|
||||||
</span>
|
onClick={() => onOpenAuth('register')}
|
||||||
)}
|
className="flex items-center justify-center gap-1.5 px-3 py-1.5 rounded-xl text-xs font-bold bg-indigo-600 hover:bg-indigo-500 text-white transition-colors shadow shadow-indigo-600/10"
|
||||||
</button>
|
>
|
||||||
</nav>
|
<UserPlus className="h-3.5 w-3.5" /> Join
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</header>
|
</header>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -235,24 +235,3 @@ export const validatePassword = (password: string, fieldName = 'Password'): stri
|
||||||
return null;
|
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;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue