fixes seri 1

master
amir hosein gorji 3 years ago
parent 856d027bce
commit 4e66f2d8c9
  1. 22
      src/Redux/actions/file.js
  2. 1
      src/Redux/actions/index.js
  3. 4
      src/Redux/actions/public.js
  4. 38
      src/Redux/proxy.js
  5. 26
      src/Redux/reducers/file.js
  6. 1
      src/Redux/reducers/index.js
  7. 6
      src/Redux/reducers/public.js
  8. 15
      src/Redux/reducers/user.js
  9. 12
      src/constants/defaultValues.js
  10. 83
      src/views/Auth/Profile/Birthdate/index.js
  11. 5
      src/views/Auth/Profile/Birthdate/index.scss
  12. 32
      src/views/Auth/Profile/GenderSwitch/index.js
  13. 13
      src/views/Auth/Profile/Input/index.js
  14. 16
      src/views/Auth/Profile/MultipleSelector/index.js
  15. 10
      src/views/Auth/Profile/Select/index.js
  16. 4
      src/views/Auth/Profile/TextArea/index.js
  17. 84
      src/views/Auth/Profile/Upload/index.js
  18. 176
      src/views/Auth/Profile/index.js
  19. 7
      src/views/Auth/Profile/index.scss

@ -0,0 +1,22 @@
import proxy from "../proxy";
const file = {
upload:
(data = {}) =>
async (dispatch) => {
var formData = new FormData();
for (let key in data) formData.append(key, data[key]);
return await proxy.post(
"file/upload",
formData,
{
dispatch,
headers: {
"Content-Type": "multipart/form-data",
},
},
data
);
},
};
export default file;

@ -11,3 +11,4 @@ export { default as userFactor } from "./userFactor.js";
export { default as transport } from "./transport.js"; export { default as transport } from "./transport.js";
export { default as comment } from "./comment.js"; export { default as comment } from "./comment.js";
export { default as activation } from "./activation.js"; export { default as activation } from "./activation.js";
export { default as file } from "./file.js";

@ -20,6 +20,10 @@ const publicApi = {
await proxy.get("public/blogInfo", data, { history, dispatch }), await proxy.get("public/blogInfo", data, { history, dispatch }),
filterNewProducts: (data, history) => async (dispatch) => filterNewProducts: (data, history) => async (dispatch) =>
await dispatch({ type: "public/filter", data: data }), await dispatch({ type: "public/filter", data: data }),
getProvince: (data, history) => async (dispatch) =>
await proxy.get("public/province", data, { history, dispatch }),
getCity: (data, history) => async (dispatch) =>
await proxy.get("public/city", data, { history, dispatch }),
}; };
export default publicApi; export default publicApi;

@ -3,7 +3,9 @@ import axios from "axios";
let { baseUrl } = ApiConfig; let { baseUrl } = ApiConfig;
let access = window.localStorage.getItem("access"); let access = window.localStorage.getItem("access");
window.baseURL = baseUrl;
baseUrl = baseUrl + "/"; baseUrl = baseUrl + "/";
const Axios = axios.create({ const Axios = axios.create({
withCredentials: true, withCredentials: true,
validateStatus: null, validateStatus: null,
@ -11,41 +13,53 @@ const Axios = axios.create({
//headers: access ? { Authorization: `Bearer ${access}` } : {}, //headers: access ? { Authorization: `Bearer ${access}` } : {},
}); });
class Proxy { class Proxy {
get = async (url, params, opt = {}) => get = async (url, params, opt = {}, data) =>
await this.check(
url,
opt,
async () => await Axios.get(url, { params, ...opt }),
data || params
);
post = async (url, params, opt = {}, data) =>
await this.check(
url,
opt,
async () => await Axios.post(url, params, opt),
data || params
);
put = async (url, params, opt = {}, data) =>
await this.check( await this.check(
url, url,
opt, opt,
async () => await Axios.get(url, { params, ...opt }) async () => await Axios.put(url, params, opt),
data || params
); );
post = async (url, params, opt = {}) => delete = async (url, params, opt = {}, data) => {
await this.check(url, opt, async () => await Axios.post(url, params, opt));
put = async (url, params, opt = {}) =>
await this.check(url, opt, async () => await Axios.put(url, params, opt));
delete = async (url, params, opt = {}) => {
await this.check( await this.check(
url, url,
opt, opt,
async () => await Axios.delete(url, { ...opt, data: params }) async () => await Axios.delete(url, { ...opt, data: params }),
data || params
); );
}; };
check = async (url, { dispatch }, fetch) => { check = async (url, { dispatch }, fetch, params) => {
dispatch = dispatch || (() => {}); dispatch = dispatch || (() => {});
dispatch({ type: "loading" }); dispatch({ type: "loading" });
let response = await fetch(); let response = await fetch();
switch (response.status) { switch (response.status) {
case 200: case 200:
dispatch({ type: url, data: response.data.data }); dispatch({ type: url, data: response.data.data, params });
return response.data.data; return response.data.data;
case 401: case 401:
if (await this.refresh()) { if (await this.refresh()) {
let response = await fetch(); let response = await fetch();
dispatch({ type: url, data: response.data.data }); dispatch({ type: url, data: response.data.data, params });
return response.data.data; return response.data.data;
} }
break; break;
default: default:
dispatch({ type: "error", data: response.data }); dispatch({ type: "error", data: response.data, params });
} }
return false; return false;
}; };

@ -0,0 +1,26 @@
const initialState = {
loading: false,
error: null,
uploads: {},
lastUpload: null,
};
export default function file(state = initialState, action) {
let { type, data, params } = action;
switch (type) {
case "file/upload":
return {
...state,
loading: false,
error: null,
uploads: { ...state.uploads, [params?.target || "last"]: data.id },
lastUpload: data.id,
};
case "loading":
return { ...state, loading: true };
case "error":
return { ...state, loading: false, error: data.message };
default:
return state;
}
}

@ -11,3 +11,4 @@ export { default as userFactor } from "./userFactor.js";
export { default as transport } from "./transport.js"; export { default as transport } from "./transport.js";
export { default as comment } from "./comment.js"; export { default as comment } from "./comment.js";
export { default as activation } from "./activation.js"; export { default as activation } from "./activation.js";
export { default as file } from "./file.js";

@ -10,6 +10,8 @@ const initialState = {
arList: [], arList: [],
blogList: [], blogList: [],
blog: null, blog: null,
province: [],
city: [],
}; };
const grades = [ const grades = [
@ -130,6 +132,10 @@ export default function publicApi(state = initialState, action) {
}; };
case "faq/list": case "faq/list":
return { ...state, loading: false, error: null, faqList: data }; return { ...state, loading: false, error: null, faqList: data };
case "public/province":
return { ...state, loading: false, error: null, province: data };
case "public/city":
return { ...state, loading: false, error: null, city: data };
case "public/faq/activate": case "public/faq/activate":
return { return {
...state, ...state,

@ -8,6 +8,7 @@ const initialState = {
domains: [], domains: [],
mothers: [], mothers: [],
profileStatus: false, profileStatus: false,
setDone: false,
}; };
export default function user(state = initialState, action) { export default function user(state = initialState, action) {
let { type, data } = action; let { type, data } = action;
@ -28,7 +29,13 @@ export default function user(state = initialState, action) {
}; };
case "user/getProfile": case "user/getProfile":
localStorage.setItem("userData", JSON.stringify(data)); localStorage.setItem("userData", JSON.stringify(data));
return { ...state, loading: false, status: data, error: null }; return {
...state,
loading: false,
status: data,
error: null,
setDone: false,
};
case "user/logout": case "user/logout":
return { ...state, loading: false, status: proxy.status(), error: null }; return { ...state, loading: false, status: proxy.status(), error: null };
case "user/getUserRole": case "user/getUserRole":
@ -40,11 +47,7 @@ export default function user(state = initialState, action) {
case "mothers/list": case "mothers/list":
return { ...state, loading: false, mothers: data, error: null }; return { ...state, loading: false, mothers: data, error: null };
case "user/setProfile": case "user/setProfile":
toast.success("تغییرات اعمال شد."); return { ...state, loading: false, error: null, setDone: true };
setTimeout(() => {
window.location = "/";
}, 500);
return { ...state, loading: false, error: null };
case "loading": case "loading":
return { ...state, loading: true }; return { ...state, loading: true };
case "error": case "error":

@ -1,9 +1,9 @@
export const ApiConfig = { export const ApiConfig = {
apiKey: 'AIzaSyBBksq-Asxq2M4Ot-75X19IyrEYJqNBPcg', apiKey: "AIzaSyBBksq-Asxq2M4Ot-75X19IyrEYJqNBPcg",
authDomain: 'dnvn.ir', authDomain: "dnvn.ir",
baseUrl: 'https://dnvn.ir/api/v1', baseUrl: "https://dnvn.ir/api/v1/",
//baseUrl: 'http://localhost:3030/api/v1', //baseUrl: 'http://localhost:3030/api/v1',
loginURL: 'user/login', loginURL: "user/login",
otploginURL: 'user/otp/login', otploginURL: "user/otp/login",
logoutURL: 'user/logout', logoutURL: "user/logout",
}; };

@ -1,16 +1,26 @@
import React from "react"; import React, { useState } from "react";
import onInput from "~/util/onInput"; import onInput from "~/util/onInput";
import Input from "../Input/index";
import "./index.scss"; import "./index.scss";
import moment from "jalali-moment";
const maxMobileSize = 550;
const maxDesktopSize = 1250;
const fontSize = {
// desktop :
};
export default function Birthdate(props) { export default function Birthdate(props) {
const { defaultValue, parent, name } = props;
const momentDate = moment(defaultValue[name]);
const day = momentDate.format("jDD"),
month = momentDate.format("jMM"),
year = momentDate.format("jYYYY");
const [state, setState] = useState({ day, month, year });
const onChange = (_name, value) => {
let _state = { ...state, [_name]: value };
setState(_state);
parent.onChange(
name,
moment
.from(`${_state.year}/${_state.month}/${_state.day}`, "fa", "YYYY/M/D")
.locale("en")
);
};
return ( return (
<> <>
{window.innerWidth < 1000 ? ( {window.innerWidth < 1000 ? (
@ -18,24 +28,33 @@ export default function Birthdate(props) {
<label>تاریخ تولد</label> <label>تاریخ تولد</label>
<div className="mobile-birthdate__date d-flex align-items-center"> <div className="mobile-birthdate__date d-flex align-items-center">
<Input <Input
variant="standard"
name="day" name="day"
placeholder="روز" placeholder="روز"
maxLength={2} maxLength={2}
onInput={onInput.dayHandler} onInput={onInput.dayHandler}
parent={{ onChange }}
defaultValue={state}
/> />
<span>/</span> <span>/</span>
<Input <Input
variant="standard"
name="month" name="month"
placeholder="ماه" placeholder="ماه"
maxLength={2} maxLength={2}
onInput={onInput.monthHandler} onInput={onInput.monthHandler}
parent={{ onChange }}
defaultValue={state}
/> />
<span>/</span> <span>/</span>
<Input <Input
variant="standard"
name="year" name="year"
placeholder="سال" placeholder="سال"
maxLength={4} maxLength={4}
onInput={onInput.yearHandler} onInput={onInput.yearHandler}
parent={{ onChange }}
defaultValue={state}
/> />
</div> </div>
</div> </div>
@ -44,28 +63,38 @@ export default function Birthdate(props) {
<div className="birthdate d-flex justify-content-between align-items-center"> <div className="birthdate d-flex justify-content-between align-items-center">
<label>تاریخ تولد</label> <label>تاریخ تولد</label>
<div className="birthdate__date d-flex align-items-center"> <div className="birthdate__date d-flex align-items-center">
<Input name="day" placeholder="روز" maxLength={2} /> <Input
variant="standard"
name="day"
placeholder="روز"
maxLength={2}
onInput={onInput.dayHandler}
parent={{ onChange }}
defaultValue={state}
/>
<span>/</span> <span>/</span>
<Input name="month" placeholder="ماه" maxLength={2} /> <Input
variant="standard"
name="month"
placeholder="ماه"
maxLength={2}
onInput={onInput.monthHandler}
parent={{ onChange }}
defaultValue={state}
/>
<span>/</span> <span>/</span>
<Input name="year" placeholder="سال" maxLength={4} /> <Input
variant="standard"
name="year"
placeholder="سال"
maxLength={4}
onInput={onInput.yearHandler}
parent={{ onChange }}
defaultValue={state}
/>
</div> </div>
</div> </div>
) : null} ) : null}
</> </>
); );
} }
const Input = (props) => {
const { name, placeholder, maxLength, onInput } = props;
return (
<input
type="text"
inputMode="numeric"
name={name}
placeholder={placeholder}
maxLength={maxLength}
onInput={(e) => (e.target.value = onInput(e.target.value))}
/>
);
};

@ -12,13 +12,14 @@
span { span {
color: #bfbfbf; color: #bfbfbf;
} }
input { input {
border: 0px; border: 0px;
background-color: white; background-color: white;
font-family: numeralLight; font-family: numeralLight;
color: #4d4d4d; color: #4d4d4d;
width: 42px; width: 42px;
text-align: center; text-align: center !important;
direction: ltr; direction: ltr;
&:focus { &:focus {
outline: 0px; outline: 0px;
@ -73,7 +74,7 @@
font-family: numeralLight; font-family: numeralLight;
color: #4d4d4d; color: #4d4d4d;
width: 42px; width: 42px;
text-align: center; text-align: center !important;
direction: ltr; direction: ltr;
&:focus { &:focus {
outline: 0px; outline: 0px;

@ -14,17 +14,17 @@ export default function GenderSwitch(props) {
const styles = { const styles = {
girl: { girl: {
fontSize: window.innerWidth > 1000 ? fontSize.desktop : fontSize.mobile, fontSize: window.innerWidth > 1000 ? fontSize.desktop : fontSize.mobile,
color: selectedOption === options[1] ? "white" : "grey", color: selectedOption === 1 ? "white" : "grey",
backgroundColor: selectedOption === options[1] ? "#128c7e" : "white", backgroundColor: selectedOption === 1 ? "#128c7e" : "white",
border: selectedOption === options[1] ? "0px" : "1px solid #ccc", border: selectedOption === 1 ? "0px" : "1px solid #ccc",
borderTopLeftRadius: 10, borderTopLeftRadius: 10,
borderBottomLeftRadius: 10, borderBottomLeftRadius: 10,
}, },
boy: { boy: {
fontSize: window.innerWidth > 1000 ? fontSize.desktop : fontSize.mobile, fontSize: window.innerWidth > 1000 ? fontSize.desktop : fontSize.mobile,
color: selectedOption === options[0] ? "white" : "grey", color: selectedOption === 2 ? "white" : "grey",
backgroundColor: selectedOption === options[0] ? "#128c7e" : "white", backgroundColor: selectedOption === 2 ? "#128c7e" : "white",
border: selectedOption === options[0] ? "0px" : "1px solid #ccc", border: selectedOption === 2 ? "0px" : "1px solid #ccc",
borderTopRightRadius: 10, borderTopRightRadius: 10,
borderBottomRightRadius: 10, borderBottomRightRadius: 10,
borderLeft: window.innerWidth > 1000 ? "1px solid #ccc" : "0px", borderLeft: window.innerWidth > 1000 ? "1px solid #ccc" : "0px",
@ -34,32 +34,20 @@ export default function GenderSwitch(props) {
<> <>
{window.innerWidth > 1000 ? ( {window.innerWidth > 1000 ? (
<div className="gender d-flex justify-content-between align-items-center"> <div className="gender d-flex justify-content-between align-items-center">
<div <div style={styles.boy} onClick={() => parent.onChange(name, 2)}>
style={styles.boy}
onClick={() => parent.onChange(name, options[0])}
>
{options[0]} {options[0]}
</div> </div>
<div <div style={styles.girl} onClick={() => parent.onChange(name, 1)}>
style={styles.girl}
onClick={() => parent.onChange(name, options[1])}
>
{options[1]} {options[1]}
</div> </div>
</div> </div>
) : null} ) : null}
{window.innerWidth < 1000 ? ( {window.innerWidth < 1000 ? (
<div className="mobile-gender d-flex justify-content-between align-items-center"> <div className="mobile-gender d-flex justify-content-between align-items-center">
<div <div style={styles.boy} onClick={() => parent.onChange(name, 2)}>
style={styles.boy}
onClick={() => parent.onChange(name, options[0])}
>
{options[0]} {options[0]}
</div> </div>
<div <div style={styles.girl} onClick={() => parent.onChange(name, 1)}>
style={styles.girl}
onClick={() => parent.onChange(name, options[1])}
>
{options[1]} {options[1]}
</div> </div>
</div> </div>

@ -19,7 +19,8 @@ export default function FormPropsTextFields(props) {
})); }));
const classes = useStyles(); const classes = useStyles();
const { parent, defaultValue, maxLength, inputMode, onInput } = props; const { parent, defaultValue, maxLength, inputMode, onInput, variant } =
props;
return ( return (
<form className={classes.root} noValidate autoComplete="off"> <form className={classes.root} noValidate autoComplete="off">
<div> <div>
@ -27,11 +28,15 @@ export default function FormPropsTextFields(props) {
id="outlined-basic" id="outlined-basic"
name={props.name} name={props.name}
label={props.label} label={props.label}
variant="outlined" variant={variant || "outlined"}
onChange={(e) => parent.onChange(e.target.name, e.target.value)} onChange={(e) => parent.onChange(e.target.name, e.target.value)}
defaultValue={defaultValue[props.name] || ""} defaultValue={defaultValue[props.name] || ""}
maxLength={maxLength} inputProps={{ maxLength }}
onInput={(e) => (e.target.value = onInput(e.target.value))} onInput={
onInput
? (e) => (e.target.value = onInput(e.target.value))
: () => {}
}
/> />
</div> </div>
</form> </form>

@ -37,13 +37,13 @@ export default function MultipleSelector(props) {
labelId="demo-mutiple-name-label" labelId="demo-mutiple-name-label"
id="demo-mutiple-name" id="demo-mutiple-name"
multiple multiple
value={selectedOptions} value={selectedOptions.split(",")}
onChange={(e) => parent.onChange(name, e.target.value)} onChange={(e) => parent.onChange(name, e.target.value.join(","))}
input={<Input />} input={<Input />}
variant="outlined" variant="outlined"
> >
{options.map((name) => ( {options.map((name, i) => (
<MenuItem key={name} value={name}> <MenuItem key={name} value={i}>
{name} {name}
</MenuItem> </MenuItem>
))} ))}
@ -69,13 +69,13 @@ export default function MultipleSelector(props) {
labelId="demo-mutiple-name-label" labelId="demo-mutiple-name-label"
id="demo-mutiple-name" id="demo-mutiple-name"
multiple multiple
value={selectedOptions} value={selectedOptions.split(",")}
onChange={(e) => parent.onChange(name, e.target.value)} onChange={(e) => parent.onChange(name, e.target.value.join(","))}
input={<Input />} input={<Input />}
variant="outlined" variant="outlined"
> >
{options.map((name) => ( {options.map((name, i) => (
<MenuItem key={name} value={name}> <MenuItem key={name} value={i}>
{name} {name}
</MenuItem> </MenuItem>
))} ))}

@ -17,7 +17,7 @@ const useStyles = makeStyles((theme) => ({
export default function CustomizedSelects(props) { export default function CustomizedSelects(props) {
const classes = useStyles(); const classes = useStyles();
const { parent } = props; const { parent, selectedOptions } = props;
return ( return (
<> <>
{window.innerWidth < 1000 ? ( {window.innerWidth < 1000 ? (
@ -29,12 +29,12 @@ export default function CustomizedSelects(props) {
<Select <Select
labelId="demo-simple-select-outlined-label" labelId="demo-simple-select-outlined-label"
id="demo-simple-select-outlined" id="demo-simple-select-outlined"
// value={props.parent.state[props.name]} value={selectedOptions}
onChange={(e) => parent.onChange(props.name, e.target.value)} onChange={(e) => parent.onChange(props.name, e.target.value)}
> >
{/* 09366858119 */} {/* 09366858119 */}
{props.options.map((item, i) => ( {props.options.map((item, i) => (
<option key={i} value={item}> <option key={i} value={i}>
{item} {item}
</option> </option>
))} ))}
@ -60,12 +60,12 @@ export default function CustomizedSelects(props) {
<Select <Select
labelId="demo-simple-select-outlined-label" labelId="demo-simple-select-outlined-label"
id="demo-simple-select-outlined" id="demo-simple-select-outlined"
// value={props.parent.state[props.name]} value={selectedOptions}
onChange={(e) => parent.onChange(props.name, e.target.value)} onChange={(e) => parent.onChange(props.name, e.target.value)}
> >
{/* 09366858119 */} {/* 09366858119 */}
{props.options.map((item, i) => ( {props.options.map((item, i) => (
<option key={i} value={item}> <option key={i} value={i}>
{item} {item}
</option> </option>
))} ))}

@ -14,7 +14,7 @@ const useStyles = makeStyles((theme) => ({
export default function MultilineTextFields(props) { export default function MultilineTextFields(props) {
const classes = useStyles(); const classes = useStyles();
const [value, setValue] = React.useState("Controlled"); const [value, setValue] = React.useState("Controlled");
const { parent } = props; const { parent, defaultValue } = props;
return ( return (
<form className={classes.root} noValidate autoComplete="off"> <form className={classes.root} noValidate autoComplete="off">
<TextField <TextField
@ -23,8 +23,8 @@ export default function MultilineTextFields(props) {
multiline multiline
rows={4} rows={4}
onChange={(e) => parent.onChange(e.target.name, e.target.value)} onChange={(e) => parent.onChange(e.target.name, e.target.value)}
defaultValue={defaultValue[props.name] || ""}
name={props.name} name={props.name}
defaultValue=""
variant="outlined" variant="outlined"
/> />
</form> </form>

@ -11,49 +11,40 @@ const fontSize = {
}; };
export default function Upload(props) { export default function Upload(props) {
const { parent } = props; let { parent, name } = props;
return ( return (
<> <>
{window.innerWidth < 1000 ? ( {window.innerWidth < 1000 ? (
<div className="mobile-auth-profile__upload d-flex justify-content-center align-items-center mb-3"> <div className="mobile-auth-profile__upload d-flex justify-content-center align-items-center mb-3">
{parent.state.file === null ? ( <>
<> {parent.state.file === null ? (
<input
type="file"
name="file"
onChange={(e) =>
parent.onChange(e.target.name, e.target.files[0])
}
/>
<AddAPhotoIcon <AddAPhotoIcon
style={{ width: 40, height: 40, color: "white" }} style={{ width: 40, height: 40, color: "white" }}
/> />
</> ) : (
) : ( <img
<> src={
<input parent.state.file.name
type="file" ? URL.createObjectURL(parent.state.file)
name="file" : window.baseURL + "file/" + parent.state.file
onChange={(e) =>
parent.onChange(e.target.name, e.target.files[0])
} }
alt={"کاربر"}
/> />
{/* <img src={parent.state.file} alt={"کاربر"} /> */} )}
</> <input
)} type="file"
name="file"
onChange={(e) =>
parent.onChange(e.target.name, e.target.files[0])
}
/>
</>
</div> </div>
) : null} ) : null}
{window.innerWidth > 1000 ? ( {window.innerWidth > 1000 ? (
<div className="auth-profile__upload d-flex justify-content-center-align-items-center"> <div className="auth-profile__upload d-flex justify-content-center-align-items-center">
{parent.state.file === "" ? ( <>
<> {parent.state.file === null ? (
<input
label={props.label}
onChange={(e) => parent.onChange(e.target.name, e.target.value)}
name={props.name}
defaultValue=""
type="file"
/>
<AddAPhotoIcon <AddAPhotoIcon
style={{ style={{
width: 40, width: 40,
@ -64,21 +55,26 @@ export default function Upload(props) {
top: "calc(50% - 20px)", top: "calc(50% - 20px)",
}} }}
/> />
</> ) : (
) : ( <img
<> src={
<input parent.state.file.name
label={props.label} ? URL.createObjectURL(parent.state.file)
onChange={(e) => parent.onChange(e.target.name, e.target.value)} : window.baseURL + "file/" + parent.state.file
name={props.name} }
defaultValue="" alt={"کاربر"}
type="file"
/> />
<span style={{ color: "rgb(18,140,126)" }}> )}
{parent.state.file.name} <input
</span> label={props.label}
</> onChange={(e) =>
)} parent.onChange(e.target.name, e.target.files[0])
}
name={props.name}
defaultValue=""
type="file"
/>
</>
</div> </div>
) : null} ) : null}
</> </>

@ -1,6 +1,6 @@
import React, { Component } from "react"; import React, { Component } from "react";
import onInput from "~/util/onInput"; import onInput from "~/util/onInput";
import { user } from "~/Redux/actions"; import { user, file } from "~/Redux/actions";
import { connect } from "react-redux"; import { connect } from "react-redux";
import Select from "./Select/index"; import Select from "./Select/index";
@ -14,8 +14,12 @@ import Loader from "~/components/Loader/index";
import Document from "./Document/index"; import Document from "./Document/index";
import logo from "../../../assets/icons/logo.png"; import logo from "../../../assets/icons/logo.png";
import pic from "../../../assets/images/pic.png"; import pic from "../../../assets/images/pic.png";
import { useHistory } from "react-router-dom";
import "./index.scss"; import "./index.scss";
function Navigate({ path }) {
let history = useHistory();
return <>{history.push(path)}</>;
}
const maxDesktopSize = 1250; const maxDesktopSize = 1250;
const maxMobileSize = 550; const maxMobileSize = 550;
@ -40,7 +44,9 @@ const toastMessages = {
class Profile extends Component { class Profile extends Component {
state = { state = {
render: false, render: false,
file: null, file: this.props.uploads["file"] || this.props.profile.picFileId || null,
picFileId:
this.props.uploads["file"] || this.props.profile.picFileId || null,
docFileIds: "", docFileIds: "",
firstName: "", firstName: "",
lastName: "", lastName: "",
@ -48,8 +54,9 @@ class Profile extends Component {
username: "", username: "",
address: "", address: "",
email: "", email: "",
gender: "دختر", birthDate: "",
userRoleId: "دانش آموز", gender: this.props.profile.gender || 1,
status: this.props.profile.status || 1,
nationalId: "", nationalId: "",
provinceId: "", provinceId: "",
phone: "", phone: "",
@ -57,7 +64,8 @@ class Profile extends Component {
zoneId: "", zoneId: "",
schoolId: "", schoolId: "",
postalCode: "", postalCode: "",
gradeId: [], gradeIds: this.props.profile.gradeIds,
validation: { validation: {
firstName: "", firstName: "",
lastName: "", lastName: "",
@ -74,14 +82,19 @@ class Profile extends Component {
} }
onChange = (name, value) => { onChange = (name, value) => {
if (name === "gardeId" && this.state.userRoleId === "معلم") { // if (name === "gradeIds" && this.state.status == 2) {
// this.setState((prevState) => ({
// gradeIds: [...prevState.gradeIds.split(","), value],
// }));
// } else
if (name === "status") {
this.setState((prevState) => ({ this.setState((prevState) => ({
gradeId: [...prevState.gradeId, value], gradeIds: prevState.gradeIds.slice(0, 1) || [],
[name]: value,
})); }));
} } else if (name === "file") {
if (name === "userRoleId") { this.props.upload({ file: value, target: name });
this.setState({ this.setState({
gradeId: [],
[name]: value, [name]: value,
}); });
} else { } else {
@ -96,12 +109,19 @@ class Profile extends Component {
firstName, firstName,
lastName, lastName,
username, username,
cellphone, //cellphone,
password, password,
postalCode, postalCode,
address, address,
email, email,
phone, phone,
picFileId,
gender,
nationalId,
birthDate,
schools,
gradeIds,
status,
} = this.state; } = this.state;
const { profile, setProfile } = this.props; const { profile, setProfile } = this.props;
const data = { const data = {
@ -114,11 +134,21 @@ class Profile extends Component {
address: address || profile.address, address: address || profile.address,
email: email || profile.email, email: email || profile.email,
phone: phone || profile.phone, phone: phone || profile.phone,
nationalId: nationalId || profile.nationalId,
picFileId: String(
this.props.uploads["file"] || picFileId || profile.picFileId
),
gender: gender || profile.gender,
birthDate: birthDate || profile.birthDate,
schools: schools || profile.schools,
gradeIds: String(gradeIds || profile.gradeIds),
status: status || profile.status,
}; };
await setProfile(data); await setProfile(data);
}; };
render() { render() {
if (this.props.setDone) return <Navigate path="/" />;
const grades = [ const grades = [
"پیش دبستان", "پیش دبستان",
"اول", "اول",
@ -134,7 +164,7 @@ class Profile extends Component {
"یازدهم", "یازدهم",
"دوازدهم", "دوازدهم",
]; ];
const { user, profile } = this.props; const { profile } = this.props;
return ( return (
<> <>
{window.innerWidth > 1000 ? ( {window.innerWidth > 1000 ? (
@ -145,7 +175,7 @@ class Profile extends Component {
<p style={{ fontSize: fontSize.desktop.p }}> <p style={{ fontSize: fontSize.desktop.p }}>
لطفا مشخصات خود را به صورت کامل نمایید. لطفا مشخصات خود را به صورت کامل نمایید.
</p> </p>
<form <div
className="auth-profile__box--form d-flex" className="auth-profile__box--form d-flex"
onSubmit={(e) => this.onSubmit(e)} onSubmit={(e) => this.onSubmit(e)}
> >
@ -159,6 +189,7 @@ class Profile extends Component {
label="نام" label="نام"
parent={this} parent={this}
defaultValue={profile} defaultValue={profile}
onInput={onInput.persianOnly}
/> />
</div> </div>
<div className="mb-2"> <div className="mb-2">
@ -167,6 +198,7 @@ class Profile extends Component {
label="نام خانوادگی" label="نام خانوادگی"
parent={this} parent={this}
defaultValue={profile} defaultValue={profile}
onInput={onInput.persianOnly}
/> />
</div> </div>
<div className="mb-2"> <div className="mb-2">
@ -176,6 +208,7 @@ class Profile extends Component {
parent={this} parent={this}
defaultValue={profile} defaultValue={profile}
align="left" align="left"
onInput={onInput.englishAndNumberWithoutSpace}
/> />
</div> </div>
@ -190,14 +223,20 @@ class Profile extends Component {
<div className="mb-2"> <div className="mb-2">
<Input <Input
name="nationalId" name="nationalId"
label="کد ملی" label="کد ملی/اتباع"
parent={this} parent={this}
align="left" align="left"
maxLength={13}
defaultValue={profile} defaultValue={profile}
onInput={onInput.numberOnly}
/> />
</div> </div>
<div className="mb-2"> <div className="mb-2">
<Birthdate /> <Birthdate
defaultValue={profile}
parent={this}
name="birthDate"
/>
</div> </div>
{/* <div className="mb-2"> {/* <div className="mb-2">
<Input name="password" label="رمز عبور" parent={this} /> <Input name="password" label="رمز عبور" parent={this} />
@ -208,35 +247,36 @@ class Profile extends Component {
<Gender <Gender
parent={this} parent={this}
options={["معلم", "دانش آموز"]} options={["معلم", "دانش آموز"]}
name="userRoleId" name="status"
label={"عنوان"} label={"عنوان"}
selectedOption={this.state.userRoleId} selectedOption={this.state.status}
/> />
</div> </div>
{this.state.userRoleId === "دانش آموز" ? ( {this.state.status === 1 ? (
<div className="mb-2"> <div className="mb-2">
<Select <Select
parent={this} parent={this}
options={grades} options={grades}
name="gradeId" name="gradeIds"
label={"پایه تحصیلی"} label={"پایه تحصیلی"}
selectedOptions={this.state.gradeIds}
/> />
</div> </div>
) : null} ) : null}
{this.state.userRoleId === "معلم" ? ( {this.state.status === 2 ? (
<div className="mb-2"> <div className="mb-2">
<MultipleSelector <MultipleSelector
parent={this} parent={this}
options={grades} options={grades}
name="gradeId" name="gradeIds"
label={"پایه تحصیلی"} label={"پایه تحصیلی"}
selectedOptions={this.state.gradeId} selectedOptions={this.state.gradeIds}
/> />
</div> </div>
) : null} ) : null}
{this.state.userRoleId === "دانش آموز" && {this.state.status === "دانش آموز" &&
this.state.gradeId > 9 ? ( this.state.gradeIds > 9 ? (
<div className="mb-2"> <div className="mb-2">
<Select <Select
parent={this} parent={this}
@ -250,7 +290,7 @@ class Profile extends Component {
]} ]}
name="field" name="field"
label={"رشته تحصیلی"} label={"رشته تحصیلی"}
selectedOptions={this.state.gradeId} selectedOptions={this.state.gradeIds}
/> />
</div> </div>
) : null} ) : null}
@ -271,31 +311,33 @@ class Profile extends Component {
label={"شهرستان"} label={"شهرستان"}
/> />
</div> </div>
<div className="mb-2"> {/* <div className="mb-2">
<Select <Select
parent={this} parent={this}
options={["chaharbagh", "mahalat"]} options={["chaharbagh", "mahalat"]}
name="zoneId" name="zoneId"
label={"شهر/روستا"} label={"شهر/روستا"}
/> />
</div> </div> */}
{this.state.userRoleId === "دانش آموز" ? ( {this.state.status === "دانش آموز" ? (
<div className="mb-2"> <div className="mb-2">
<Input <Input
parent={this} parent={this}
name="schoolId" name="schools"
label={"نام مدرسه"} label={"نام مدرسه"}
defaultValue={profile} defaultValue={profile}
onInput={onInput.persianOnly}
/> />
</div> </div>
) : null} ) : null}
{this.state.userRoleId === "معلم" ? ( {this.state.status === "معلم" ? (
<div className="mb-2"> <div className="mb-2">
<Input <Input
parent={this} parent={this}
name="schoolId" name="schools"
label={"محل تدریس"} label={"محل تدریس"}
defaultValue={profile} defaultValue={profile}
onInput={onInput.persianOnly}
/> />
</div> </div>
) : null} ) : null}
@ -305,7 +347,10 @@ class Profile extends Component {
name="postalCode" name="postalCode"
label={"کد پستی"} label={"کد پستی"}
align="left" align="left"
maxLength={10}
inputMode="numeric"
defaultValue={profile} defaultValue={profile}
onInput={onInput.numberOnly}
/> />
</div> </div>
<div className="mb-2"> <div className="mb-2">
@ -313,13 +358,14 @@ class Profile extends Component {
parent={this} parent={this}
label={"آدرس محل سکونت"} label={"آدرس محل سکونت"}
name="address" name="address"
defaultValue={profile}
/> />
</div> </div>
<div className="auth-profile__box--form__footer d-flex justify-content-center"> <div className="auth-profile__box--form__footer d-flex justify-content-center">
<button>ذخیره</button> <button onClick={() => this.onSubmit()}>ذخیره</button>
</div> </div>
</div> </div>
</form> </div>
</div> </div>
</div> </div>
) : ( ) : (
@ -383,32 +429,37 @@ class Profile extends Component {
inputMode="numeric" inputMode="numeric"
onInput={onInput.numberOnly} onInput={onInput.numberOnly}
/> />
<Birthdate /> <Birthdate
defaultValue={profile}
parent={this}
name="birthDate"
/>
<Gender <Gender
parent={this} parent={this}
options={["معلم", "دانش آموز"]} options={["معلم", "دانش آموز"]}
name="userRoleId" name="status"
selectedOption={this.state.userRoleId} selectedOption={this.state.status}
/> />
{this.state.userRoleId === "دانش آموز" ? ( {this.state.status === 1 ? (
<Select <Select
parent={this} parent={this}
options={grades} options={grades}
name="gradeId" name="gradeIds"
label={"پایه تحصیلی"} label={"پایه تحصیلی"}
selectedOptions={this.state.gradeIds}
/> />
) : null} ) : null}
{this.state.userRoleId === "معلم" ? ( {this.state.status === 2 ? (
<MultipleSelector <MultipleSelector
parent={this} parent={this}
options={grades} options={grades}
name="gradeId" name="gradeIds"
label={"پایه تحصیلی"} label={"پایه تحصیلی"}
selectedOptions={this.state.gradeId} selectedOptions={this.state.gradeIds}
/> />
) : null} ) : null}
{this.state.userRoleId === "دانش آموز" && {this.state.status === "دانش آموز" &&
Number(this.state.gradeId) > 9 ? ( Number(this.state.gradeIds) > 9 ? (
<Select <Select
parent={this} parent={this}
options={[ options={[
@ -421,7 +472,7 @@ class Profile extends Component {
]} ]}
name="field" name="field"
label={"رشته تحصیلی"} label={"رشته تحصیلی"}
selectedOptions={this.state.gradeId} selectedOptions={this.state.gradeIds}
/> />
) : null} ) : null}
@ -437,31 +488,31 @@ class Profile extends Component {
name="cityId" name="cityId"
label={"شهرستان"} label={"شهرستان"}
/> />
<Select {/* <Select
parent={this} parent={this}
options={["chaharbagh", "mahalat"]} options={["chaharbagh", "mahalat"]}
name="zoneId" name="zoneId"
label={"شهر/روستا"} label={"شهر/روستا"}
/> /> */}
{this.state.userRoleId === "دانش آموز" ? ( {this.state.status === "دانش آموز" ? (
<Input <Input
parent={this} parent={this}
name="schoolId" name="schools"
label={"نام مدرسه"} label={"نام مدرسه"}
defaultValue={profile} defaultValue={profile}
onInput={onInput.persianOnly} onInput={onInput.persianOnly}
/> />
) : null} ) : null}
{this.state.userRoleId === "معلم" ? ( {this.state.status === "معلم" ? (
<Input <Input
parent={this} parent={this}
name="schoolId" name="schools"
label={"محل تدریس"} label={"محل تدریس"}
defaultValue={profile} defaultValue={profile}
onInput={onInput.persianOnly} onInput={onInput.persianOnly}
/> />
) : null} ) : null}
{this.state.userRoleId === "معلم" ? ( {this.state.status === "معلم" ? (
<Document parent={this} name="docFileIds" /> <Document parent={this} name="docFileIds" />
) : null} ) : null}
<Input <Input
@ -469,14 +520,20 @@ class Profile extends Component {
name="postalCode" name="postalCode"
label={"کد پستی"} label={"کد پستی"}
align="left" align="left"
maxLength={13} maxLength={10}
inputMode="numeric" inputMode="numeric"
defaultValue={profile} defaultValue={profile}
onInput={onInput.numberOnly} onInput={onInput.numberOnly}
/> />
<TextArea parent={this} label={"آدرس محل سکونت"} name="address" /> <TextArea
parent={this}
label={"آدرس محل سکونت"}
name="address"
defaultValue={profile}
defaultValue={profile}
/>
<div className="mobile-auth-profile__footer d-flex justify-content-center"> <div className="mobile-auth-profile__footer d-flex justify-content-center">
<button onClick={() => this.onSubmit()}>ذخیره</button> <button onClick={() => this.onSubmit()}>ذخیره</button>{" "}
</div> </div>
</div> </div>
) : ( ) : (
@ -496,9 +553,16 @@ class Profile extends Component {
export default connect( export default connect(
(state) => ({ (state) => ({
profile: state.user.status, profile: state.user.status,
setDone: state.user.setDone,
loading: state.user.loading, loading: state.user.loading,
uploading: state.file.loading,
uploads: state.file.uploads,
}), }),
{ getProfile: user.getProfile, setProfile: user.setProfile } {
getProfile: user.getProfile,
setProfile: user.setProfile,
upload: file.upload,
}
)(Profile); )(Profile);
Profile.defaultProps = { Profile.defaultProps = {

@ -1,3 +1,6 @@
.MuiOutlinedInput-input {
font-family: numeralLight !important;
}
.mobile-auth-profile { .mobile-auth-profile {
width: 100%; width: 100%;
height: 100%; height: 100%;
@ -43,6 +46,10 @@
img { img {
width: 100%; width: 100%;
height: 100%; height: 100%;
position: absolute;
left: -15px;
top: 0px;
object-fit: cover; object-fit: cover;
border-radius: 50%; border-radius: 50%;
} }

Loading…
Cancel
Save