|
|
@ -28,6 +28,7 @@ import { settingApi } from "../../services/api/setting"; |
|
|
|
import flagMap from "../../utils/flagMap"; |
|
|
|
import flagMap from "../../utils/flagMap"; |
|
|
|
import { useTranslation } from "react-i18next"; |
|
|
|
import { useTranslation } from "react-i18next"; |
|
|
|
import fontSize from "../../utils/fontsizeUtils"; |
|
|
|
import fontSize from "../../utils/fontsizeUtils"; |
|
|
|
|
|
|
|
import { getCountryTransLanguage } from "../../utils/languageUtils"; |
|
|
|
|
|
|
|
|
|
|
|
type RootStackParamList = { |
|
|
|
type RootStackParamList = { |
|
|
|
AddRess: { address?: AddressItem }; |
|
|
|
AddRess: { address?: AddressItem }; |
|
|
@ -53,7 +54,7 @@ export const EditAddress = () => { |
|
|
|
|
|
|
|
|
|
|
|
const [open, setOpen] = useState(false); |
|
|
|
const [open, setOpen] = useState(false); |
|
|
|
const [value, setValue] = useState<string | null>(null); |
|
|
|
const [value, setValue] = useState<string | null>(null); |
|
|
|
const [items, setItems] = useState<{label: string; value: string}[]>([]); |
|
|
|
const [items, setItems] = useState<{ label: string; value: string }[]>([]); |
|
|
|
const [selectedCountryLabel, setSelectedCountryLabel] = useState<string>(""); |
|
|
|
const [selectedCountryLabel, setSelectedCountryLabel] = useState<string>(""); |
|
|
|
const [countryList, setCountryList] = useState<any[]>([]); |
|
|
|
const [countryList, setCountryList] = useState<any[]>([]); |
|
|
|
|
|
|
|
|
|
|
@ -91,11 +92,11 @@ export const EditAddress = () => { |
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
settingApi.getCountryList().then((res) => { |
|
|
|
settingApi.getCountryList().then((res) => { |
|
|
|
const formattedCountries = res.map((item) => ({ |
|
|
|
const formattedCountries = res.map((item) => ({ |
|
|
|
label: `${item.name_en} (${item.country})`, |
|
|
|
label: `${getCountryTransLanguage(item)} (${item.country})`, |
|
|
|
value: item.name.toString(), |
|
|
|
value: item.name.toString(), |
|
|
|
flag: flagMap.get(item.name_en), |
|
|
|
flag: flagMap.get(item.name_en), |
|
|
|
name_en: item.name_en, |
|
|
|
name_en: getCountryTransLanguage(item), |
|
|
|
country: item.country |
|
|
|
country: item.country, |
|
|
|
})); |
|
|
|
})); |
|
|
|
setItems(formattedCountries); |
|
|
|
setItems(formattedCountries); |
|
|
|
setCountryList(formattedCountries); |
|
|
|
setCountryList(formattedCountries); |
|
|
@ -108,7 +109,8 @@ export const EditAddress = () => { |
|
|
|
// 如果有路由参数中的地址
|
|
|
|
// 如果有路由参数中的地址
|
|
|
|
const addressFromRoute = route.params?.address; |
|
|
|
const addressFromRoute = route.params?.address; |
|
|
|
if (addressFromRoute && addressFromRoute.country) { |
|
|
|
if (addressFromRoute && addressFromRoute.country) { |
|
|
|
const selectedCountry = countryList.find(item =>
|
|
|
|
const selectedCountry = countryList.find( |
|
|
|
|
|
|
|
(item) => |
|
|
|
item.name_en === addressFromRoute.country || |
|
|
|
item.name_en === addressFromRoute.country || |
|
|
|
item.value === addressFromRoute.country |
|
|
|
item.value === addressFromRoute.country |
|
|
|
); |
|
|
|
); |
|
|
@ -155,7 +157,9 @@ export const EditAddress = () => { |
|
|
|
newErrors.receiver_phone = t("address.errors.phone_required"); |
|
|
|
newErrors.receiver_phone = t("address.errors.phone_required"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!formData.receiver_phone_again) { |
|
|
|
if (!formData.receiver_phone_again) { |
|
|
|
newErrors.receiver_phone_again = t("address.errors.confirm_phone_required"); |
|
|
|
newErrors.receiver_phone_again = t( |
|
|
|
|
|
|
|
"address.errors.confirm_phone_required" |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
if (formData.receiver_phone !== formData.receiver_phone_again) { |
|
|
|
if (formData.receiver_phone !== formData.receiver_phone_again) { |
|
|
|
newErrors.receiver_phone_again = t("address.errors.phone_mismatch"); |
|
|
|
newErrors.receiver_phone_again = t("address.errors.phone_mismatch"); |
|
|
@ -170,7 +174,9 @@ export const EditAddress = () => { |
|
|
|
|
|
|
|
|
|
|
|
const handleSubmit = async () => { |
|
|
|
const handleSubmit = async () => { |
|
|
|
if (validateForm()) { |
|
|
|
if (validateForm()) { |
|
|
|
const selectedCountryObj = countryList.find(item => item.value === value); |
|
|
|
const selectedCountryObj = countryList.find( |
|
|
|
|
|
|
|
(item) => item.value === value |
|
|
|
|
|
|
|
); |
|
|
|
const submitData = { |
|
|
|
const submitData = { |
|
|
|
...formData, |
|
|
|
...formData, |
|
|
|
country: selectedCountryObj ? selectedCountryObj.name_en : "", |
|
|
|
country: selectedCountryObj ? selectedCountryObj.name_en : "", |
|
|
@ -219,14 +225,18 @@ export const EditAddress = () => { |
|
|
|
</TouchableOpacity> |
|
|
|
</TouchableOpacity> |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
|
|
|
|
|
|
|
|
<Text style={styles.titleHeading}>{t("address.select_recipient")}</Text> |
|
|
|
<Text style={styles.titleHeading}> |
|
|
|
|
|
|
|
{t("address.select_recipient")} |
|
|
|
|
|
|
|
</Text> |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
<View style={styles.recipientInfoForm}> |
|
|
|
<View style={styles.recipientInfoForm}> |
|
|
|
<View style={styles.contactFormContainer}> |
|
|
|
<View style={styles.contactFormContainer}> |
|
|
|
{/* First Name Field */} |
|
|
|
{/* First Name Field */} |
|
|
|
<View style={styles.formFieldContainer}> |
|
|
|
<View style={styles.formFieldContainer}> |
|
|
|
<View style={styles.flexRowCentered}> |
|
|
|
<View style={styles.flexRowCentered}> |
|
|
|
<Text style={styles.elegantTextSnippet}>{t("address.first_name")}</Text> |
|
|
|
<Text style={styles.elegantTextSnippet}> |
|
|
|
|
|
|
|
{t("address.first_name")} |
|
|
|
|
|
|
|
</Text> |
|
|
|
<Text style={styles.redTextHeading}>*</Text> |
|
|
|
<Text style={styles.redTextHeading}>*</Text> |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
<TextInput |
|
|
|
<TextInput |
|
|
@ -250,7 +260,9 @@ export const EditAddress = () => { |
|
|
|
{/* Last Name Field */} |
|
|
|
{/* Last Name Field */} |
|
|
|
<View style={styles.lastNameInputContainer}> |
|
|
|
<View style={styles.lastNameInputContainer}> |
|
|
|
<View style={styles.flexRowCentered}> |
|
|
|
<View style={styles.flexRowCentered}> |
|
|
|
<Text style={styles.elegantTextSnippet}>{t("address.last_name")}</Text> |
|
|
|
<Text style={styles.elegantTextSnippet}> |
|
|
|
|
|
|
|
{t("address.last_name")} |
|
|
|
|
|
|
|
</Text> |
|
|
|
<Text style={styles.redAsteriskTextStyle}>*</Text> |
|
|
|
<Text style={styles.redAsteriskTextStyle}>*</Text> |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
<TextInput |
|
|
|
<TextInput |
|
|
@ -258,7 +270,10 @@ export const EditAddress = () => { |
|
|
|
placeholder={t("address.placeholder.last_name")} |
|
|
|
placeholder={t("address.placeholder.last_name")} |
|
|
|
value={formData.receiver_last_name} |
|
|
|
value={formData.receiver_last_name} |
|
|
|
onChangeText={(text) => |
|
|
|
onChangeText={(text) => |
|
|
|
setFormData({ ...formData, receiver_last_name: text }) |
|
|
|
setFormData({ |
|
|
|
|
|
|
|
...formData, |
|
|
|
|
|
|
|
receiver_last_name: text, |
|
|
|
|
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
/> |
|
|
|
/> |
|
|
|
{errors.receiver_last_name && ( |
|
|
|
{errors.receiver_last_name && ( |
|
|
@ -270,16 +285,22 @@ export const EditAddress = () => { |
|
|
|
{/* 国家 */} |
|
|
|
{/* 国家 */} |
|
|
|
<View style={styles.lastNameInputContainer}> |
|
|
|
<View style={styles.lastNameInputContainer}> |
|
|
|
<View style={styles.flexRowCentered}> |
|
|
|
<View style={styles.flexRowCentered}> |
|
|
|
<Text style={styles.elegantTextSnippet}>{t("address.country")}</Text> |
|
|
|
<Text style={styles.elegantTextSnippet}> |
|
|
|
|
|
|
|
{t("address.country")} |
|
|
|
|
|
|
|
</Text> |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
<TouchableOpacity |
|
|
|
<TouchableOpacity |
|
|
|
style={styles.countrySelectorButton} |
|
|
|
style={styles.countrySelectorButton} |
|
|
|
onPress={() => setOpen(true)} |
|
|
|
onPress={() => setOpen(true)} |
|
|
|
> |
|
|
|
> |
|
|
|
{selectedCountryLabel ? ( |
|
|
|
{selectedCountryLabel ? ( |
|
|
|
<Text style={styles.selectedCountryText}>{selectedCountryLabel}</Text> |
|
|
|
<Text style={styles.selectedCountryText}> |
|
|
|
|
|
|
|
{selectedCountryLabel} |
|
|
|
|
|
|
|
</Text> |
|
|
|
) : ( |
|
|
|
) : ( |
|
|
|
<Text style={styles.placeholderStyle}>{t("address.placeholder.select_country")}</Text> |
|
|
|
<Text style={styles.placeholderStyle}> |
|
|
|
|
|
|
|
{t("address.placeholder.select_country")} |
|
|
|
|
|
|
|
</Text> |
|
|
|
)} |
|
|
|
)} |
|
|
|
<Text style={styles.dropdownArrow}>▼</Text> |
|
|
|
<Text style={styles.dropdownArrow}>▼</Text> |
|
|
|
</TouchableOpacity> |
|
|
|
</TouchableOpacity> |
|
|
@ -293,11 +314,15 @@ export const EditAddress = () => { |
|
|
|
<Text style={styles.elegantTextSnippet}> |
|
|
|
<Text style={styles.elegantTextSnippet}> |
|
|
|
{t("address.phone_number")} |
|
|
|
{t("address.phone_number")} |
|
|
|
</Text> |
|
|
|
</Text> |
|
|
|
<Text style={styles.redAsteriskTextStyle}>*</Text> |
|
|
|
<Text style={styles.redAsteriskTextStyle}> |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
</Text> |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
<TextInput |
|
|
|
<TextInput |
|
|
|
style={styles.pingFangText1} |
|
|
|
style={styles.pingFangText1} |
|
|
|
placeholder={t("address.placeholder.phone_number")} |
|
|
|
placeholder={t( |
|
|
|
|
|
|
|
"address.placeholder.phone_number" |
|
|
|
|
|
|
|
)} |
|
|
|
value={formData.receiver_phone} |
|
|
|
value={formData.receiver_phone} |
|
|
|
onChangeText={(text) => |
|
|
|
onChangeText={(text) => |
|
|
|
setFormData({ |
|
|
|
setFormData({ |
|
|
@ -317,11 +342,15 @@ export const EditAddress = () => { |
|
|
|
<Text style={styles.elegantTextSnippet}> |
|
|
|
<Text style={styles.elegantTextSnippet}> |
|
|
|
{t("address.confirm_phone_number")} |
|
|
|
{t("address.confirm_phone_number")} |
|
|
|
</Text> |
|
|
|
</Text> |
|
|
|
<Text style={styles.redAsteriskTextStyle}>*</Text> |
|
|
|
<Text style={styles.redAsteriskTextStyle}> |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
</Text> |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
<TextInput |
|
|
|
<TextInput |
|
|
|
style={styles.pingFangText1} |
|
|
|
style={styles.pingFangText1} |
|
|
|
placeholder={t("address.placeholder.confirm_phone_number")} |
|
|
|
placeholder={t( |
|
|
|
|
|
|
|
"address.placeholder.confirm_phone_number" |
|
|
|
|
|
|
|
)} |
|
|
|
value={formData.receiver_phone_again} |
|
|
|
value={formData.receiver_phone_again} |
|
|
|
onChangeText={(text) => |
|
|
|
onChangeText={(text) => |
|
|
|
setFormData({ |
|
|
|
setFormData({ |
|
|
@ -347,7 +376,9 @@ export const EditAddress = () => { |
|
|
|
{/* WhatsApp Field */} |
|
|
|
{/* WhatsApp Field */} |
|
|
|
<View style={styles.lastNameInputContainer}> |
|
|
|
<View style={styles.lastNameInputContainer}> |
|
|
|
<View style={styles.flexRowCentered}> |
|
|
|
<View style={styles.flexRowCentered}> |
|
|
|
<Text style={styles.elegantTextSnippet}>{t("address.whatsapp")}</Text> |
|
|
|
<Text style={styles.elegantTextSnippet}> |
|
|
|
|
|
|
|
{t("address.whatsapp")} |
|
|
|
|
|
|
|
</Text> |
|
|
|
<Text style={styles.redTextHeading}>*</Text> |
|
|
|
<Text style={styles.redTextHeading}>*</Text> |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
<TextInput |
|
|
|
<TextInput |
|
|
@ -401,7 +432,9 @@ export const EditAddress = () => { |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
trackColor={{ false: "#767577", true: "#81b0ff" }} |
|
|
|
trackColor={{ false: "#767577", true: "#81b0ff" }} |
|
|
|
thumbColor={formData.is_default ? "#002fa7" : "#f4f3f4"} |
|
|
|
thumbColor={ |
|
|
|
|
|
|
|
formData.is_default ? "#002fa7" : "#f4f3f4" |
|
|
|
|
|
|
|
} |
|
|
|
ios_backgroundColor="#3e3e3e" |
|
|
|
ios_backgroundColor="#3e3e3e" |
|
|
|
/> |
|
|
|
/> |
|
|
|
</View> |
|
|
|
</View> |
|
|
@ -414,7 +447,9 @@ export const EditAddress = () => { |
|
|
|
style={styles.primaryButtonStyle} |
|
|
|
style={styles.primaryButtonStyle} |
|
|
|
onPress={handleSubmit} |
|
|
|
onPress={handleSubmit} |
|
|
|
> |
|
|
|
> |
|
|
|
<Text style={styles.buttonText}>{t("address.submit")}</Text> |
|
|
|
<Text style={styles.buttonText}> |
|
|
|
|
|
|
|
{t("address.submit")} |
|
|
|
|
|
|
|
</Text> |
|
|
|
</TouchableOpacity> |
|
|
|
</TouchableOpacity> |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
</View> |
|
|
@ -431,7 +466,9 @@ export const EditAddress = () => { |
|
|
|
<View style={styles.modalContainer}> |
|
|
|
<View style={styles.modalContainer}> |
|
|
|
<View style={styles.modalContent}> |
|
|
|
<View style={styles.modalContent}> |
|
|
|
<View style={styles.modalHeader}> |
|
|
|
<View style={styles.modalHeader}> |
|
|
|
<Text style={styles.modalTitle}>{t("address.select_country")}</Text> |
|
|
|
<Text style={styles.modalTitle}> |
|
|
|
|
|
|
|
{t("address.select_country")} |
|
|
|
|
|
|
|
</Text> |
|
|
|
<TouchableOpacity onPress={() => setOpen(false)}> |
|
|
|
<TouchableOpacity onPress={() => setOpen(false)}> |
|
|
|
<Text style={styles.closeButton}>{t("address.close")}</Text> |
|
|
|
<Text style={styles.closeButton}>{t("address.close")}</Text> |
|
|
|
</TouchableOpacity> |
|
|
|
</TouchableOpacity> |
|
|
@ -445,10 +482,7 @@ export const EditAddress = () => { |
|
|
|
onPress={() => handleCountrySelect(item)} |
|
|
|
onPress={() => handleCountrySelect(item)} |
|
|
|
> |
|
|
|
> |
|
|
|
{item.flag && ( |
|
|
|
{item.flag && ( |
|
|
|
<Image
|
|
|
|
<Image source={item.flag} style={styles.flagImage} /> |
|
|
|
source={item.flag}
|
|
|
|
|
|
|
|
style={styles.flagImage}
|
|
|
|
|
|
|
|
/> |
|
|
|
|
|
|
|
)} |
|
|
|
)} |
|
|
|
<Text style={styles.countryItemText}>{item.label}</Text> |
|
|
|
<Text style={styles.countryItemText}>{item.label}</Text> |
|
|
|
{value === item.value && ( |
|
|
|
{value === item.value && ( |
|
|
@ -471,7 +505,7 @@ export const EditAddress = () => { |
|
|
|
const styles = StyleSheet.create({ |
|
|
|
const styles = StyleSheet.create({ |
|
|
|
safeArea: { |
|
|
|
safeArea: { |
|
|
|
flex: 1, |
|
|
|
flex: 1, |
|
|
|
backgroundColor: '#fff', |
|
|
|
backgroundColor: "#fff", |
|
|
|
}, |
|
|
|
}, |
|
|
|
safeAreaContent: { |
|
|
|
safeAreaContent: { |
|
|
|
flex: 1, |
|
|
|
flex: 1, |
|
|
@ -854,7 +888,7 @@ const styles = StyleSheet.create({ |
|
|
|
borderTopLeftRadius: 20, |
|
|
|
borderTopLeftRadius: 20, |
|
|
|
borderTopRightRadius: 20, |
|
|
|
borderTopRightRadius: 20, |
|
|
|
width: "100%", |
|
|
|
width: "100%", |
|
|
|
height: Dimensions.get('window').height * 0.8, |
|
|
|
height: Dimensions.get("window").height * 0.8, |
|
|
|
display: "flex", |
|
|
|
display: "flex", |
|
|
|
flexDirection: "column", |
|
|
|
flexDirection: "column", |
|
|
|
}, |
|
|
|
}, |
|
|
|