|
|
|
@ -43,6 +43,7 @@ const Address = ({ |
|
|
|
|
provinces, |
|
|
|
|
cities, |
|
|
|
|
createAddress, |
|
|
|
|
editAddress, |
|
|
|
|
profileFields, |
|
|
|
|
setProfileFields, |
|
|
|
|
setProfile, |
|
|
|
@ -58,36 +59,65 @@ const Address = ({ |
|
|
|
|
|
|
|
|
|
const profilePage = React.useMemo(() => { |
|
|
|
|
return route.params?.type === "profile"; |
|
|
|
|
},[route]); |
|
|
|
|
}, [route]); |
|
|
|
|
|
|
|
|
|
const editAddressPreviousValue = React.useMemo(() => { |
|
|
|
|
return route.params?.form; |
|
|
|
|
}, [route]); |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
getProvince(); |
|
|
|
|
setProfileFields({ |
|
|
|
|
file: user?.picFileId, |
|
|
|
|
picFileId: user?.picFileId, |
|
|
|
|
docFileIds: user?.docFileIds, |
|
|
|
|
cellphone: user?.cellphone, |
|
|
|
|
firstName: user?.firstName, |
|
|
|
|
lastName: user?.lastName, |
|
|
|
|
password: user?.password, |
|
|
|
|
username: user?.username, |
|
|
|
|
address: user?.address, |
|
|
|
|
email: user?.email, |
|
|
|
|
birthDate: user?.birthDate, |
|
|
|
|
gender: user?.gender, |
|
|
|
|
status: user?.status, |
|
|
|
|
nationalId: user?.nationalId, |
|
|
|
|
phone: user?.phone, |
|
|
|
|
schools: user?.schools, |
|
|
|
|
zoneId: user?.zoneId, |
|
|
|
|
schoolId: user?.schoolId, |
|
|
|
|
postalCode: user?.postalCode, |
|
|
|
|
gradeIds: user?.gradeIds, |
|
|
|
|
provinceId: user?.provinceId, |
|
|
|
|
cityId: user?.cityId, |
|
|
|
|
}); |
|
|
|
|
if (profilePage) { |
|
|
|
|
setProfileFields({ |
|
|
|
|
file: user?.picFileId, |
|
|
|
|
picFileId: user?.picFileId, |
|
|
|
|
docFileIds: user?.docFileIds, |
|
|
|
|
cellphone: user?.cellphone, |
|
|
|
|
firstName: user?.firstName, |
|
|
|
|
lastName: user?.lastName, |
|
|
|
|
password: user?.password, |
|
|
|
|
username: user?.username, |
|
|
|
|
address: user?.address, |
|
|
|
|
email: user?.email, |
|
|
|
|
birthDate: user?.birthDate, |
|
|
|
|
gender: user?.gender, |
|
|
|
|
status: user?.status, |
|
|
|
|
nationalId: user?.nationalId, |
|
|
|
|
phone: user?.phone, |
|
|
|
|
schools: user?.schools, |
|
|
|
|
zoneId: user?.zoneId, |
|
|
|
|
schoolId: user?.schoolId, |
|
|
|
|
postalCode: user?.postalCode, |
|
|
|
|
gradeIds: user?.gradeIds, |
|
|
|
|
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: "باشه", |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
createAddress({ |
|
|
|
|
firstName, |
|
|
|
|
lastName, |
|
|
|
|
cellphone, |
|
|
|
|
phone, |
|
|
|
|
address: mapAddress, |
|
|
|
|
provinceId: provinces.filter( |
|
|
|
|
(province) => province.name === provinceId |
|
|
|
|
)[0].id, |
|
|
|
|
cityId: cities.filter((city) => city.name === cityId)[0]?.id, |
|
|
|
|
postalCode, |
|
|
|
|
location: null, |
|
|
|
|
}); |
|
|
|
|
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: 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, |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|