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)}