From 52fc20927431dcdd7dc04b51d1d90e71fd5fac25 Mon Sep 17 00:00:00 2001 From: ShivaniKhaire Date: Sat, 7 Nov 2026 17:18:00 +0530 Subject: [PATCH] feat(auth): sort country selection alphabetically in registration and profile (issue #110) - Export SORTED_COUNTRY_CODES sorted by country name in constants/countries.ts - Use SORTED_COUNTRY_CODES in SignUpForm to sort countries alphabetically in the Select Country modal - Sort COMMON_COUNTRIES in EditProfileForm alphabetically for consistent UX --- src/constants/countries.ts | 4 +++ src/features/auth/components/SignUpForm.tsx | 6 ++--- .../profile/components/EditProfileForm.tsx | 26 +++++++++---------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/constants/countries.ts b/src/constants/countries.ts index 7b227e6..7537b48 100644 --- a/src/constants/countries.ts +++ b/src/constants/countries.ts @@ -98,6 +98,10 @@ export const COUNTRY_CODES: CountryCode[] = [ export const DEFAULT_COUNTRY = COUNTRY_CODES[0]; // India (+91) +export const SORTED_COUNTRY_CODES: CountryCode[] = [...COUNTRY_CODES].sort((a, b) => + a.country.localeCompare(b.country) +); + export const getCountryRuleByDialCode = (dialCode: string): CountryCode => { return ( COUNTRY_CODES.find((c) => c.code === dialCode) || { diff --git a/src/features/auth/components/SignUpForm.tsx b/src/features/auth/components/SignUpForm.tsx index cf851be..f2f3f71 100644 --- a/src/features/auth/components/SignUpForm.tsx +++ b/src/features/auth/components/SignUpForm.tsx @@ -24,9 +24,9 @@ import PrimaryButton from "@/components/buttons/PrimaryButton"; import { AuthColors } from "../constants/colors"; import { Colors } from "@/theme"; import { - COUNTRY_CODES, CountryCode, DEFAULT_COUNTRY, + SORTED_COUNTRY_CODES, validatePhoneNumber, validateEmail, } from "@/constants/countries"; @@ -55,8 +55,8 @@ export default function SignUpForm() { const filteredCountries = useMemo(() => { const q = countrySearch.trim().toLowerCase(); - if (!q) return COUNTRY_CODES; - return COUNTRY_CODES.filter( + if (!q) return SORTED_COUNTRY_CODES; + return SORTED_COUNTRY_CODES.filter( (c) => c.country.toLowerCase().includes(q) || c.code.includes(q) || diff --git a/src/features/profile/components/EditProfileForm.tsx b/src/features/profile/components/EditProfileForm.tsx index 488156d..18d0a83 100644 --- a/src/features/profile/components/EditProfileForm.tsx +++ b/src/features/profile/components/EditProfileForm.tsx @@ -35,22 +35,22 @@ interface EditProfileFormProps { } const COMMON_COUNTRIES = [ - "India", - "United States", - "United Kingdom", - "Canada", "Australia", - "Germany", - "Singapore", - "Malaysia", - "New Zealand", - "United Arab Emirates", - "South Africa", - "Ireland", - "Netherlands", - "Switzerland", + "Canada", "France", + "Germany", + "India", + "Ireland", + "Malaysia", + "Netherlands", + "New Zealand", + "Singapore", + "South Africa", "Spain", + "Switzerland", + "United Arab Emirates", + "United Kingdom", + "United States", ]; export const isValidPhoneNumber = (val?: string, country?: string): boolean => { -- 2.34.1