reza fixed edit address

master
Reza_ashrafi 3 years ago
parent be780c908e
commit 8aae174d19
  1. 2
      src/components/CustomTextInput.js
  2. 106
      src/screens/Address/index.js
  3. 20
      src/screens/Profile/components/ProfileAddress/index.js

@ -23,6 +23,7 @@ const FloatingLabelInput = ({
keyboardType,
multiline,
theme,
defaultValue,
editable = true,
...props
}) => {
@ -89,6 +90,7 @@ const FloatingLabelInput = ({
underlineColorAndroid={"transparent"}
maxLength={maxLength}
value={value}
defaultValue={defaultValue}
onBlur={() => (value ? {} : setIsFocused(() => false))}
keyboardType={keyboardType}
multiline={multiline}

@ -43,6 +43,7 @@ const Address = ({
provinces,
cities,
createAddress,
editAddress,
profileFields,
setProfileFields,
setProfile,
@ -60,8 +61,13 @@ const Address = ({
return route.params?.type === "profile";
}, [route]);
const editAddressPreviousValue = React.useMemo(() => {
return route.params?.form;
}, [route]);
useEffect(() => {
getProvince();
if (profilePage) {
setProfileFields({
file: user?.picFileId,
picFileId: user?.picFileId,
@ -86,8 +92,32 @@ const Address = ({
provinceId: user?.provinceId,
cityId: user?.cityId,
});
}
if (route.params?.type === "editAddress") {
setAddressFields({
firstName: editAddressPreviousValue?.firstName,
lastName: editAddressPreviousValue?.lastName,
cellphone: editAddressPreviousValue?.cellphone,
phone: editAddressPreviousValue?.phone,
provinceId: editAddressPreviousValue?.provinceId,
cityId: editAddressPreviousValue?.cityId,
postalCode: editAddressPreviousValue?.postalCode,
id: editAddressPreviousValue?.id,
});
setMapAddress(editAddressPreviousValue?.address);
}
}, []);
useEffect(() => {
if (route.params?.type === "editAddress" && provinces?.length) {
getCity({
provinceId: provinces?.filter(
(province) => province?.name === editAddressPreviousValue?.provinceId
)[0]?.id,
});
}
}, [provinces]);
useEffect(() => {
StatusBar.setBarStyle(
`${theme === "light" ? "dark" : "light"}-content`,
@ -98,9 +128,9 @@ const Address = ({
useEffect(() => {
if (addressFields?.provinceId) {
getCity({
provinceId: provinces.filter(
(province) => province.name === addressFields?.provinceId
)[0].id,
provinceId: provinces?.filter(
(province) => province?.name === addressFields?.provinceId
)[0]?.id,
});
}
}, [addressFields]);
@ -115,10 +145,10 @@ const Address = ({
lastName,
cellphone,
phone,
address,
provinceId,
cityId,
postalCode,
id
} = addressFields;
if (!firstName) {
@ -177,12 +207,6 @@ const Address = ({
}
);
}
if (phone.length !== 11) {
return asyncAwesomeAlert("خطا", "شماره تلفن میبایست یازده رقم باشد.", {
showCancelButton: false,
confirmText: "باشه",
});
}
}
if (!provinceId) {
@ -211,26 +235,43 @@ const Address = ({
}
}
if (!mapAddress) {
if (!mapAddress && !editAddressPreviousValue?.address) {
return asyncAwesomeAlert("خطا", "آدرس خود را از روی نقشه انتخاب کن", {
showCancelButton: false,
confirmText: "باشه",
});
}
if (route.params?.type === "editAddress") {
editAddress({
firstName: firstName,
lastName: lastName,
cellphone: cellphone,
phone: phone,
address: mapAddress,
provinceId: provinces?.filter(
(province) => province?.name === provinceId
)[0]?.id,
cityId: cities?.filter((city) => city?.name === cityId)[0]?.id,
postalCode: postalCode,
location: null,
id,
});
} else {
createAddress({
firstName,
lastName,
cellphone,
phone,
firstName: firstName,
lastName: lastName,
cellphone: cellphone,
phone: phone,
address: mapAddress,
provinceId: provinces.filter(
(province) => province.name === provinceId
)[0].id,
cityId: cities.filter((city) => city.name === cityId)[0]?.id,
postalCode,
provinceId: provinces?.filter(
(province) => province?.name === provinceId
)[0]?.id,
cityId: cities?.filter((city) => city?.name === cityId)[0]?.id,
postalCode: postalCode,
location: null,
});
}
navigation.goBack();
};
@ -387,7 +428,9 @@ const Address = ({
name="lastName"
maxlength="60"
value={
profilePage ? profileFields?.lastName : addressFields?.lastName
profilePage
? profileFields?.lastName
: addressFields?.lastName
}
onChange={(name, value) =>
profilePage
@ -448,7 +491,9 @@ const Address = ({
textAlign="left"
name="phone"
maxLength={11}
value={profilePage ? profileFields?.phone : addressFields?.phone}
value={
profilePage ? profileFields?.phone : addressFields?.phone
}
onChange={(name, value) =>
profilePage
? setProfileFields({ ...profileFields, phone: value })
@ -468,9 +513,14 @@ const Address = ({
defaultValue={
profilePage
? provinces?.filter(
(province) => province.id === profileFields?.provinceId
(province) =>
province?.id === profileFields?.provinceId
)[0]?.name || province[0]
: provinces?.filter(
(province) =>
province?.id ===
editAddressPreviousValue?.provinceId
)[0]?.name || province[0]
: province[0]
}
onChange={(name, value) =>
value === "استان" ? {} : onChange(name, value)
@ -485,9 +535,12 @@ const Address = ({
defaultValue={
profilePage
? cities?.filter(
(city) => city.id === profileFields?.cityId
(city) => city?.id === profileFields?.cityId
)[0]?.name || city[0]
: cities?.filter(
(city) =>
city?.id === editAddressPreviousValue?.cityId
)[0]?.name || city[0]
: city[0]
}
onChange={(name, value) =>
value === "شهرستان" ? {} : onChange(name, value)
@ -608,6 +661,7 @@ const mapDispatchToProps = {
createAddress: userAddress.add,
setProfileFields: user.setProfileFields,
setProfile: user.setProfile,
editAddress: userAddress.update,
};
export default connect(mapStateToProps, mapDispatchToProps)(Address);

@ -109,7 +109,15 @@ const ProfileAddress = ({
</Text>
</View>
<View style={tw("flex flex-row-reverse")}>
<Pressable style={tw("ml-4")}>
<Pressable
style={tw("ml-4")}
onPress={() =>
navigation.navigate("CreateAddress", {
type: "editAddress",
form: address,
})
}
>
<Ionicons
name="ios-pencil-sharp"
size={20}
@ -227,7 +235,15 @@ const ProfileAddress = ({
</View>
{!active ? (
<View style={tw("flex flex-row-reverse")}>
<Pressable style={tw("ml-4")}>
<Pressable
style={tw("ml-4")}
onPress={() =>
navigation.navigate("CreateAddress", {
type: "editAddress",
form: address,
})
}
>
<Ionicons
name="ios-pencil-sharp"
size={20}

Loading…
Cancel
Save