import React from "react"; import Head from 'next/head'; import Image from 'next/image'; import Link from "next/link"; import cookie from 'cookie'; import { connect } from "react-redux"; import numeral from "numeral"; import { SpinnerCircular } from 'spinners-react'; import { withRouter } from 'next/router'; import { reduxWrapper } from '../../store'; import InnerMenu from "./components/InnerMenu"; import Header from '../components/Header'; import Footer from '../components/Footer'; import Pagination from '../components/Pagination'; import Company from "../components/Company"; import { sendNewPassword } from '../../actions'; class IndexPage extends React.Component { constructor(props) { super(props); this.state = { password_form_step: 1, password: "", password_error: false, new_password: "", new_password_repeat: "", new_password_check_loading: false, new_password_submit_disabled: true, new_password_error: false, user: {}, }; } static getDerivedStateFromProps(nextProps, prevState) { return { user: nextProps.user, }; } _handle_onPasswordSubmit = (event) => { event.preventDefault(); const { password, new_password, new_password_repeat, new_password_check_loading, user, } = this.state; if(!new_password_check_loading) { this.setState({ new_password_check_loading: true }, () => { sendNewPassword({ email: user.email, password, new_password, new_password_repeat, }) .then((response) => { if(response.status === "success") { this.setState({ new_password_error: false, new_password_check_loading: false, password_form_step: 2, }); } else { console.log(response.error); if(response.status === "error" && response.error === "wrong_email") { this.setState({ password_error: true, new_password_error: false, new_password_check_loading: false }); } } }) .catch(() => { this.setState({ new_password_error: true, new_password_check_loading: false }); }); }); } } _handle_onPasswordChange = (value) => { this.setState({ password: value, password_error: false, new_password_submit_disabled: this._check_fields_disabled([ value, this.state.new_password, this.state.new_password_repeat ]), }); } _handle_onNewPasswordChange = (value) => { let error = false; if(this.state.new_password_repeat.length > 0) { value === this.state.new_password ? false : true; error = value.length < 6 ? true : error; } this.setState({ new_password: value, new_password_submit_disabled: this._check_fields_disabled([ value, this.state.password, this.state.new_password_repeat ]), new_password_error: false }); } _handle_onNewPasswordRepeatChange = (value) => { let error = value === this.state.new_password ? false : true; error = value.length < 6 ? true : error; this.setState({ new_password_repeat: value, new_password_submit_disabled: error ? true : this._check_fields_disabled([ value, this.state.password, this.state.new_password ]), new_password_error: error }); } _check_fields_disabled = (values) => { for(let i in values) { if(values[i] === "") { return true; } } return false; } render() { console.log("this.state.user", this.state.user); const { password, password_error, new_password, new_password_repeat, new_password_submit_disabled, new_password_check_loading, new_password_error, password_form_step } = this.state; return ( ЛК Эволюция автолизинга

Смена пароля

{ password_form_step === 1 && (

Введите Ваш текущий пароль

this._handle_onPasswordChange(event.target.value) } />

{ password_error ? 'Ошибка: неверный пароль' : `\u00A0` }



Введите новый пароль и повторите новый пароль

this._handle_onNewPasswordChange(event.target.value) } />
this._handle_onNewPasswordRepeatChange(event.target.value) } />

{ new_password_error ? 'Внимание: пароли не совпадают' : `\u00A0` }

{ new_password.length < 6 ? 'Внимание: минимальная длина пароля - 6 символов' : `\u00A0` }

) } { password_form_step === 2 && (

Ваш пароль был успешно изменен.

) }