Compare commits

..

No commits in common. "e153668f06584ee62fbf0edc4e0ce5ea54d28093" and "4453a2a96c03ead6557a6062ee6cd7f18b5c190f" have entirely different histories.

1 changed files with 56 additions and 145 deletions

View File

@ -1,11 +1,10 @@
import React, { useState, useEffect, useMemo } from "react"; import React, { useState, useEffect } from "react";
import { import {
Modal, Modal,
Pressable, Pressable,
ScrollView, ScrollView,
StyleSheet, StyleSheet,
Text, Text,
TextInput,
View, View,
} from "react-native"; } from "react-native";
import { Ionicons } from "@expo/vector-icons"; import { Ionicons } from "@expo/vector-icons";
@ -21,8 +20,8 @@ import FieldLabel from "@/components/forms/FieldLabel";
import PrimaryButton from "@/components/buttons/PrimaryButton"; import PrimaryButton from "@/components/buttons/PrimaryButton";
import { Colors } from "@/theme"; import { Colors } from "@/theme";
import { import {
SORTED_COUNTRY_CODES,
getCountryRuleByName, getCountryRuleByName,
updatePhoneDialCode,
validatePhoneNumber, validatePhoneNumber,
isValidPhoneNumber, isValidPhoneNumber,
parsePhoneNumber, parsePhoneNumber,
@ -39,6 +38,25 @@ interface EditProfileFormProps {
isLoading?: boolean; 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({ export default function EditProfileForm({
initialName = "User Name", initialName = "User Name",
initialEmail = "user@example.com", initialEmail = "user@example.com",
@ -53,21 +71,9 @@ export default function EditProfileForm({
const [nameError, setNameError] = useState(""); const [nameError, setNameError] = useState("");
const [phoneError, setPhoneError] = useState(""); const [phoneError, setPhoneError] = useState("");
const [showCountryModal, setShowCountryModal] = useState(false); const [showCountryModal, setShowCountryModal] = useState(false);
const [countrySearch, setCountrySearch] = useState("");
const activeRule = getCountryRuleByName(country); 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(() => { useEffect(() => {
setFullName(initialName); setFullName(initialName);
}, [initialName]); }, [initialName]);
@ -99,12 +105,12 @@ export default function EditProfileForm({
const handleCountrySelect = (newCountry: string) => { const handleCountrySelect = (newCountry: string) => {
if (newCountry !== country) { if (newCountry !== country) {
setPhone(""); const updatedPhone = updatePhoneDialCode(phone, country, newCountry);
setPhone(updatedPhone);
setCountry(newCountry); setCountry(newCountry);
if (phoneError) setPhoneError(""); if (phoneError) setPhoneError("");
} }
setShowCountryModal(false); setShowCountryModal(false);
setCountrySearch("");
}; };
const handleSave = () => { const handleSave = () => {
@ -214,27 +220,18 @@ export default function EditProfileForm({
visible={showCountryModal} visible={showCountryModal}
transparent transparent
animationType="slide" animationType="slide"
onRequestClose={() => { onRequestClose={() => setShowCountryModal(false)}
setShowCountryModal(false);
setCountrySearch("");
}}
> >
<Pressable <Pressable
style={styles.modalOverlay} style={styles.modalOverlay}
onPress={() => { onPress={() => setShowCountryModal(false)}
setShowCountryModal(false);
setCountrySearch("");
}}
> >
<Pressable style={styles.modalSheet} onPress={() => {}}> <View style={styles.modalSheet}>
<View style={styles.modalHeader}> <View style={styles.modalHeader}>
<Text style={styles.modalTitle}>Select Country</Text> <Text style={styles.modalTitle}>Select Country</Text>
<Pressable <Pressable
hitSlop={8} hitSlop={8}
onPress={() => { onPress={() => setShowCountryModal(false)}
setShowCountryModal(false);
setCountrySearch("");
}}
> >
<Ionicons <Ionicons
name="close" name="close"
@ -244,69 +241,30 @@ export default function EditProfileForm({
</Pressable> </Pressable>
</View> </View>
{/* Country Search Bar */}
<View style={styles.modalSearchContainer}>
<Ionicons
name="search-outline"
size={moderateScale(17)}
color={Colors.textSecondary}
/>
<TextInput
value={countrySearch}
onChangeText={setCountrySearch}
placeholder="Search country or code..."
placeholderTextColor={Colors.textSecondary}
style={styles.modalSearchInput}
autoCapitalize="none"
autoCorrect={false}
/>
{countrySearch.length > 0 && (
<Pressable
hitSlop={8}
onPress={() => setCountrySearch("")}
>
<Ionicons
name="close-circle"
size={moderateScale(17)}
color={Colors.textSecondary}
/>
</Pressable>
)}
</View>
<ScrollView <ScrollView
showsVerticalScrollIndicator={false} showsVerticalScrollIndicator={false}
contentContainerStyle={styles.countryList} contentContainerStyle={styles.countryList}
keyboardShouldPersistTaps="handled"
> >
{filteredCountries.length === 0 ? ( {COMMON_COUNTRIES.map((c) => {
<View style={styles.emptyContainer}> const isSelected = country === c;
<Text style={styles.emptyText}>No countries found</Text>
</View>
) : (
filteredCountries.map((c) => {
const isSelected = country === c.country;
return ( return (
<Pressable <Pressable
key={c.iso2 + c.country} key={c}
style={({ pressed }) => [ style={({ pressed }) => [
styles.countryItem, styles.countryItem,
isSelected && styles.countryItemSelected, isSelected && styles.countryItemSelected,
pressed && styles.countryItemPressed, pressed && styles.countryItemPressed,
]} ]}
onPress={() => handleCountrySelect(c.country)} onPress={() => handleCountrySelect(c)}
> >
<View style={styles.countryRow}>
<Text style={styles.countryDialCode}>{c.code}</Text>
<Text <Text
style={[ style={[
styles.countryName, styles.countryName,
isSelected && styles.countryNameSelected, isSelected && styles.countryNameSelected,
]} ]}
> >
{c.country} {c}
</Text> </Text>
</View>
{isSelected && ( {isSelected && (
<Ionicons <Ionicons
name="checkmark" name="checkmark"
@ -316,10 +274,9 @@ export default function EditProfileForm({
)} )}
</Pressable> </Pressable>
); );
}) })}
)}
</ScrollView> </ScrollView>
</Pressable> </View>
</Pressable> </Pressable>
</Modal> </Modal>
</View> </View>
@ -377,52 +334,6 @@ const styles = StyleSheet.create({
color: Colors.textPrimary, 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: { countryList: {
paddingHorizontal: scale(16), paddingHorizontal: scale(16),
paddingTop: verticalScale(8), paddingTop: verticalScale(8),