);
}
+
+const mapStateToProps = (state) => ({
+ isDesktop: state.config.device === "desktop",
+});
+
+export default connect(mapStateToProps)(Birthdate);
diff --git a/src/views/Auth/Profile/Upload/index.js b/src/views/Auth/Profile/Upload/index.js
index f6e262c..64f3f62 100644
--- a/src/views/Auth/Profile/Upload/index.js
+++ b/src/views/Auth/Profile/Upload/index.js
@@ -1,27 +1,55 @@
-import React from "react";
+import React, { useState, useMemo } from "react";
+import { connect } from "react-redux";
+//assets
-export default function Upload({ name, value, onChange, label }) {
+const reader = new FileReader();
+function Upload({ name, value: initValue, onChange }) {
+ const [loaded, setSelected] = useState(null);
+ reader.onload = (e) => setSelected(e.target.result);
+ const value = loaded || initValue;
+ useMemo(() => {
+ setSelected(null);
+ }, [initValue]);
return (
-
- <>
- {value === null ? (
- <>>
- ) : (
-
- )}
-
onChange(e.target.name, e.target.files[0])}
+
+
+
-1
+ ? value
+ : "https://iranesch.com/api/v1/file/" + value
+ : "/icons/camera-white.svg"
+ }
+ alt=""
+ className={`rounded-full ${
+ value ? "w-full object-contain " : "w-2/5 object-contain"
+ } ${isNaN(value) ? "grayscale" : ""}`}
/>
- >
+
+ {value && (
+
+
+
+ )}
+
{
+ reader.readAsDataURL(e.target.files[0]);
+ onChange(e.target.name, e.target.files[0]);
+ }}
+ />
);
}
+
+const mapStateToProps = (state) => ({
+});
+
+export default connect(mapStateToProps)(Upload);
diff --git a/src/views/Auth/Profile/index.js b/src/views/Auth/Profile/index.js
index 036b16d..86b9908 100644
--- a/src/views/Auth/Profile/index.js
+++ b/src/views/Auth/Profile/index.js
@@ -3,10 +3,12 @@ import { useNavigate } from "react-router-dom";
import onInput from "../../../utils/onInput";
import { user, file, publicApi } from "../../../redux/actions";
import { connect } from "react-redux";
+import moment from "jalali-moment";
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";
@@ -17,52 +19,68 @@ function Profile({
isMobile,
profile,
uploads,
+ uploadId,
+ upload,
getProvince,
getCity,
setDone,
- upload,
setProfile,
province,
provinceList,
cityList,
setHeaderOptions,
+ loading,
}) {
let navigate = useNavigate();
- const [render, setRender] = useState(false);
- const [formData, setFormData] = useState({
- file: uploads["file"] || profile.picFileId || null,
- picFileId: uploads["file"] || profile.picFileId || null,
- docFileIds: uploads["docFileIds"] || profile.docFileIds || "",
- firstName: profile.firstName || "",
- lastName: profile.lastName || "",
- password: profile.password || "",
- username: profile.username || "",
- address: profile.address || "",
- email: profile.email || "",
- birthDate: profile.birthDate || "",
- 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,
- });
+ const [formData, setFormData] = useState(null);
+
+ useEffect(() => {
+ if (user) {
+ 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,
+ 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,
+ });
+ }
+ }, [user]);
useEffect(() => {
- setHeaderOptions({
- logo: true,
- hamburgerMenu: true,
- qr: true,
- title: false,
- back: false,
- shown: true,
- menu: false,
- });
+ if (!isMobile) {
+ setHeaderOptions({
+ logo: true,
+ hamburgerMenu: true,
+ qr: true,
+ title: false,
+ back: false,
+ shown: true,
+ menu: false,
+ });
+ }
+
getProvince();
getCity({ provinceId: profile.provinceId });
}, []);
@@ -135,7 +153,7 @@ function Profile({
} else if (name === "status") {
setFormData({
...formData,
- gradeIds: formData.gradeIds?.slice(0, 1) || [],
+ gradeIds: formData?.gradeIds?.slice(0, 1) || [],
[name]: value,
});
} else if (name === "docFileIds") {
@@ -208,7 +226,7 @@ function Profile({
@@ -219,7 +237,7 @@ function Profile({
@@ -230,9 +248,11 @@ function Profile({
label={window.t("نام")}
align="right"
onInput={onInput.persianOnly}
- defaultValue={formData}
- onChange={onChange}
- // ref={usernameInput}
+ value={formData?.firstName}
+ onChange={(name, value) =>
+ setFormData({ ...formData, [name]: value })
+ }
+ regex={(val) => val}
/>
@@ -240,27 +260,34 @@ function Profile({
name="lastName"
label={window.t("نام نام خانوادگی")}
align="right"
- defaultValue={formData}
- onChange={onChange}
+ value={formData?.lastName}
+ onChange={(name, value) =>
+ setFormData({ ...formData, [name]: value })
+ }
onInput={onInput.persianOnly}
+ regex={(val) => val}
/>
+ setFormData({ ...formData, [name]: value })
+ }
align="left"
- onInput={onInput.englishAndNumberWithoutSpace}
+ regex={(val) => onInput.englishAndNumberWithoutSpace(val)}
/>
+ setFormData({ ...formData, [name]: value })
+ }
label=""
/>
@@ -270,25 +297,32 @@ function Profile({
label={window.t("کد ملی/اتباع")}
align="left"
maxLength={13}
- defaultValue={formData}
- onChange={onChange}
- onInput={onInput.numberOnly}
+ value={formData?.nationalId}
+ onChange={(name, value) =>
+ setFormData({ ...formData, [name]: value })
+ }
+ regex={(val) => onInput.numberOnly(val)}
/>
+ setFormData({ ...formData, [name]: value })
+ }
+ value={formData?.birthDate}
/>
+ setFormData({ ...formData, [name]: value })
+ }
+ value={formData?.password}
align="left"
- onInput={onInput.englishAndNumberWithoutSpace}
+ regex={(val) => onInput.englishAndNumberWithoutSpace(val)}
/>
@@ -298,37 +332,41 @@ function Profile({
options={[window.t("معلم"), window.t("دانش آموز")]}
name="status"
label={window.t("عنوان")}
- selectedOption={formData.status}
+ selectedOption={formData?.status}
onChange={onChange}
/>