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