diff --git a/src/App.tsx b/src/App.tsx index e91428c..3685210 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,4 +1,4 @@ -import { useState, useEffect } from 'react'; +import { useState, useEffect, useMemo } from 'react'; import axios from 'axios'; import { CURRICULUM_MODULES } from './constants/modules'; @@ -37,6 +37,23 @@ const getInitialTab = (): 'storefront' | 'subscriptions' | 'logged-out' => { 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() { const [activeTab, setActiveTab] = useState<'storefront' | 'subscriptions' | 'logged-out'>(getInitialTab); @@ -52,7 +69,8 @@ export default function App() { } }; - const [currency, setCurrency] = useState('INR'); + const initialRegion = useMemo(getInitialRegion, []); + const [currency, setCurrency] = useState(initialRegion.currency); // Auth state const [userToken, setUserToken] = useState(localStorage.getItem('access_token')); @@ -80,8 +98,8 @@ export default function App() { const [authPassword, setAuthPassword] = useState(''); const [authDisplayName, setAuthDisplayName] = useState(''); const [authPhone, setAuthPhone] = useState(''); - const [authDialCode, setAuthDialCode] = useState('+91'); - const [authCountry, setAuthCountry] = useState('India'); + const [authDialCode, setAuthDialCode] = useState(initialRegion.dialCode); + const [authCountry, setAuthCountry] = useState(initialRegion.country); const [authLoading, setAuthLoading] = useState(false); const [authError, setAuthError] = useState(null); @@ -404,7 +422,8 @@ export default function App() { setShowProfileDrawer(false); setProfileDisplayName(''); setProfilePhone(''); - setProfileCountry('India'); + setProfileCountry(initialRegion.country); + setCurrency(initialRegion.currency); setProfileError(null); setProfileSuccess(false); setShowAuthModal(false); @@ -1099,7 +1118,6 @@ export default function App() { void; toggleCartItem: (module: ModuleItem) => void; couponCode: string; setCouponCode: (code: string) => void; @@ -25,7 +24,6 @@ interface CartDrawerProps { export const CartDrawer: React.FC = ({ cart, currency, - setCurrency, toggleCartItem, couponCode, setCouponCode, @@ -77,28 +75,23 @@ export const CartDrawer: React.FC = ({ - {/* Currency selector toggle */} -
- Billing Currency: -
- - + {/* Billing Currency & Region Badge */} +
+
+ + + {loggedInUser ? 'Billing Currency' : 'Estimated Currency'}: + +
+
+ + {currency === 'INR' ? 'INR (₹)' : currency === 'EUR' ? 'EUR (€)' : 'USD ($)'} + + {loggedInUser?.country && ( + + • {loggedInUser.country} + + )}
@@ -417,6 +410,15 @@ export const CartDrawer: React.FC = ({

* Integrated with Razorpay Gateway API (Test Mode).

+

+ Billing currency is tied to your country. Need billing assistance?{' '} + + Contact Support + +

)}