|
|
|
@ -47,7 +47,7 @@ export const Address = ({ |
|
|
|
|
const [mapAddress, setMapAddress] = useState(null); |
|
|
|
|
const navigation = useNavigate(); |
|
|
|
|
const location = useLocation(); |
|
|
|
|
|
|
|
|
|
console.log({ provinces }); |
|
|
|
|
useEffect(() => { |
|
|
|
|
setHeaderOptions(headerOptions); |
|
|
|
|
if (province.length <= 1) { |
|
|
|
@ -91,39 +91,54 @@ export const Address = ({ |
|
|
|
|
}, [addressInfo]); |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
console.log({ addressFields }); |
|
|
|
|
if (addressFields?.provinceId) { |
|
|
|
|
console.log({ addressFields }); |
|
|
|
|
getCity({ |
|
|
|
|
provinceId: provinces.filter( |
|
|
|
|
(province) => province.name === addressFields?.provinceId |
|
|
|
|
)[0]?.id, |
|
|
|
|
provinceId: addressFields?.provinceId, |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}, [addressFields]); |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
console.log({ profileFields }); |
|
|
|
|
if (profileFields?.provinceId) { |
|
|
|
|
getCity({ |
|
|
|
|
provinceId: provinces.filter( |
|
|
|
|
(province) => province.name === profileFields?.provinceId |
|
|
|
|
)[0]?.id, |
|
|
|
|
provinceId: profileFields?.provinceId, |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}, [profileFields]); |
|
|
|
|
|
|
|
|
|
const onChange = (name, value) => { |
|
|
|
|
console.log({ name, value }); |
|
|
|
|
setAddressFields({ ...addressFields, [name]: value }); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const submitProfile = () => { |
|
|
|
|
if (user.cellphone && user.cellphone.length < 11) { |
|
|
|
|
setDialog({ |
|
|
|
|
text: "شماره موبایل خود را وارد کنید.", |
|
|
|
|
type: "alert", |
|
|
|
|
accept: () => {}, |
|
|
|
|
open: true, |
|
|
|
|
}); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
const postalCode = profileFields?.postalCode || user.postalCode; |
|
|
|
|
if (postalCode && postalCode.length < 10) { |
|
|
|
|
setDialog({ |
|
|
|
|
text: "شماره کد پستی خود را وارد کنید.", |
|
|
|
|
type: "alert", |
|
|
|
|
accept: () => {}, |
|
|
|
|
open: true, |
|
|
|
|
}); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
const data = { |
|
|
|
|
firstName: profileFields?.firstName || user.firstName, |
|
|
|
|
lastName: profileFields?.lastName || user.lastName, |
|
|
|
|
username: profileFields?.username || user.username, |
|
|
|
|
cellphone: user.cellphone, |
|
|
|
|
password: profileFields?.password || user.password, |
|
|
|
|
postalCode: profileFields?.postalCode || user.postalCode, |
|
|
|
|
postalCode, |
|
|
|
|
address: profileFields?.address || user.address, |
|
|
|
|
email: profileFields?.email || user.email, |
|
|
|
|
phone: profileFields?.phone || user.phone, |
|
|
|
@ -133,18 +148,13 @@ export const Address = ({ |
|
|
|
|
birthDate: profileFields?.birthDate || user.birthDate, |
|
|
|
|
schools: profileFields?.schools || user.schools, |
|
|
|
|
gradeIds: profileFields?.gradeIds || user.gradeIds, |
|
|
|
|
provinceId: |
|
|
|
|
provinces.filter( |
|
|
|
|
(province) => province.name === profileFields?.provinceId |
|
|
|
|
)[0]?.id || user.provinceId, |
|
|
|
|
cityId: |
|
|
|
|
cities.filter((city) => city.name === profileFields?.cityId)[0]?.id || |
|
|
|
|
user.cityId, |
|
|
|
|
provinceId: profileFields?.provinceId || user.provinceId, |
|
|
|
|
cityId: profileFields?.cityId || user.cityId, |
|
|
|
|
docFileIds: profileFields?.docFileIds || user.docFileIds, |
|
|
|
|
}; |
|
|
|
|
setProfile(data); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const [activeCheckbox, setActiveCheckbox] = useState(true); |
|
|
|
|
const submit = () => { |
|
|
|
|
const { |
|
|
|
|
firstName, |
|
|
|
@ -157,7 +167,7 @@ export const Address = ({ |
|
|
|
|
postalCode, |
|
|
|
|
} = addressFields; |
|
|
|
|
|
|
|
|
|
if (!firstName) { |
|
|
|
|
if (!activeCheckbox && !firstName) { |
|
|
|
|
setDialog({ |
|
|
|
|
text: "نام خود را وارد کنید.", |
|
|
|
|
type: "alert", |
|
|
|
@ -166,7 +176,7 @@ export const Address = ({ |
|
|
|
|
}); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (!lastName) { |
|
|
|
|
if (!activeCheckbox && !lastName) { |
|
|
|
|
setDialog({ |
|
|
|
|
text: "نام خانوادگی خود را وارد کنید.", |
|
|
|
|
type: "alert", |
|
|
|
@ -175,7 +185,7 @@ export const Address = ({ |
|
|
|
|
}); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (!cellphone) { |
|
|
|
|
if (!activeCheckbox && (!cellphone || cellphone.length < 11)) { |
|
|
|
|
setDialog({ |
|
|
|
|
text: "شماره موبایل خود را وارد کنید.", |
|
|
|
|
type: "alert", |
|
|
|
@ -184,7 +194,7 @@ export const Address = ({ |
|
|
|
|
}); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (!phone) { |
|
|
|
|
if (!activeCheckbox && !phone) { |
|
|
|
|
setDialog({ |
|
|
|
|
text: "شماره تلفن خود را وارد کنید.", |
|
|
|
|
type: "alert", |
|
|
|
@ -211,7 +221,7 @@ export const Address = ({ |
|
|
|
|
}); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (!postalCode) { |
|
|
|
|
if (!postalCode || postalCode.length < 10) { |
|
|
|
|
setDialog({ |
|
|
|
|
text: "کد پستی خود را وارد کنید.", |
|
|
|
|
type: "alert", |
|
|
|
@ -237,15 +247,8 @@ export const Address = ({ |
|
|
|
|
cellphone, |
|
|
|
|
phone, |
|
|
|
|
address: mapAddress, |
|
|
|
|
provinceId: |
|
|
|
|
typeof provinceId === "number" |
|
|
|
|
? provinceId |
|
|
|
|
: provinces.filter((province) => province.name === provinceId)[0] |
|
|
|
|
?.id, |
|
|
|
|
cityId: |
|
|
|
|
typeof cityId === "number" |
|
|
|
|
? cityId |
|
|
|
|
: cities.filter((city) => city.name === cityId)[0]?.id, |
|
|
|
|
provinceId, |
|
|
|
|
cityId, |
|
|
|
|
postalCode, |
|
|
|
|
location: null, |
|
|
|
|
}); |
|
|
|
@ -256,15 +259,8 @@ export const Address = ({ |
|
|
|
|
cellphone, |
|
|
|
|
phone, |
|
|
|
|
address: mapAddress, |
|
|
|
|
provinceId: |
|
|
|
|
typeof provinceId === "number" |
|
|
|
|
? provinceId |
|
|
|
|
: provinces.filter((province) => province.name === provinceId)[0] |
|
|
|
|
?.id, |
|
|
|
|
cityId: |
|
|
|
|
typeof cityId === "number" |
|
|
|
|
? cityId |
|
|
|
|
: cities.filter((city) => city.name === cityId)[0]?.id, |
|
|
|
|
provinceId, |
|
|
|
|
cityId, |
|
|
|
|
postalCode, |
|
|
|
|
location: null, |
|
|
|
|
}); |
|
|
|
@ -290,8 +286,6 @@ export const Address = ({ |
|
|
|
|
); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const [activeCheckbox, setActiveCheckbox] = useState([false]); |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<div |
|
|
|
|
className={`flex flex-col lg:flex-row-reverse px-4 flex-1 lg:pt-0 pb-20 gap-5 lg:divide-x lg:divide-solid lg:divide-gray-200 ${ |
|
|
|
@ -384,7 +378,7 @@ export const Address = ({ |
|
|
|
|
</div> |
|
|
|
|
)} |
|
|
|
|
|
|
|
|
|
{activeCheckbox === false && !profilePage ? ( |
|
|
|
|
{profilePage || activeCheckbox === false ? ( |
|
|
|
|
<> |
|
|
|
|
<Header |
|
|
|
|
title="اطلاعات هویتی" |
|
|
|
@ -506,16 +500,13 @@ export const Address = ({ |
|
|
|
|
/> |
|
|
|
|
|
|
|
|
|
<div className="flex flex-col lg:flex-row items-center gap-3 lg:gap-5 w-full"> |
|
|
|
|
{console.log(city)} |
|
|
|
|
<Select |
|
|
|
|
options={province} |
|
|
|
|
options={provinces.map((e) => ({ value: e.id, name: e.name }))} |
|
|
|
|
name="provinceId" |
|
|
|
|
defaultValue={ |
|
|
|
|
profilePage |
|
|
|
|
? provinces?.filter( |
|
|
|
|
(province) => province?.id === profileFields.provinceId |
|
|
|
|
)[0]?.name || province[0] |
|
|
|
|
: city[0] |
|
|
|
|
? profileFields.provinceId || provinces[0]?.id |
|
|
|
|
: provinces[0]?.id |
|
|
|
|
} |
|
|
|
|
onChange={(name, value) => |
|
|
|
|
value === "استان" |
|
|
|
@ -533,14 +524,12 @@ export const Address = ({ |
|
|
|
|
{!cityLoading ? ( |
|
|
|
|
// <div>fdfds</div>
|
|
|
|
|
<Select |
|
|
|
|
options={city} |
|
|
|
|
options={cities.map((e) => ({ value: e.id, name: e.name }))} |
|
|
|
|
name="cityId" |
|
|
|
|
defaultValue={ |
|
|
|
|
profilePage |
|
|
|
|
? cities?.filter( |
|
|
|
|
(city) => city?.id === profileFields.cityId |
|
|
|
|
)[0]?.name || city[0] |
|
|
|
|
: city[0] |
|
|
|
|
? profileFields.cityId || cities[0]?.id |
|
|
|
|
: cities[0]?.id |
|
|
|
|
} |
|
|
|
|
onChange={(name, value) => |
|
|
|
|
value === "شهر" |
|
|
|
|