update src/views/Auth/Profile/Document/index.js, src/views/Auth/Profile/Document/index.scss, src/views/Auth/Profile/Upload/index.js and src/views/Auth/Profile/index.js

master
Reza_ashrafi 2 years ago
parent 82d7aec1df
commit 92e000e0d5
  1. 7
      src/views/Auth/Profile/Document/index.js
  2. 5
      src/views/Auth/Profile/Document/index.scss
  3. 2
      src/views/Auth/Profile/Upload/index.js
  4. 202
      src/views/Auth/Profile/index.js

@ -1,9 +1,10 @@
import React from "react";
import './index.scss';
export default function Document({ defaultValue, name, onChange }) {
export default function Document({ value, name, onChange }) {
return (
<div className="mobile-auth-profile__document d-flex justify-content-center align-items-center mb-3">
{defaultValue.docFileIds === "" ? (
<div className="mobile-auth-profile__document flex justify-center items-center mb-3">
{!value?.docFileIds ? (
<>
<input
type="file"

@ -4,7 +4,7 @@
width: 100%;
height: 50px;
border-radius: 10px;
border: 2px dashed $gray1;
border: 2px dashed #aaa;
position: relative;
input {
width: 100%;
@ -21,8 +21,7 @@
border-radius: 50%;
}
span {
color: #afafaf;
font-family: numeralLight;
color: #444;
}
}
}

@ -27,7 +27,7 @@ function Upload({ name, value: initValue, onChange }) {
value
? value?.indexOf("data") > -1
? value
: "https://iranesch.com/api/v1/file/" + value
: "https://dnvn.ir/api/v1/file/" + value
: camera
}
alt=""

@ -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`}
>

Loading…
Cancel
Save