import React, { Component } from "react";
import onInput from "~/util/onInput";
import { user, file, publicApi } from "~/Redux/actions";
import { connect } from "react-redux";
import Select from "./Select/index";
import Input from "./Input/index";
import TextArea from "./TextArea/index";
import Upload from "./Upload/index";
import Gender from "./GenderSwitch/index";
import Birthdate from "./Birthdate/index";
import MultipleSelector from "./MultipleSelector/index";
import Loader from "~/components/Loader/index";
import Document from "./Document/index";
import pic from "../../../assets/images/pic.png";
import "./index.scss";
import { useHistory } from "react-router-dom";
import Navbar from "../../Home/Navbar/index";
function Navigate({ path }) {
let history = useHistory();
return <>{history.push(path)}>;
}
const maxDesktopSize = 1250;
const maxMobileSize = 550;
const fontSize = {
desktop: {
h1: window.innerWidth > maxDesktopSize ? 25 : window.innerWidth / 55,
p: window.innerWidth > maxDesktopSize ? 14 : window.innerWidth / 90,
},
mobile: {
h1: window.innerWidth > maxMobileSize ? 20 : window.innerWidth / 18,
p: window.innerWidth > maxMobileSize ? 14 : window.innerWidth / 28,
},
};
class Profile extends Component {
state = {
render: false,
file: this.props.uploads["file"] || this.props.profile.picFileId || null,
picFileId:
this.props.uploads["file"] || this.props.profile.picFileId || null,
docFileIds:
this.props.uploads["docFileIds"] || this.props.profile.docFileIds || "",
firstName: "",
lastName: "",
password: "",
username: "",
address: "",
email: "",
birthDate: "",
gender: this.props.profile.gender || 1,
status: this.props.profile.status || 1,
nationalId: "",
phone: "",
zoneId: "",
schoolId: "",
postalCode: "",
gradeIds: this.props.profile.gradeIds,
provinceId: this.props.profile.provinceId,
cityId: this.props.profile.cityId,
validation: {
firstName: "",
lastName: "",
username: "",
email: "",
postalCode: "",
nationalId: "",
schoolId: "",
},
};
componentDidMount() {
this.props.getProvince();
this.props.getCity({ provinceId: this.props.profile.provinceId });
// this.props.getProfile();
}
onChange = (name, value) => {
if (name === "provinceId") {
this.props.getCity({ provinceId: value });
this.setState({
cityId: null,
[name]: value,
});
} else if (name === "status") {
this.setState((prevState) => ({
gradeIds: String(prevState?.gradeIds || "").slice(0, 1) || "",
[name]: value,
}));
} else if (name === "docFileIds") {
this.props.upload({ file: value, target: name });
this.setState({
[name]: value,
});
} else if (name === "file") {
this.props.upload({ file: value, target: name });
this.setState({
[name]: value,
});
} else {
this.setState({
[name]: value,
});
}
};
onSubmit = async (e) => {
const {
firstName,
lastName,
username,
//cellphone,
password,
postalCode,
address,
email,
phone,
picFileId,
gender,
nationalId,
birthDate,
schools,
gradeIds,
status,
provinceId,
cityId,
docFileIds,
} = this.state;
const { profile, setProfile } = this.props;
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: 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,
provinceId: provinceId || profile.provinceId,
cityId: cityId || profile.cityId,
docFileIds: String(
this.props.uploads["docFileIds"] || docFileIds || profile.docFileIds
),
};
await setProfile(data);
};
render() {
if (this.props.setDone) return
{window.t("لطفا مشخصات خود را به صورت کامل نمایید.")}
{window.t("لطفا مشخصات خود را به صورت کامل وارد نمایید")}{" "}