From f5ba1596b0a4c4f0fda3cc0cf7b27e9a9d1bfb77 Mon Sep 17 00:00:00 2001 From: Reza_ashrafi Date: Mon, 11 Jul 2022 18:47:42 +0430 Subject: [PATCH] update 13 files --- src/components/Navbar/index.js | 2 - src/components/Select/index.js | 1 - src/components/StarRating/index.js | 1 - src/views/Address/index.js | 4 - src/views/Auth/Profile/Birthdate/index.js | 119 +++++--- src/views/Auth/Profile/Upload/index.js | 70 +++-- src/views/Auth/Profile/index.js | 331 +++++++++++++++------- src/views/Dashboard/layouts/Main/index.js | 7 +- src/views/Home/Portrait/Private/index.js | 1 - src/views/ShoppingCart/index.js | 3 +- 10 files changed, 358 insertions(+), 181 deletions(-) diff --git a/src/components/Navbar/index.js b/src/components/Navbar/index.js index 4e932f5..6132096 100644 --- a/src/components/Navbar/index.js +++ b/src/components/Navbar/index.js @@ -61,8 +61,6 @@ function Navbar({ ); }, [headerOptions, userFavoriteList]); - console.log(Boolean(isActiveBookmark)); - useEffect(() => { if (window.scrollY === 0) { setTop(() => true); diff --git a/src/components/Select/index.js b/src/components/Select/index.js index 19fd511..ed1c5c6 100644 --- a/src/components/Select/index.js +++ b/src/components/Select/index.js @@ -13,7 +13,6 @@ function Select({ width = "w-1/2", selectProvince, }) { - console.log({ options }); return (
{ - //console.log("gl2"); // if (isLogin && !userProducts.length) getUserProducts(); }, []); diff --git a/src/views/Address/index.js b/src/views/Address/index.js index c6ed856..9f9d66c 100644 --- a/src/views/Address/index.js +++ b/src/views/Address/index.js @@ -48,7 +48,6 @@ export const Address = ({ const [addressFields, setAddressFields] = useState({}); const [mapAddress, setMapAddress] = useState(null); const navigation = useNavigate(); - console.log({ provinces }); useEffect(() => { setHeaderOptions(headerOptions); if (province.length <= 1) { @@ -98,7 +97,6 @@ export const Address = ({ useEffect(() => { if (addressFields?.provinceId) { - console.log({ addressFields }); getCity({ provinceId: addressFields?.provinceId, }); @@ -114,7 +112,6 @@ export const Address = ({ }, [profileFields]); const onChange = (name, value) => { - console.log({ name, value }); setAddressFields({ ...addressFields, [name]: value }); }; @@ -296,7 +293,6 @@ export const Address = ({
); }; - console.log({ state: location?.state }); return (
{ - let _state = { ...state, [_name]: value }; - setState(_state); - - props.onChange( - name, - moment - .from(`${_state.year}/${_state.month}/${_state.day}`, "fa", "YYYY/M/D") - .locale("en") - ); - }; return ( -
- -
- + {isDesktop && ( + + )} + +
+ setIsFocused(true)} + onBlur={() => setIsFocused(false)} + onChange={(e) => + onChange(name, { + ...value, + day: onInput.dayHandler(e.target.value), + }) + } + placeholder="روز" + maxLength="2" + value={value?.day} /> - / - / + setIsFocused(true)} + onBlur={() => setIsFocused(false)} + onChange={(e) => + onChange(name, { + ...value, + month: onInput.monthHandler(e.target.value), + }) + } + placeholder="ماه" + maxLength="2" + value={value?.month} /> - / - / + setIsFocused(true)} + onBlur={() => setIsFocused(false)} + onChange={(e) => + onChange(name, { + ...value, + year: onInput.yearHandler(e.target.value), + }) + } + placeholder="سال" + maxLength="4" + value={value?.year} />
); } + +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 ? ( - <> - ) : ( - {window.t("کاربر")} - )} - 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 && ( +
+ camera +
+ )} + { + 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} />
- {formData.status === 1 ? ( + {formData?.status === 1 ? (
+ setFormData({ ...formData, [name]: value }) + } />
) : null} @@ -351,8 +391,10 @@ function Profile({ options={provinceList} name="provinceId" label={window.t("استان")} - selectedOptions={formData.provinceId} - onChange={onChange} + selectedOptions={formData?.provinceId} + onChange={(name, value) => + setFormData({ ...formData, [name]: value }) + } />
@@ -360,36 +402,42 @@ function Profile({ options={cityList} name="cityId" label={window.t("شهرستان")} - selectedOptions={formData.cityId} - onChange={onChange} + selectedOptions={formData?.cityId} + onChange={(name, value) => + setFormData({ ...formData, [name]: value }) + } />
- {formData.status == 1 ? ( + {formData?.status == 1 ? (
onInput.persianOnly(val)} + onChange={(name, value) => + setFormData({ ...formData, [name]: value }) + } />
) : null} - {formData.status == 2 ? ( + {formData?.status == 2 ? (
onInput.persianOnly(val)} onChange={onChange} />
) : null} - {formData.status == 2 ? ( + {formData?.status == 2 ? ( + setFormData({ ...formData, [name]: value }) + } + value={formData?.docFileIds} name="docFileIds" /> ) : null} @@ -401,16 +449,18 @@ function Profile({ onChange={onChange} maxLength={10} inputMode="numeric" - defaultValue={formData} - onInput={onInput.numberOnly} + value={formData?.postalCode} + regex={(val) => onInput.numberOnly(val)} />