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