From 9c0315c36a5931e241eb0fd421f10db278cf872a Mon Sep 17 00:00:00 2001 From: ShivaniKhaire Date: Sat, 7 Nov 2026 16:01:38 +0530 Subject: [PATCH] feat(store): add country search, alphabetical sorting, and country code display (#84) --- src/components/auth/AuthModal.tsx | 46 ++--- src/components/auth/ProfileDrawer.tsx | 21 +-- src/components/common/CountrySelect.tsx | 234 ++++++++++++++++++++++++ src/constants/countries.ts | 5 + 4 files changed, 267 insertions(+), 39 deletions(-) create mode 100644 src/components/common/CountrySelect.tsx diff --git a/src/components/auth/AuthModal.tsx b/src/components/auth/AuthModal.tsx index 1d71255..3b394d4 100644 --- a/src/components/auth/AuthModal.tsx +++ b/src/components/auth/AuthModal.tsx @@ -3,8 +3,9 @@ import { XCircle, Sparkles, AlertCircle, CheckCircle, RefreshCw, Phone, Globe, Eye, EyeOff, LogIn, UserPlus } from 'lucide-react'; -import { COUNTRY_CODES, getCountryRuleByDialCode, getCountryRuleByName } from '../../constants/countries'; +import { SORTED_COUNTRY_CODES, getCountryRuleByDialCode, getCountryRuleByName } from '../../constants/countries'; import { cleanPhoneInput } from '../../utils/validation'; +import { CountrySelect } from '../common/CountrySelect'; interface AuthModalProps { isOpen: boolean; @@ -305,7 +306,7 @@ export const AuthModal: React.FC = ({ }} className="w-full bg-slate-950 border border-slate-800 rounded-xl px-2.5 py-2.5 text-xs sm:text-sm font-semibold text-white focus:outline-none focus:border-indigo-500 appearance-none pr-6" > - {COUNTRY_CODES.map((cc) => ( + {SORTED_COUNTRY_CODES.map((cc) => ( @@ -338,32 +339,23 @@ export const AuthModal: React.FC = ({ -
- -
- ▼ -
-
+ setAuthPhone(''); + } + }} + theme="dark" + size="md" + showCurrency={true} + showDialCode={true} + /> )} diff --git a/src/components/auth/ProfileDrawer.tsx b/src/components/auth/ProfileDrawer.tsx index f852025..d333435 100644 --- a/src/components/auth/ProfileDrawer.tsx +++ b/src/components/auth/ProfileDrawer.tsx @@ -4,8 +4,9 @@ import { Eye, EyeOff, RefreshCw, LogOut, Download } from 'lucide-react'; import type { UserProfile, ModuleItem, Currency } from '../../types'; -import { COUNTRY_CODES, getCountryRuleByName } from '../../constants/countries'; +import { getCountryRuleByName } from '../../constants/countries'; import { cleanPhoneInput, updatePhoneDialCode, SPECIAL_CHAR_REGEX } from '../../utils/validation'; +import { CountrySelect } from '../common/CountrySelect'; interface ProfileDrawerProps { isOpen: boolean; @@ -164,10 +165,9 @@ export const ProfileDrawer: React.FC = ({
- + theme="light" + size="sm" + showDialCode={true} + showCurrency={false} + />
+ + {/* Dropdown Menu */} + {isOpen && ( +
+ {/* Search Box */} +
+
+ + setSearchQuery(e.target.value)} + placeholder="Search country name or code..." + className={`w-full rounded-xl pl-8 pr-8 py-1.5 text-xs font-semibold focus:outline-none transition-colors ${ + isDark + ? 'bg-slate-950 border border-slate-800 text-white placeholder:text-slate-600 focus:border-indigo-500' + : 'bg-white border border-slate-200 text-slate-800 placeholder:text-slate-400 focus:border-indigo-500' + }`} + /> + {searchQuery && ( + + )} +
+
+ + {/* Options List */} +
+ {filteredCountries.length === 0 ? ( +
+ No countries found matching “{searchQuery}” +
+ ) : ( + filteredCountries.map((c) => { + const isSelected = c.country.toLowerCase() === value.toLowerCase(); + return ( + + ); + }) + )} +
+
+ )} + + ); +}; diff --git a/src/constants/countries.ts b/src/constants/countries.ts index 52acd95..40eff4b 100644 --- a/src/constants/countries.ts +++ b/src/constants/countries.ts @@ -98,6 +98,11 @@ export const COUNTRY_CODES: CountryCode[] = [ { code: '+230', label: '🇲🇺 +230', country: 'Mauritius', currency: 'USD', minLength: 7, maxLength: 8, placeholder: '7 to 8 digits' }, ]; +// Alphabetically sorted list of countries (A-Z) +export const SORTED_COUNTRY_CODES: CountryCode[] = [...COUNTRY_CODES].sort((a, b) => + a.country.localeCompare(b.country) +); + export const DEFAULT_COUNTRY = COUNTRY_CODES[0]; // India (+91) export const getCountryRuleByDialCode = (dialCode: string): CountryCode => {