updated | 30

temp
mahdi 2 years ago
parent 654e2e2eb4
commit ea4f7bd235
  1. 15
      src/components/Select/index.js
  2. 99
      src/views/Address/index.js

@ -9,9 +9,10 @@ function Select({
backgroundColor, backgroundColor,
onChange, onChange,
name, name,
defaultValue, defaultValue,
width = "w-1/2" width = "w-1/2",
}) { }) {
console.log({ options });
return ( return (
<div <div
className={`inline-block ${width} relative group rounded-md overflow-hidden ${margin} bg-transparent`} className={`inline-block ${width} relative group rounded-md overflow-hidden ${margin} bg-transparent`}
@ -22,8 +23,12 @@ function Select({
defaultValue={defaultValue} defaultValue={defaultValue}
> >
{options.map((option, index) => ( {options.map((option, index) => (
<option key={index} className="text-sm lg:text-tiny"> <option
{option} key={index}
value={option.value || option}
className="text-sm lg:text-tiny"
>
{option.name || option}
</option> </option>
))} ))}
</select> </select>
@ -44,5 +49,5 @@ export default Select;
Select.defaultProps = { Select.defaultProps = {
options: ["Really", "Option 2", "Option 3"], options: ["Really", "Option 2", "Option 3"],
borderColor : 'border-gray-300' borderColor: "border-gray-300",
}; };

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

Loading…
Cancel
Save