|
|
|
@ -11,7 +11,8 @@ import { |
|
|
|
|
} from "react-native"; |
|
|
|
|
import React, { useEffect, useState } from "react"; |
|
|
|
|
import { connect } from "react-redux"; |
|
|
|
|
import { publicApi, userAddress } from "../../redux/actions"; |
|
|
|
|
import { publicApi, user, userAddress } from "../../redux/actions"; |
|
|
|
|
import onInput from "../../utils/onInput"; |
|
|
|
|
import { useNavigation } from "@react-navigation/native"; |
|
|
|
|
import { asyncAwesomeAlert } from "../../utils/AsyncWrappers"; |
|
|
|
|
|
|
|
|
@ -30,6 +31,8 @@ import fontSize from "../../constants/fontSize"; |
|
|
|
|
const ios = Platform.OS === "ios"; |
|
|
|
|
|
|
|
|
|
const Address = ({ |
|
|
|
|
user, |
|
|
|
|
route, |
|
|
|
|
city, |
|
|
|
|
province, |
|
|
|
|
getCity, |
|
|
|
@ -37,18 +40,45 @@ const Address = ({ |
|
|
|
|
provinces, |
|
|
|
|
cities, |
|
|
|
|
createAddress, |
|
|
|
|
profileFields, |
|
|
|
|
setProfileFields, |
|
|
|
|
setProfile, |
|
|
|
|
loading, |
|
|
|
|
setPhase, |
|
|
|
|
cityLoading, |
|
|
|
|
}) => { |
|
|
|
|
const profilePage = route.params.type === "profile"; |
|
|
|
|
const colorScheme = Appearance.getColorScheme(); |
|
|
|
|
const navigation = useNavigation(); |
|
|
|
|
|
|
|
|
|
const [addressFields, setAddressFields] = useState({}); |
|
|
|
|
const [mapAddress, setMapAddress] = useState(null); |
|
|
|
|
|
|
|
|
|
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, |
|
|
|
|
}); |
|
|
|
|
}, []); |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
@ -135,6 +165,52 @@ const Address = ({ |
|
|
|
|
navigation.goBack(); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const submitProfile = () => { |
|
|
|
|
const { |
|
|
|
|
firstName, |
|
|
|
|
lastName, |
|
|
|
|
username, |
|
|
|
|
password, |
|
|
|
|
postalCode, |
|
|
|
|
address, |
|
|
|
|
email, |
|
|
|
|
phone, |
|
|
|
|
picFileId, |
|
|
|
|
gender, |
|
|
|
|
nationalId, |
|
|
|
|
birthDate, |
|
|
|
|
schools, |
|
|
|
|
gradeIds, |
|
|
|
|
status, |
|
|
|
|
provinceId, |
|
|
|
|
cityId, |
|
|
|
|
docFileIds, |
|
|
|
|
} = profileFields; |
|
|
|
|
const data = { |
|
|
|
|
firstName: firstName, |
|
|
|
|
lastName: lastName, |
|
|
|
|
username: username, |
|
|
|
|
cellphone: user.cellphone, |
|
|
|
|
password: password, |
|
|
|
|
postalCode: postalCode, |
|
|
|
|
address: address, |
|
|
|
|
email: email, |
|
|
|
|
phone: phone, |
|
|
|
|
nationalId: nationalId, |
|
|
|
|
picFileId: picFileId, |
|
|
|
|
gender: gender, |
|
|
|
|
birthDate: birthDate, |
|
|
|
|
schools: schools, |
|
|
|
|
gradeIds: gradeIds, |
|
|
|
|
status: status, |
|
|
|
|
provinceId: provinceId, |
|
|
|
|
cityId: cityId, |
|
|
|
|
docFileIds: docFileIds, |
|
|
|
|
}; |
|
|
|
|
setProfile(data); |
|
|
|
|
navigation.goBack(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const Header = ({ title, text }) => { |
|
|
|
|
return ( |
|
|
|
|
<View style={tw("flex flex-col mt-2")}> |
|
|
|
@ -170,10 +246,10 @@ const Address = ({ |
|
|
|
|
<Navbar |
|
|
|
|
headerOptions={{ |
|
|
|
|
logo: false, |
|
|
|
|
menu: true, |
|
|
|
|
menu: profilePage ? false : true, |
|
|
|
|
hamburgerMenu: false, |
|
|
|
|
title: "", |
|
|
|
|
bookmark: true, |
|
|
|
|
title: profilePage ? "اطلاعات کاربری" : "", |
|
|
|
|
bookmark: profilePage ? false : true, |
|
|
|
|
qr: false, |
|
|
|
|
back: true, |
|
|
|
|
}} |
|
|
|
@ -194,8 +270,14 @@ const Address = ({ |
|
|
|
|
textAlign="right" |
|
|
|
|
name="firstName" |
|
|
|
|
maxlength="40" |
|
|
|
|
value={addressFields?.firstName} |
|
|
|
|
onChange={(name, value) => onChange(name, value)} |
|
|
|
|
value={ |
|
|
|
|
profilePage ? profileFields.firstName : addressFields?.firstName |
|
|
|
|
} |
|
|
|
|
onChange={(name, value) => |
|
|
|
|
profilePage |
|
|
|
|
? setProfileFields({ ...profileFields, firstName: value }) |
|
|
|
|
: onChange(name, value) |
|
|
|
|
} |
|
|
|
|
autoFocus={false} |
|
|
|
|
regex={(val) => val} |
|
|
|
|
/> |
|
|
|
@ -205,11 +287,32 @@ const Address = ({ |
|
|
|
|
textAlign="right" |
|
|
|
|
name="lastName" |
|
|
|
|
maxlength="60" |
|
|
|
|
value={addressFields?.lastName} |
|
|
|
|
onChange={(name, value) => onChange(name, value)} |
|
|
|
|
value={ |
|
|
|
|
profilePage ? profileFields.lastName : addressFields?.lastName |
|
|
|
|
} |
|
|
|
|
onChange={(name, value) => |
|
|
|
|
profilePage |
|
|
|
|
? setProfileFields({ ...profileFields, lastName: value }) |
|
|
|
|
: onChange(name, value) |
|
|
|
|
} |
|
|
|
|
autoFocus={false} |
|
|
|
|
regex={(val) => val} |
|
|
|
|
/> |
|
|
|
|
{profilePage && ( |
|
|
|
|
<CustomTextInput |
|
|
|
|
label="کد ملی" |
|
|
|
|
placeholder="" |
|
|
|
|
textAlign="left" |
|
|
|
|
name="nationalId" |
|
|
|
|
maxlength="10" |
|
|
|
|
value={profileFields.nationalId} |
|
|
|
|
onChange={(name, value) => |
|
|
|
|
setProfileFields({ ...profileFields, nationalId: value }) |
|
|
|
|
} |
|
|
|
|
autoFocus={false} |
|
|
|
|
regex={onInput.numberOnly} |
|
|
|
|
/> |
|
|
|
|
)} |
|
|
|
|
<Header |
|
|
|
|
title="شماره تماس" |
|
|
|
|
text="( شماره موبایل و شماره تلفن ثابت خود را
|
|
|
|
@ -221,10 +324,16 @@ const Address = ({ |
|
|
|
|
textAlign="left" |
|
|
|
|
name="cellphone" |
|
|
|
|
maxlength="11" |
|
|
|
|
value={addressFields?.cellphone} |
|
|
|
|
onChange={(name, value) => onChange(name, value)} |
|
|
|
|
value={ |
|
|
|
|
profilePage ? profileFields.cellphone : addressFields?.cellphone |
|
|
|
|
} |
|
|
|
|
onChange={(name, value) => |
|
|
|
|
profilePage |
|
|
|
|
? setProfileFields({ ...profileFields, cellphone: value }) |
|
|
|
|
: onChange(name, value) |
|
|
|
|
} |
|
|
|
|
autoFocus={false} |
|
|
|
|
regex={(val) => val} |
|
|
|
|
regex={onInput.phonenumber} |
|
|
|
|
/> |
|
|
|
|
<CustomTextInput |
|
|
|
|
label="شماره تلفن" |
|
|
|
@ -232,10 +341,14 @@ const Address = ({ |
|
|
|
|
textAlign="left" |
|
|
|
|
name="phone" |
|
|
|
|
maxlength="11" |
|
|
|
|
value={addressFields?.phone} |
|
|
|
|
onChange={(name, value) => onChange(name, value)} |
|
|
|
|
value={profilePage ? profileFields.phone : addressFields?.phone} |
|
|
|
|
onChange={(name, value) => |
|
|
|
|
profilePage |
|
|
|
|
? setProfileFields({ ...profileFields, phone: value }) |
|
|
|
|
: onChange(name, value) |
|
|
|
|
} |
|
|
|
|
autoFocus={false} |
|
|
|
|
regex={(val) => val} |
|
|
|
|
regex={onInput.phonenumber} |
|
|
|
|
/> |
|
|
|
|
<Header |
|
|
|
|
title="آدرس" |
|
|
|
@ -244,8 +357,16 @@ const Address = ({ |
|
|
|
|
/> |
|
|
|
|
<View style={tw("w-full mt-4")}> |
|
|
|
|
<Select |
|
|
|
|
defaultValue={province[0]} |
|
|
|
|
onChange={(name, value) => onChange(name, value)} |
|
|
|
|
defaultValue={ |
|
|
|
|
profilePage |
|
|
|
|
? provinces?.filter( |
|
|
|
|
(province) => province.id === profileFields.provinceId |
|
|
|
|
)[0]?.name || province[0] |
|
|
|
|
: city[0] |
|
|
|
|
} |
|
|
|
|
onChange={(name, value) => |
|
|
|
|
value === "استان" ? {} : onChange(name, value) |
|
|
|
|
} |
|
|
|
|
options={province} |
|
|
|
|
width={"100%"} |
|
|
|
|
name="provinceId" |
|
|
|
@ -253,34 +374,50 @@ const Address = ({ |
|
|
|
|
</View> |
|
|
|
|
<View style={tw("w-full mt-4")}> |
|
|
|
|
<Select |
|
|
|
|
defaultValue={city[0]} |
|
|
|
|
onChange={(name, value) => onChange(name, value)} |
|
|
|
|
defaultValue={ |
|
|
|
|
profilePage |
|
|
|
|
? cities?.filter( |
|
|
|
|
(city) => city.id === profileFields.cityId |
|
|
|
|
)[0]?.name || city[0] |
|
|
|
|
: city[0] |
|
|
|
|
} |
|
|
|
|
onChange={(name, value) => |
|
|
|
|
value === "شهر" ? {} : onChange(name, value) |
|
|
|
|
} |
|
|
|
|
options={city} |
|
|
|
|
width={"100%"} |
|
|
|
|
name="cityId" |
|
|
|
|
/> |
|
|
|
|
</View> |
|
|
|
|
<View style={tw('mb-4')}> |
|
|
|
|
<View style={tw("mb-4")}> |
|
|
|
|
<CustomTextInput |
|
|
|
|
label="کد پستی" |
|
|
|
|
placeholder="" |
|
|
|
|
textAlign="left" |
|
|
|
|
name="postalCode" |
|
|
|
|
maxlength="60" |
|
|
|
|
value={addressFields?.postalCode} |
|
|
|
|
onChange={(name, value) => onChange(name, value)} |
|
|
|
|
value={ |
|
|
|
|
profilePage |
|
|
|
|
? profileFields.postalCode |
|
|
|
|
: addressFields?.postalCode |
|
|
|
|
} |
|
|
|
|
onChange={(name, value) => |
|
|
|
|
profilePage |
|
|
|
|
? setProfileFields({ ...profileFields, postalCode: value }) |
|
|
|
|
: onChange(name, value) |
|
|
|
|
} |
|
|
|
|
autoFocus={false} |
|
|
|
|
regex={(val) => val} |
|
|
|
|
/> |
|
|
|
|
</View> |
|
|
|
|
|
|
|
|
|
<CustomPressable |
|
|
|
|
title={"ثبت آدرس"} |
|
|
|
|
title={profilePage ? "ذخیره اطلاعات و بازگشت به صفحه قبل" : "ثبت آدرس"} |
|
|
|
|
backgroundColor={Colors.theme1[colorScheme].greenCF} |
|
|
|
|
color={"white"} |
|
|
|
|
border={{ color: "#196EC0", width: 0 }} |
|
|
|
|
width={"100%"} |
|
|
|
|
onPress={() => navigation.push("Address")} |
|
|
|
|
onPress={() => profilePage ? submitProfile() : submit()} |
|
|
|
|
/> |
|
|
|
|
</View> |
|
|
|
|
</ScrollView> |
|
|
|
@ -308,12 +445,16 @@ const mapStateToProps = (state) => ({ |
|
|
|
|
city: state.publicApi.city, |
|
|
|
|
loading: state.userAddress.loading, |
|
|
|
|
cityLoading: state.publicApi.loading, |
|
|
|
|
user: state.user.status, |
|
|
|
|
profileFields: state.user.profileFields, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = { |
|
|
|
|
getProvince: publicApi.getProvince, |
|
|
|
|
getCity: publicApi.getCity, |
|
|
|
|
createAddress: userAddress.add, |
|
|
|
|
setProfileFields: user.setProfileFields, |
|
|
|
|
setProfile: user.setProfile |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(Address); |
|
|
|
|