Merge branch 'main' into fix/standardized-phone-validation-and-billing
This commit is contained in:
commit
a1c127e684
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 { 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}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -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<AuthModalProps> = ({
|
|||
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<AuthModalProps> = ({
|
|||
value={authCountry}
|
||||
onChange={(e) => {
|
||||
const newCountry = e.target.value;
|
||||
if (newCountry !== authCountry) {
|
||||
setAuthCountry(newCountry);
|
||||
const rule = getCountryRuleByName(newCountry);
|
||||
if (rule) {
|
||||
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"
|
||||
|
|
|
|||
|
|
@ -549,7 +549,7 @@ export const CatalogSection: React.FC<CatalogSectionProps> = ({
|
|||
<button
|
||||
type="button"
|
||||
onClick={() => setShowLockedByCategory(prev => ({ ...prev, Lifetime: true }))}
|
||||
className="mt-1 text-xs text-amber-900 hover:text-black font-bold hover:underline cursor-pointer"
|
||||
className="mt-1 text-xs text-amber-900 hover:text-amber-950 font-bold hover:underline cursor-pointer"
|
||||
>
|
||||
Click here to show locked pass
|
||||
</button>
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ export interface PhoneInputProps {
|
|||
disabled?: boolean;
|
||||
theme?: 'dark' | 'light';
|
||||
id?: string;
|
||||
clearOnDialCodeChange?: boolean;
|
||||
}
|
||||
|
||||
export const PhoneInput: React.FC<PhoneInputProps> = ({
|
||||
|
|
@ -24,6 +25,7 @@ export const PhoneInput: React.FC<PhoneInputProps> = ({
|
|||
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<PhoneInputProps> = ({
|
|||
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));
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -18,7 +18,8 @@ export const StoreHeader: React.FC<StoreHeaderProps> = ({
|
|||
onOpenAuth,
|
||||
}) => {
|
||||
return (
|
||||
<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">
|
||||
<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">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-6">
|
||||
<div
|
||||
onClick={() => onSwitchTab('storefront')}
|
||||
|
|
@ -35,7 +36,7 @@ export const StoreHeader: React.FC<StoreHeaderProps> = ({
|
|||
</div>
|
||||
</div>
|
||||
|
||||
{/* Navigation Tabs */}
|
||||
{/* 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')}
|
||||
|
|
@ -97,6 +98,36 @@ export const StoreHeader: React.FC<StoreHeaderProps> = ({
|
|||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Mobile Navigation Tabs */}
|
||||
<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">
|
||||
<button
|
||||
onClick={() => onSwitchTab('storefront')}
|
||||
className={`flex-1 flex items-center justify-center gap-1.5 px-3 py-2 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-1 flex items-center justify-center gap-1.5 px-3 py-2 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-1 font-semibold">
|
||||
{loggedInUser.active_subscriptions.length}
|
||||
</span>
|
||||
)}
|
||||
</button>
|
||||
</nav>
|
||||
</header>
|
||||
);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue