|
|
|
@ -5,10 +5,10 @@ import { user, file, publicApi } from "../../../redux/actions"; |
|
|
|
|
import { connect } from "react-redux"; |
|
|
|
|
import moment from "jalali-moment"; |
|
|
|
|
|
|
|
|
|
//components
|
|
|
|
|
import Select from "../../../components/Select"; |
|
|
|
|
import Input from "../../../components/Input"; |
|
|
|
|
import TextArea from "../../../components/Textarea"; |
|
|
|
|
import Button from "../../../components/Button"; |
|
|
|
|
import Upload from "./Upload"; |
|
|
|
|
import Gender from "./GenderSwitch"; |
|
|
|
|
import Birthdate from "./Birthdate"; |
|
|
|
@ -40,47 +40,43 @@ function Profile({ |
|
|
|
|
const momentDate = moment(profile?.birthDate); |
|
|
|
|
const isValid = momentDate.isValid(); |
|
|
|
|
setFormData({ |
|
|
|
|
file: uploads["file"] || profile.picFileId, |
|
|
|
|
picFileId: uploads["file"] || profile.picFileId, |
|
|
|
|
docFileIds: uploads["docFileIds"] || profile.docFileIds, |
|
|
|
|
firstName: profile.firstName, |
|
|
|
|
lastName: profile.lastName, |
|
|
|
|
password: profile.password, |
|
|
|
|
username: profile.username, |
|
|
|
|
address: profile.address, |
|
|
|
|
email: profile.email, |
|
|
|
|
// file: uploads["file"] || profile.picFileId,
|
|
|
|
|
picFileId: uploads["file"] || profile?.picFileId, |
|
|
|
|
docFileIds: uploads["docFileIds"] || profile?.docFileIds, |
|
|
|
|
firstName: profile?.firstName, |
|
|
|
|
lastName: profile?.lastName, |
|
|
|
|
password: profile?.password, |
|
|
|
|
username: profile?.username, |
|
|
|
|
address: profile?.address, |
|
|
|
|
email: profile?.email, |
|
|
|
|
birthDate: { |
|
|
|
|
day: isValid ? moment(profile?.birthDate).format("jDD") : null, |
|
|
|
|
month: isValid ? moment(profile?.birthDate).format("jMM") : null, |
|
|
|
|
year: isValid ? moment(profile?.birthDate).format("jYYYY") : null, |
|
|
|
|
}, |
|
|
|
|
gender: profile.gender || 1, |
|
|
|
|
status: profile.status || 1, |
|
|
|
|
nationalId: profile.nationalId || "", |
|
|
|
|
phone: profile.phone || "", |
|
|
|
|
schools: profile.schools || null, |
|
|
|
|
zoneId: profile.zoneId || "", |
|
|
|
|
schoolId: profile.schoolId || "", |
|
|
|
|
postalCode: profile.postalCode || "", |
|
|
|
|
gradeIds: profile.gradeIds || [], |
|
|
|
|
provinceId: profile.provinceId || null, |
|
|
|
|
cityId: profile.cityId || null, |
|
|
|
|
gender: profile?.gender || 1, |
|
|
|
|
status: profile?.status || 1, |
|
|
|
|
nationalId: profile?.nationalId || "", |
|
|
|
|
phone: profile?.phone || "", |
|
|
|
|
cellphone: profile?.cellphone || "", |
|
|
|
|
schools: profile?.schools || null, |
|
|
|
|
zoneId: profile?.zoneId || "", |
|
|
|
|
schoolId: profile?.schoolId || "", |
|
|
|
|
postalCode: profile?.postalCode || "", |
|
|
|
|
gradeIds: profile?.gradeIds || [], |
|
|
|
|
provinceId: profile?.provinceId || null, |
|
|
|
|
cityId: profile?.cityId || null, |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}, [user]); |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
setHeaderOptions(headerOptions); |
|
|
|
|
if(isMobile){ |
|
|
|
|
setHeaderOptions(headerOptions); |
|
|
|
|
} |
|
|
|
|
getProvince(); |
|
|
|
|
getCity({ provinceId: profile.provinceId }); |
|
|
|
|
}, []); |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
if (setDone) { |
|
|
|
|
navigate("/"); |
|
|
|
|
} |
|
|
|
|
}, [setDone]); |
|
|
|
|
|
|
|
|
|
const grades = [ |
|
|
|
|
{ |
|
|
|
|
name: window.t("پیش دبستانی"), |
|
|
|
@ -136,77 +132,41 @@ function Profile({ |
|
|
|
|
}, |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
const onChange = (name, value) => { |
|
|
|
|
if (name === "provinceId") { |
|
|
|
|
getCity({ provinceId: value }); |
|
|
|
|
setFormData({ ...formData, cityId: null, [name]: value }); |
|
|
|
|
} else if (name === "status") { |
|
|
|
|
setFormData({ |
|
|
|
|
...formData, |
|
|
|
|
gradeIds: formData?.gradeIds?.slice(0, 1) || [], |
|
|
|
|
[name]: value, |
|
|
|
|
}); |
|
|
|
|
} else if (name === "docFileIds") { |
|
|
|
|
upload({ file: value, target: name }); |
|
|
|
|
setFormData({ ...formData, [name]: value }); |
|
|
|
|
} else if (name === "file") { |
|
|
|
|
upload({ file: value, target: name }); |
|
|
|
|
setFormData({ ...formData, [name]: value }); |
|
|
|
|
} else { |
|
|
|
|
setFormData({ ...formData, [name]: value }); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const onSubmit = async () => { |
|
|
|
|
const { |
|
|
|
|
firstName, |
|
|
|
|
lastName, |
|
|
|
|
username, |
|
|
|
|
//cellphone,
|
|
|
|
|
password, |
|
|
|
|
postalCode, |
|
|
|
|
address, |
|
|
|
|
email, |
|
|
|
|
phone, |
|
|
|
|
picFileId, |
|
|
|
|
gender, |
|
|
|
|
nationalId, |
|
|
|
|
birthDate, |
|
|
|
|
schools, |
|
|
|
|
gradeIds, |
|
|
|
|
status, |
|
|
|
|
provinceId, |
|
|
|
|
cityId, |
|
|
|
|
docFileIds, |
|
|
|
|
} = formData; |
|
|
|
|
const onSubmit = React.useCallback(async () => { |
|
|
|
|
const data = { |
|
|
|
|
firstName: firstName || profile.firstName, |
|
|
|
|
lastName: lastName || profile.lastName, |
|
|
|
|
username: username || profile.username, |
|
|
|
|
cellphone: profile.cellphone, |
|
|
|
|
password: password || profile.password, |
|
|
|
|
postalCode: postalCode || profile.postalCode, |
|
|
|
|
address: address || profile.address, |
|
|
|
|
email: email || profile.email, |
|
|
|
|
phone: phone || profile.phone, |
|
|
|
|
nationalId: nationalId || profile.nationalId, |
|
|
|
|
picFileId: uploads["file"] || picFileId || profile.picFileId, |
|
|
|
|
gender: gender || profile.gender, |
|
|
|
|
birthDate: birthDate || profile.birthDate, |
|
|
|
|
schools: schools || profile.schools, |
|
|
|
|
gradeIds: gradeIds || profile.gradeIds, |
|
|
|
|
status: status || profile.status, |
|
|
|
|
provinceId: provinceId || profile.provinceId, |
|
|
|
|
cityId: cityId || profile.cityId, |
|
|
|
|
docFileIds: uploads["docFileIds"] || docFileIds || profile.docFileIds, |
|
|
|
|
firstName: formData?.firstName, |
|
|
|
|
lastName: formData?.lastName, |
|
|
|
|
username: formData?.username, |
|
|
|
|
cellphone: formData?.cellphone, |
|
|
|
|
password: formData?.password, |
|
|
|
|
postalCode: formData?.postalCode, |
|
|
|
|
address: formData?.address, |
|
|
|
|
email: formData?.email, |
|
|
|
|
phone: formData?.phone, |
|
|
|
|
cellphone: formData?.cellphone, |
|
|
|
|
nationalId: formData?.nationalId, |
|
|
|
|
picFileId: uploads["picFileId"] || formData?.picFileId, |
|
|
|
|
birthDate: moment |
|
|
|
|
.from( |
|
|
|
|
`${formData?.birthDate?.year}/${formData?.birthDate?.month}/${formData?.birthDate?.day}`, |
|
|
|
|
"fa", |
|
|
|
|
"YYYY/MM/DD" |
|
|
|
|
) |
|
|
|
|
.locale("en"), |
|
|
|
|
gender: formData?.gender, |
|
|
|
|
schools: formData?.schools, |
|
|
|
|
gradeIds: formData?.gradeIds, |
|
|
|
|
status: formData?.status, |
|
|
|
|
provinceId: formData?.provinceId, |
|
|
|
|
cityId: formData?.cityId, |
|
|
|
|
docFileIds: uploads["docFileIds"] || formData?.docFileIds, |
|
|
|
|
}; |
|
|
|
|
await setProfile(data); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// if (setDone) return <Navigate path="/" />;
|
|
|
|
|
await setProfile(data); |
|
|
|
|
}, [formData, uploads]); |
|
|
|
|
|
|
|
|
|
return isMobile ? ( |
|
|
|
|
<div className="flex flex-col gap-6 lg:hidden px-4 pb-20"> |
|
|
|
|
<div className="lg:hidden flex flex-col gap-6 px-4 pb-20"> |
|
|
|
|
<header className="flex flex-col gap-2 w-full"> |
|
|
|
|
<h1 className="text-base text-gray1">{window.t("حساب کاربری")}</h1> |
|
|
|
|
<p className="text-sm text-gray1"> |
|
|
|
@ -218,9 +178,14 @@ function Profile({ |
|
|
|
|
onSubmit={(e) => e.preventDefault()} |
|
|
|
|
> |
|
|
|
|
<Upload |
|
|
|
|
name="file" |
|
|
|
|
value={formData?.file} |
|
|
|
|
onChange={onChange} |
|
|
|
|
name="picFileId" |
|
|
|
|
value={String( |
|
|
|
|
uploads["picFileId"] || uploadId || formData?.picFileId |
|
|
|
|
)} |
|
|
|
|
onChange={(name, value) => { |
|
|
|
|
upload({ file: value, target: name }); |
|
|
|
|
setFormData({ ...formData, [name]: value }); |
|
|
|
|
}} |
|
|
|
|
label={window.t("فایل")} |
|
|
|
|
/> |
|
|
|
|
<Input |
|
|
|
@ -293,11 +258,17 @@ function Profile({ |
|
|
|
|
regex={(val) => onInput.englishAndNumberWithoutSpace(val)} |
|
|
|
|
/> |
|
|
|
|
<Gender |
|
|
|
|
options={[window.t("معلم"), window.t("دانش آموز")]} |
|
|
|
|
options={[window.t("دانش آموز"), window.t("معلم")]} |
|
|
|
|
name="status" |
|
|
|
|
label={window.t("عنوان")} |
|
|
|
|
selectedOption={formData?.status} |
|
|
|
|
onChange={onChange} |
|
|
|
|
onChange={(name, value) => { |
|
|
|
|
setFormData({ |
|
|
|
|
...formData, |
|
|
|
|
gradeIds: formData?.gradeIds?.slice(0, 1) || [], |
|
|
|
|
[name]: value, |
|
|
|
|
}); |
|
|
|
|
}} |
|
|
|
|
/> |
|
|
|
|
{formData?.status === 1 ? ( |
|
|
|
|
<Select |
|
|
|
@ -348,9 +319,10 @@ function Profile({ |
|
|
|
|
name="provinceId" |
|
|
|
|
label={window.t("استان")} |
|
|
|
|
selectedOptions={formData?.provinceId} |
|
|
|
|
onChange={(name, value) => |
|
|
|
|
setFormData({ ...formData, [name]: value }) |
|
|
|
|
} |
|
|
|
|
onChange={(name, value) => { |
|
|
|
|
setFormData({ ...formData, cityId: null, [name]: value }); |
|
|
|
|
getCity({ provinceId: provinceList.find((province) => province.name === value)?.id }); |
|
|
|
|
}} |
|
|
|
|
/> |
|
|
|
|
<Select |
|
|
|
|
options={cityList} |
|
|
|
@ -378,23 +350,28 @@ function Profile({ |
|
|
|
|
label={window.t("محل تدریس")} |
|
|
|
|
defaultValue={formData} |
|
|
|
|
regex={(val) => onInput.persianOnly(val)} |
|
|
|
|
onChange={onChange} |
|
|
|
|
onChange={(name, value) => |
|
|
|
|
setFormData({ ...formData, [name]: value }) |
|
|
|
|
} |
|
|
|
|
/> |
|
|
|
|
) : null} |
|
|
|
|
{formData?.status == 2 ? ( |
|
|
|
|
<Document |
|
|
|
|
onChange={(name, value) => |
|
|
|
|
setFormData({ ...formData, [name]: value }) |
|
|
|
|
} |
|
|
|
|
value={formData?.docFileIds} |
|
|
|
|
onChange={(name, value) => { |
|
|
|
|
upload({ file: value, target: name }); |
|
|
|
|
setFormData({ ...formData, [name]: value }); |
|
|
|
|
}} |
|
|
|
|
value={String(uploads["docFileIds"] || formData?.docFileIds)} |
|
|
|
|
name="docFileIds" |
|
|
|
|
/> |
|
|
|
|
) : null} |
|
|
|
|
<Input |
|
|
|
|
name="postalCode" |
|
|
|
|
placeholder={window.t("کد پستی")} |
|
|
|
|
label={window.t("کد پستی")} |
|
|
|
|
align="left" |
|
|
|
|
onChange={onChange} |
|
|
|
|
onChange={(name, value) => |
|
|
|
|
setFormData({ ...formData, [name]: value }) |
|
|
|
|
} |
|
|
|
|
maxLength={10} |
|
|
|
|
inputMode="numeric" |
|
|
|
|
value={formData?.postalCode} |
|
|
|
@ -418,16 +395,15 @@ function Profile({ |
|
|
|
|
</div> |
|
|
|
|
) : ( |
|
|
|
|
<div |
|
|
|
|
className="flex flex-col items-center gap-5 w-full pt-5 select-none" |
|
|
|
|
className="hidden lg:flex flex-col items-center gap-5 w-full pt-5 select-none" |
|
|
|
|
onSubmit={(e) => onSubmit()} |
|
|
|
|
> |
|
|
|
|
<Upload |
|
|
|
|
name="file" |
|
|
|
|
value={String(uploadId || formData?.picFileId)} |
|
|
|
|
onChange={onChange} |
|
|
|
|
onChange={(name, value) => setFormData({ ...formData, [name]: value })} |
|
|
|
|
label="فایل" |
|
|
|
|
/> |
|
|
|
|
<br /> |
|
|
|
|
<div |
|
|
|
|
className={`w-full gap-5 lg:flex lg:flex-row lg:my-2 lg:items-center flex flex-col`} |
|
|
|
|
> |
|
|
|
|