From ea4f7bd23517a853b6603d891891f8757f11cb5a Mon Sep 17 00:00:00 2001 From: mahdi Date: Mon, 20 Jun 2022 15:28:04 +0430 Subject: [PATCH] updated | 30 --- src/components/Select/index.js | 15 ++++-- src/views/Address/index.js | 99 +++++++++++++++------------------- 2 files changed, 54 insertions(+), 60 deletions(-) diff --git a/src/components/Select/index.js b/src/components/Select/index.js index a251b81..fbe27e0 100644 --- a/src/components/Select/index.js +++ b/src/components/Select/index.js @@ -9,9 +9,10 @@ function Select({ backgroundColor, onChange, name, - defaultValue, - width = "w-1/2" + defaultValue, + width = "w-1/2", }) { + console.log({ options }); return (
{options.map((option, index) => ( - ))} @@ -44,5 +49,5 @@ export default Select; Select.defaultProps = { options: ["Really", "Option 2", "Option 3"], - borderColor : 'border-gray-300' + borderColor: "border-gray-300", }; diff --git a/src/views/Address/index.js b/src/views/Address/index.js index cc06376..2488a39 100644 --- a/src/views/Address/index.js +++ b/src/views/Address/index.js @@ -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 (
)} - {activeCheckbox === false && !profilePage ? ( + {profilePage || activeCheckbox === false ? ( <>
- {console.log(city)} ({ 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 === "شهر"