Compare commits

..

No commits in common. "2513c854117f0641569d2b8acea4a4aa25f186aa" and "a1c127e684ed7a0f37d9037fb8b64ce3847a04b7" have entirely different histories.

4 changed files with 43 additions and 113 deletions

View File

@ -92,7 +92,7 @@ export const ProfileDrawer: React.FC<ProfileDrawerProps> = ({
const handleLocalPhoneChange = (newLocal: string) => {
setLocalPhone(newLocal);
setProfilePhone(newLocal ? formatE164Phone(dialCode, newLocal) : '');
setProfilePhone(formatE164Phone(dialCode, newLocal));
};
const handleDialCodeChange = (newCode: string, newCountry: string) => {
@ -192,7 +192,6 @@ export const ProfileDrawer: React.FC<ProfileDrawerProps> = ({
onPhoneChange={handleLocalPhoneChange}
theme="light"
disabled={profileSaving}
error={profileError && profileError.toLowerCase().includes('phone') ? profileError : null}
/>
</div>

View File

@ -1,7 +1,6 @@
import React from 'react';
import { ShoppingCart, ShoppingBag, Trash2, RefreshCw, CreditCard, XCircle } from 'lucide-react';
import type { ModuleItem, Currency, UserProfile, VerificationResult } from '../../types';
import { isValidPhoneNumber } from '../../utils/validation';
interface CartDrawerProps {
cart: ModuleItem[];
@ -114,55 +113,36 @@ export const CartDrawer: React.FC<CartDrawerProps> = ({
</div>
) : (
<div className="space-y-3 max-h-[220px] overflow-y-auto pr-1">
{cart.map((item) => {
const isCompletePackage =
item.code === 'POINTS_PACK' ||
item.code === 'PATTERN_CORE' ||
item.code === 'NUTRITION_CORE' ||
item.code === 'THERAPEUTICS_CORE' ||
item.name.toLowerCase().includes('complete pack') ||
item.name.toLowerCase().includes('complete package') ||
item.name.toLowerCase().includes('complete bundle') ||
item.category === 'Bundle';
return (
<div
key={item.code}
className="flex justify-between items-center gap-4 bg-slate-50 border border-slate-200/60 p-3 rounded-2xl"
>
<div className="flex-1 min-w-0">
<div className="flex items-center gap-1.5 flex-wrap min-w-0">
<p className="text-xs font-bold text-slate-800 truncate">{item.name}</p>
{isCompletePackage && (
<span className="text-[8px] bg-gradient-to-r from-indigo-500 to-purple-600 text-white font-extrabold px-1.5 py-0.5 rounded tracking-wider uppercase flex-shrink-0">
Complete Pack
</span>
)}
</div>
<p className="text-[9px] text-slate-400 tracking-wider uppercase font-semibold">{item.category}</p>
</div>
<div className="flex items-center gap-3">
<span className="text-xs font-bold text-indigo-600">
{(() => {
const calculatedItem = activePricing?.cart_items?.find((ci: any) => ci.code === item.code);
const price = calculatedItem
? calculatedItem.price
: (currency === 'INR' ? item.priceInr : currency === 'EUR' ? item.priceEur : item.priceUsd);
const symbol = currency === 'INR' ? '₹' : currency === 'EUR' ? '€' : '$';
return `${symbol}${price}`;
})()}
</span>
<button
onClick={() => toggleCartItem(item)}
className="h-7 w-7 rounded-lg bg-rose-50 text-rose-500 hover:bg-rose-100 flex items-center justify-center transition-colors"
title="Remove item"
>
<Trash2 className="h-3.5 w-3.5" />
</button>
</div>
{cart.map((item) => (
<div
key={item.code}
className="flex justify-between items-center gap-4 bg-slate-50 border border-slate-200/60 p-3 rounded-2xl"
>
<div className="flex-1 min-w-0">
<p className="text-xs font-bold text-slate-800 truncate">{item.name}</p>
<p className="text-[9px] text-slate-400 tracking-wider uppercase font-semibold">{item.category}</p>
</div>
);
})}
<div className="flex items-center gap-3">
<span className="text-xs font-bold text-indigo-600">
{(() => {
const calculatedItem = activePricing?.cart_items?.find((ci: any) => ci.code === item.code);
const price = calculatedItem
? calculatedItem.price
: (currency === 'INR' ? item.priceInr : currency === 'EUR' ? item.priceEur : item.priceUsd);
const symbol = currency === 'INR' ? '₹' : currency === 'EUR' ? '€' : '$';
return `${symbol}${price}`;
})()}
</span>
<button
onClick={() => toggleCartItem(item)}
className="h-7 w-7 rounded-lg bg-rose-50 text-rose-500 hover:bg-rose-100 flex items-center justify-center transition-colors"
title="Remove item"
>
<Trash2 className="h-3.5 w-3.5" />
</button>
</div>
</div>
))}
</div>
)}
@ -352,12 +332,12 @@ export const CartDrawer: React.FC<CartDrawerProps> = ({
<span className="text-[10px] uppercase font-black tracking-wider text-slate-400">
Billing Profile
</span>
{(!loggedInUser.phone_number || !isValidPhoneNumber(loggedInUser.phone_number, undefined, loggedInUser.country || 'India')) && (
{!loggedInUser.phone_number && (
<button
onClick={onUpdateBillingPhone}
className="text-[9px] text-indigo-600 hover:text-indigo-500 font-black uppercase tracking-wider underline focus:outline-none"
>
{loggedInUser.phone_number ? 'Update Number' : 'Add Number'}
Add Number
</button>
)}
</div>
@ -369,11 +349,7 @@ export const CartDrawer: React.FC<CartDrawerProps> = ({
<div className="flex justify-between text-xs font-semibold text-slate-600">
<span>Phone:</span>
<span className="text-slate-800 font-bold">
{loggedInUser.phone_number && isValidPhoneNumber(loggedInUser.phone_number, undefined, loggedInUser.country || 'India') ? (
loggedInUser.phone_number
) : loggedInUser.phone_number ? (
<span className="text-amber-600 font-black italic">Incomplete ({loggedInUser.phone_number})</span>
) : (
{loggedInUser.phone_number || (
<span className="text-rose-500 font-black italic">Required for checkout</span>
)}
</span>

View File

@ -50,38 +50,8 @@ export const PhoneInput: React.FC<PhoneInputProps> = ({
};
const handlePhoneInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const inputVal = e.target.value;
const trimmed = inputVal.trim();
// Check if input contains an explicit international prefix '+'
if (trimmed.startsWith('+')) {
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) {
onDialCodeChange(matched.code, matched.country);
}
const rest = trimmed.slice(matched.code.length).replace(/\D/g, '');
onPhoneChange(rest.slice(0, matched.maxLength));
return;
}
}
// Check if input was pasted with dial code digits without '+' (e.g. 919876543210)
const dialDigits = activeRule.code.replace(/\D/g, '');
const rawDigits = trimmed.replace(/\D/g, '');
if (
dialDigits &&
rawDigits.startsWith(dialDigits) &&
rawDigits.length > activeRule.maxLength
) {
const rest = rawDigits.slice(dialDigits.length);
onPhoneChange(rest.slice(0, activeRule.maxLength));
return;
}
// Strictly numeric local digits, capped at active country's maxLength
const cleaned = cleanPhoneInput(inputVal, activeRule.maxLength, false);
// Strictly numeric, capped at maxLength
const cleaned = cleanPhoneInput(e.target.value, activeRule.maxLength, false);
onPhoneChange(cleaned);
};
@ -93,10 +63,6 @@ export const PhoneInput: React.FC<PhoneInputProps> = ({
) {
return;
}
// Allow '+' as leading character to support international number paste/typing
if (e.key === '+' && (e.currentTarget.selectionStart === 0 || !phone)) {
return;
}
// Block any non-digit
if (!/^\d$/.test(e.key)) {
e.preventDefault();

View File

@ -51,11 +51,6 @@ export const validatePhoneNumber = (
if ((!rule || rule.country === 'Other') && country) {
rule = getCountryRuleByName(country);
}
// If still not found and input starts with '+', match from COUNTRY_CODES
if (!rule && trimmed.startsWith('+')) {
const sorted = [...COUNTRY_CODES].sort((a, b) => b.code.length - a.code.length);
rule = sorted.find((c) => trimmed.startsWith(c.code));
}
// Default to India if no specific rule resolved and dial code is +91 or country is India
if (!rule || rule.country === 'Other') {
if (dialCode === '+91' || (country && country.toLowerCase() === 'india')) {
@ -67,14 +62,12 @@ export const validatePhoneNumber = (
const dialDigits = rule.code.replace(/\D/g, '');
let localDigits = allDigits;
if (trimmed.startsWith('+')) {
// Input includes country code prefix (e.g. +919876543210 or +9198765432)
// Must strip the dial code to extract the actual local number
if (allDigits.startsWith(dialDigits)) {
localDigits = allDigits.slice(dialDigits.length);
}
} else if (allDigits.length > rule.maxLength && allDigits.startsWith(dialDigits)) {
// Input was formatted with dial digits without '+' and exceeds local maxLength (e.g. 919876543210)
// If formatted with country code (e.g. +919876543210 or 919876543210 where total length > rule.maxLength), strip country prefix
if (
(trimmed.startsWith('+') || allDigits.length > rule.maxLength) &&
allDigits.startsWith(dialDigits) &&
allDigits.length === dialDigits.length + rule.minLength
) {
localDigits = allDigits.slice(dialDigits.length);
}
@ -144,15 +137,11 @@ export const parsePhoneNumber = (
};
}
// If no '+' prefix, check if digits start with fallback country dial digits and exceed national length
// If no '+' prefix, check if digits start with fallback country dial digits
const dialDigits = defaultRule.code.replace(/\D/g, '');
const rawDigits = trimmed.replace(/\D/g, '');
let local = rawDigits;
if (
dialDigits &&
rawDigits.startsWith(dialDigits) &&
rawDigits.length > defaultRule.maxLength
) {
if (rawDigits.startsWith(dialDigits) && rawDigits.length > dialDigits.length) {
local = rawDigits.slice(dialDigits.length);
}
return {