feat/country-currency-parity #117
34
src/App.tsx
34
src/App.tsx
|
|
@ -1,4 +1,4 @@
|
||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect, useMemo } from 'react';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
|
||||||
import { CURRICULUM_MODULES } from './constants/modules';
|
import { CURRICULUM_MODULES } from './constants/modules';
|
||||||
|
|
@ -37,6 +37,23 @@ const getInitialTab = (): 'storefront' | 'subscriptions' | 'logged-out' => {
|
||||||
return 'storefront';
|
return 'storefront';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getInitialRegion = (): { currency: Currency; country: string; dialCode: string } => {
|
||||||
|
if (typeof Intl !== 'undefined') {
|
||||||
|
try {
|
||||||
|
const tz = Intl.DateTimeFormat().resolvedOptions().timeZone || '';
|
||||||
|
if (tz.includes('Kolkata') || tz.includes('Calcutta')) {
|
||||||
|
return { currency: 'INR', country: 'India', dialCode: '+91' };
|
||||||
|
}
|
||||||
|
if (tz.startsWith('Europe/')) {
|
||||||
|
return { currency: 'EUR', country: 'Germany', dialCode: '+49' };
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return { currency: 'USD', country: 'United States', dialCode: '+1' };
|
||||||
|
};
|
||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
const [activeTab, setActiveTab] = useState<'storefront' | 'subscriptions' | 'logged-out'>(getInitialTab);
|
const [activeTab, setActiveTab] = useState<'storefront' | 'subscriptions' | 'logged-out'>(getInitialTab);
|
||||||
|
|
||||||
|
|
@ -52,7 +69,8 @@ export default function App() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const [currency, setCurrency] = useState<Currency>('INR');
|
const initialRegion = useMemo(getInitialRegion, []);
|
||||||
|
const [currency, setCurrency] = useState<Currency>(initialRegion.currency);
|
||||||
|
|
||||||
// Auth state
|
// Auth state
|
||||||
const [userToken, setUserToken] = useState<string | null>(localStorage.getItem('access_token'));
|
const [userToken, setUserToken] = useState<string | null>(localStorage.getItem('access_token'));
|
||||||
|
|
@ -80,8 +98,8 @@ export default function App() {
|
||||||
const [authPassword, setAuthPassword] = useState('');
|
const [authPassword, setAuthPassword] = useState('');
|
||||||
const [authDisplayName, setAuthDisplayName] = useState('');
|
const [authDisplayName, setAuthDisplayName] = useState('');
|
||||||
const [authPhone, setAuthPhone] = useState('');
|
const [authPhone, setAuthPhone] = useState('');
|
||||||
const [authDialCode, setAuthDialCode] = useState('+91');
|
const [authDialCode, setAuthDialCode] = useState(initialRegion.dialCode);
|
||||||
const [authCountry, setAuthCountry] = useState('India');
|
const [authCountry, setAuthCountry] = useState(initialRegion.country);
|
||||||
const [authLoading, setAuthLoading] = useState(false);
|
const [authLoading, setAuthLoading] = useState(false);
|
||||||
const [authError, setAuthError] = useState<string | null>(null);
|
const [authError, setAuthError] = useState<string | null>(null);
|
||||||
|
|
||||||
|
|
@ -262,7 +280,7 @@ export default function App() {
|
||||||
return {
|
return {
|
||||||
priceInr: livePlan.price_inr ?? item.priceInr,
|
priceInr: livePlan.price_inr ?? item.priceInr,
|
||||||
priceUsd: livePlan.price_usd ?? item.priceUsd,
|
priceUsd: livePlan.price_usd ?? item.priceUsd,
|
||||||
priceEur: item.priceEur,
|
priceEur: livePlan.price_eur ?? livePlan.price_usd ?? item.priceEur,
|
||||||
isActive: livePlan.is_active !== undefined ? livePlan.is_active : true,
|
isActive: livePlan.is_active !== undefined ? livePlan.is_active : true,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -404,7 +422,8 @@ export default function App() {
|
||||||
setShowProfileDrawer(false);
|
setShowProfileDrawer(false);
|
||||||
setProfileDisplayName('');
|
setProfileDisplayName('');
|
||||||
setProfilePhone('');
|
setProfilePhone('');
|
||||||
setProfileCountry('India');
|
setProfileCountry(initialRegion.country);
|
||||||
|
setCurrency(initialRegion.currency);
|
||||||
setProfileError(null);
|
setProfileError(null);
|
||||||
setProfileSuccess(false);
|
setProfileSuccess(false);
|
||||||
setShowAuthModal(false);
|
setShowAuthModal(false);
|
||||||
|
|
@ -703,6 +722,7 @@ export default function App() {
|
||||||
...item,
|
...item,
|
||||||
priceInr: live.priceInr,
|
priceInr: live.priceInr,
|
||||||
priceUsd: live.priceUsd,
|
priceUsd: live.priceUsd,
|
||||||
|
priceEur: live.priceEur,
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
@ -783,6 +803,7 @@ export default function App() {
|
||||||
...module,
|
...module,
|
||||||
priceInr: live.priceInr,
|
priceInr: live.priceInr,
|
||||||
priceUsd: live.priceUsd,
|
priceUsd: live.priceUsd,
|
||||||
|
priceEur: live.priceEur,
|
||||||
};
|
};
|
||||||
|
|
||||||
const exists = cart.find(item => item.code === module.code);
|
const exists = cart.find(item => item.code === module.code);
|
||||||
|
|
@ -1097,7 +1118,6 @@ export default function App() {
|
||||||
<CartDrawer
|
<CartDrawer
|
||||||
cart={cart}
|
cart={cart}
|
||||||
currency={currency}
|
currency={currency}
|
||||||
setCurrency={setCurrency}
|
|
||||||
toggleCartItem={toggleCartItem}
|
toggleCartItem={toggleCartItem}
|
||||||
couponCode={couponCode}
|
couponCode={couponCode}
|
||||||
setCouponCode={setCouponCode}
|
setCouponCode={setCouponCode}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,11 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { ShoppingCart, ShoppingBag, Trash2, RefreshCw, CreditCard, XCircle } from 'lucide-react';
|
import { ShoppingCart, ShoppingBag, Trash2, RefreshCw, CreditCard, XCircle, Globe } from 'lucide-react';
|
||||||
import type { ModuleItem, Currency, UserProfile, VerificationResult } from '../../types';
|
import type { ModuleItem, Currency, UserProfile, VerificationResult } from '../../types';
|
||||||
import { isValidPhoneNumber } from '../../utils/validation';
|
import { isValidPhoneNumber } from '../../utils/validation';
|
||||||
|
|
||||||
interface CartDrawerProps {
|
interface CartDrawerProps {
|
||||||
cart: ModuleItem[];
|
cart: ModuleItem[];
|
||||||
currency: Currency;
|
currency: Currency;
|
||||||
setCurrency: (c: Currency) => void;
|
|
||||||
toggleCartItem: (module: ModuleItem) => void;
|
toggleCartItem: (module: ModuleItem) => void;
|
||||||
couponCode: string;
|
couponCode: string;
|
||||||
setCouponCode: (code: string) => void;
|
setCouponCode: (code: string) => void;
|
||||||
|
|
@ -25,7 +24,6 @@ interface CartDrawerProps {
|
||||||
export const CartDrawer: React.FC<CartDrawerProps> = ({
|
export const CartDrawer: React.FC<CartDrawerProps> = ({
|
||||||
cart,
|
cart,
|
||||||
currency,
|
currency,
|
||||||
setCurrency,
|
|
||||||
toggleCartItem,
|
toggleCartItem,
|
||||||
couponCode,
|
couponCode,
|
||||||
setCouponCode,
|
setCouponCode,
|
||||||
|
|
@ -77,28 +75,23 @@ export const CartDrawer: React.FC<CartDrawerProps> = ({
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Currency selector toggle */}
|
{/* Billing Currency & Region Badge */}
|
||||||
<div className="flex flex-col sm:flex-row gap-2 sm:items-center justify-between">
|
<div className="flex items-center justify-between p-2.5 bg-slate-50 border border-slate-200/70 rounded-xl">
|
||||||
<span className="text-xs font-bold text-slate-500">Billing Currency:</span>
|
<div className="flex items-center gap-1.5 min-w-0">
|
||||||
<div className="flex bg-slate-100 rounded-lg p-0.5 border border-slate-200 self-end sm:self-auto flex-shrink-0">
|
<Globe className="h-3.5 w-3.5 text-indigo-500 shrink-0" />
|
||||||
<button
|
<span className="text-xs font-semibold text-slate-600 truncate">
|
||||||
onClick={() => setCurrency('INR')}
|
{loggedInUser ? 'Billing Currency' : 'Estimated Currency'}:
|
||||||
className={`px-3 py-1 rounded-md text-xs font-bold transition-all duration-300 ${currency === 'INR'
|
</span>
|
||||||
? 'bg-white text-slate-900 shadow-sm border border-slate-200/50'
|
</div>
|
||||||
: 'text-slate-500 hover:text-slate-800'
|
<div className="flex items-center gap-1.5 shrink-0">
|
||||||
}`}
|
<span className="text-[11px] bg-white border border-slate-200 font-extrabold text-slate-800 px-2 py-0.5 rounded-md shadow-xs">
|
||||||
>
|
{currency === 'INR' ? 'INR (₹)' : currency === 'EUR' ? 'EUR (€)' : 'USD ($)'}
|
||||||
INR (₹)
|
</span>
|
||||||
</button>
|
{loggedInUser?.country && (
|
||||||
<button
|
<span className="text-[10px] text-slate-400 font-semibold max-w-[90px] truncate" title={loggedInUser.country}>
|
||||||
onClick={() => setCurrency('USD')}
|
• {loggedInUser.country}
|
||||||
className={`px-3 py-1 rounded-md text-xs font-bold transition-all duration-300 ${currency === 'USD'
|
</span>
|
||||||
? 'bg-white text-slate-900 shadow-sm border border-slate-200/50'
|
)}
|
||||||
: 'text-slate-500 hover:text-slate-800'
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
USD ($)
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -417,6 +410,15 @@ export const CartDrawer: React.FC<CartDrawerProps> = ({
|
||||||
<p className="text-[10px] text-slate-400 text-center leading-relaxed font-semibold">
|
<p className="text-[10px] text-slate-400 text-center leading-relaxed font-semibold">
|
||||||
* Integrated with Razorpay Gateway API (Test Mode).
|
* Integrated with Razorpay Gateway API (Test Mode).
|
||||||
</p>
|
</p>
|
||||||
|
<p className="text-[10px] text-slate-400 text-center font-medium">
|
||||||
|
Billing currency is tied to your country. Need billing assistance?{' '}
|
||||||
|
<a
|
||||||
|
href="mailto:support@acupedia.com?subject=Billing%20Support%20Inquiry"
|
||||||
|
className="text-indigo-600 hover:underline font-bold"
|
||||||
|
>
|
||||||
|
Contact Support
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -665,7 +665,7 @@ export const CatalogSection: React.FC<CatalogSectionProps> = ({
|
||||||
category: 'Bundle',
|
category: 'Bundle',
|
||||||
priceInr: pInr,
|
priceInr: pInr,
|
||||||
priceUsd: pUsd,
|
priceUsd: pUsd,
|
||||||
priceEur: pUsd,
|
priceEur: cPlan.price_eur ?? pUsd,
|
||||||
desc: cPlan.description || 'Custom bundled access.',
|
desc: cPlan.description || 'Custom bundled access.',
|
||||||
color: 'from-slate-700 to-slate-900'
|
color: 'from-slate-700 to-slate-900'
|
||||||
};
|
};
|
||||||
|
|
@ -717,7 +717,7 @@ export const CatalogSection: React.FC<CatalogSectionProps> = ({
|
||||||
</span>
|
</span>
|
||||||
) : (
|
) : (
|
||||||
<span className="text-xs font-extrabold text-slate-700">
|
<span className="text-xs font-extrabold text-slate-700">
|
||||||
{currency === 'INR' ? `₹${pInr}` : `$${pUsd}`}
|
{currency === 'INR' ? `₹${pInr}` : currency === 'EUR' ? `€${cPlan.price_eur ?? pUsd}` : `$${pUsd}`}
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
{!isUnlocked && (
|
{!isUnlocked && (
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,12 @@ export const COUNTRY_CODES: CountryCode[] = [
|
||||||
{ iso2: 'HR', code: '+385', label: '🇭🇷 +385', country: 'Croatia', currency: 'EUR', minLength: 8, maxLength: 9, placeholder: '8 to 9 digits' },
|
{ iso2: 'HR', code: '+385', label: '🇭🇷 +385', country: 'Croatia', currency: 'EUR', minLength: 8, maxLength: 9, placeholder: '8 to 9 digits' },
|
||||||
{ iso2: 'SK', code: '+421', label: '🇸🇰 +421', country: 'Slovakia', currency: 'EUR', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' },
|
{ iso2: 'SK', code: '+421', label: '🇸🇰 +421', country: 'Slovakia', currency: 'EUR', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' },
|
||||||
{ iso2: 'BG', code: '+359', label: '🇧🇬 +359', country: 'Bulgaria', currency: 'EUR', minLength: 8, maxLength: 9, placeholder: '8 to 9 digits' },
|
{ iso2: 'BG', code: '+359', label: '🇧🇬 +359', country: 'Bulgaria', currency: 'EUR', minLength: 8, maxLength: 9, placeholder: '8 to 9 digits' },
|
||||||
|
{ iso2: 'CY', code: '+357', label: '🇨🇾 +357', country: 'Cyprus', currency: 'EUR', minLength: 8, maxLength: 8, placeholder: '8-digit phone number' },
|
||||||
|
{ iso2: 'EE', code: '+372', label: '🇪🇪 +372', country: 'Estonia', currency: 'EUR', minLength: 7, maxLength: 8, placeholder: '7 to 8 digits' },
|
||||||
|
{ iso2: 'LV', code: '+371', label: '🇱🇻 +371', country: 'Latvia', currency: 'EUR', minLength: 8, maxLength: 8, placeholder: '8-digit phone number' },
|
||||||
|
{ iso2: 'LT', code: '+370', label: '🇱🇹 +370', country: 'Lithuania', currency: 'EUR', minLength: 8, maxLength: 8, placeholder: '8-digit phone number' },
|
||||||
|
{ iso2: 'MT', code: '+356', label: '🇲🇹 +356', country: 'Malta', currency: 'EUR', minLength: 8, maxLength: 8, placeholder: '8-digit phone number' },
|
||||||
|
{ iso2: 'SI', code: '+386', label: '🇸🇮 +386', country: 'Slovenia', currency: 'EUR', minLength: 8, maxLength: 8, placeholder: '8-digit phone number' },
|
||||||
{ iso2: 'RU', code: '+7', label: '🇷🇺 +7', country: 'Russia', currency: 'USD', minLength: 10, maxLength: 10, placeholder: '10-digit mobile number' },
|
{ iso2: 'RU', code: '+7', label: '🇷🇺 +7', country: 'Russia', currency: 'USD', minLength: 10, maxLength: 10, placeholder: '10-digit mobile number' },
|
||||||
{ iso2: 'TR', code: '+90', label: '🇹🇷 +90', country: 'Turkey', currency: 'USD', minLength: 10, maxLength: 10, placeholder: '10-digit mobile number' },
|
{ iso2: 'TR', code: '+90', label: '🇹🇷 +90', country: 'Turkey', currency: 'USD', minLength: 10, maxLength: 10, placeholder: '10-digit mobile number' },
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue