diff --git a/src/features/profile/components/EditProfileForm.tsx b/src/features/profile/components/EditProfileForm.tsx index fe2f7cc..5311f19 100644 --- a/src/features/profile/components/EditProfileForm.tsx +++ b/src/features/profile/components/EditProfileForm.tsx @@ -1,10 +1,11 @@ -import React, { useState, useEffect } from "react"; +import React, { useState, useEffect, useMemo } from "react"; import { Modal, Pressable, ScrollView, StyleSheet, Text, + TextInput, View, } from "react-native"; import { Ionicons } from "@expo/vector-icons"; @@ -20,8 +21,8 @@ import FieldLabel from "@/components/forms/FieldLabel"; import PrimaryButton from "@/components/buttons/PrimaryButton"; import { Colors } from "@/theme"; import { + SORTED_COUNTRY_CODES, getCountryRuleByName, - updatePhoneDialCode, validatePhoneNumber, isValidPhoneNumber, parsePhoneNumber, @@ -38,25 +39,6 @@ interface EditProfileFormProps { isLoading?: boolean; } -const COMMON_COUNTRIES = [ - "Australia", - "Canada", - "France", - "Germany", - "India", - "Ireland", - "Malaysia", - "Netherlands", - "New Zealand", - "Singapore", - "South Africa", - "Spain", - "Switzerland", - "United Arab Emirates", - "United Kingdom", - "United States", -]; - export default function EditProfileForm({ initialName = "User Name", initialEmail = "user@example.com", @@ -71,9 +53,21 @@ export default function EditProfileForm({ const [nameError, setNameError] = useState(""); const [phoneError, setPhoneError] = useState(""); const [showCountryModal, setShowCountryModal] = useState(false); + const [countrySearch, setCountrySearch] = useState(""); const activeRule = getCountryRuleByName(country); + const filteredCountries = useMemo(() => { + const q = countrySearch.trim().toLowerCase(); + if (!q) return SORTED_COUNTRY_CODES; + return SORTED_COUNTRY_CODES.filter( + (c) => + c.country.toLowerCase().includes(q) || + c.code.toLowerCase().includes(q) || + c.label.toLowerCase().includes(q) + ); + }, [countrySearch]); + useEffect(() => { setFullName(initialName); }, [initialName]); @@ -105,12 +99,12 @@ export default function EditProfileForm({ const handleCountrySelect = (newCountry: string) => { if (newCountry !== country) { - const updatedPhone = updatePhoneDialCode(phone, country, newCountry); - setPhone(updatedPhone); + setPhone(""); setCountry(newCountry); if (phoneError) setPhoneError(""); } setShowCountryModal(false); + setCountrySearch(""); }; const handleSave = () => { @@ -220,18 +214,27 @@ export default function EditProfileForm({ visible={showCountryModal} transparent animationType="slide" - onRequestClose={() => setShowCountryModal(false)} + onRequestClose={() => { + setShowCountryModal(false); + setCountrySearch(""); + }} > setShowCountryModal(false)} + onPress={() => { + setShowCountryModal(false); + setCountrySearch(""); + }} > - + {}}> Select Country setShowCountryModal(false)} + onPress={() => { + setShowCountryModal(false); + setCountrySearch(""); + }} > + {/* Country Search Bar */} + + + + {countrySearch.length > 0 && ( + setCountrySearch("")} + > + + + )} + + - {COMMON_COUNTRIES.map((c) => { - const isSelected = country === c; - return ( - [ - styles.countryItem, - isSelected && styles.countryItemSelected, - pressed && styles.countryItemPressed, - ]} - onPress={() => handleCountrySelect(c)} - > - + No countries found + + ) : ( + filteredCountries.map((c) => { + const isSelected = country === c.country; + return ( + [ + styles.countryItem, + isSelected && styles.countryItemSelected, + pressed && styles.countryItemPressed, ]} + onPress={() => handleCountrySelect(c.country)} > - {c} - - {isSelected && ( - - )} - - ); - })} + + {c.code} + + {c.country} + + + {isSelected && ( + + )} + + ); + }) + )} - + @@ -334,6 +377,52 @@ const styles = StyleSheet.create({ color: Colors.textPrimary, }, + modalSearchContainer: { + flexDirection: "row", + alignItems: "center", + marginHorizontal: scale(16), + marginTop: verticalScale(10), + marginBottom: verticalScale(4), + paddingHorizontal: scale(12), + paddingVertical: verticalScale(8), + backgroundColor: "#F8FAFC", + borderRadius: moderateScale(10), + borderWidth: 1, + borderColor: "#E2E8F0", + gap: scale(8), + }, + + modalSearchInput: { + flex: 1, + fontSize: moderateScale(14), + color: Colors.textPrimary, + padding: 0, + }, + + emptyContainer: { + paddingVertical: verticalScale(24), + alignItems: "center", + }, + + emptyText: { + fontSize: moderateScale(14), + color: Colors.textSecondary, + }, + + countryRow: { + flexDirection: "row", + alignItems: "center", + gap: scale(10), + flex: 1, + }, + + countryDialCode: { + fontSize: moderateScale(13), + fontWeight: "700", + color: Colors.textSecondary, + minWidth: scale(46), + }, + countryList: { paddingHorizontal: scale(16), paddingTop: verticalScale(8),