import React from "react"; import Head from 'next/head'; import Link from "next/link"; import Image from 'next/image'; import { connect } from "react-redux"; import { withRouter } from 'next/router'; import { reduxWrapper } from '../store'; import pluralize from 'pluralize-ru'; import { SpinnerCircular } from 'spinners-react'; import Header from './components/Header'; import Footer from './components/Footer'; import MainHeader from "./components/MainHeader"; import FormRequest from "./components/FormRequest"; import { sendEmailCheck, sendEmailCode, sendPassword } from "../actions/recoveryActions"; export default class RecoveryPage extends React.Component { constructor(props) { super(props); this.state = { email: "", email_code: "", password: "", password_repeat: "", tab: "email", email_error: false, recovery_form_step: 1, email_code_error: false, email_send_disabled: true, set_password_disabled: true, email_code_submit_disabled: true, email_code_resend_disabled: true, timer: 0, email_auth_loading: false, email_check_loading: false, code_check_loading: false, password_check_loading: false, password_submit_disabled: true, password_error: false, }; this.timer_ref = null; } _handle_onEmailSubmit = (event) => { event.preventDefault(); const { email, email_check_loading } = this.state; if(!email_check_loading) { this.setState({ email_check_loading: true }, () => { sendEmailCheck({ email }) .then(() => { this.setState({ email_check_loading: false, email_error: false, timer: 60, recovery_form_step: 2, }, () => { this.timer_ref = setInterval(() => { const t = this.state.timer - 1; this.setState({ timer: t, }, () => { if(t === 0) { clearInterval(this.timer_ref); } }); }, 1000); }); }) .catch(() => { this.setState({ email_error: true, email_check_loading: false }); }); }); } } _handle_onCodeSubmit = (event) => { event.preventDefault(); const { email, email_code, code_check_loading } = this.state; if(!code_check_loading) { this.setState({ code_check_loading: true }, () => { sendEmailCode({ email, code: email_code }) .then(() => { this.setState({ email_code_error: false, code_check_loading: false, recovery_form_step: 3, }); }) .catch(() => { this.setState({ email_code_error: true, code_check_loading: false }); }); }); } } _handle_onPasswordSubmit = (event) => { event.preventDefault(); const { email, email_code, password, password_repeat, password_check_loading, } = this.state; if(!password_check_loading) { this.setState({ password_check_loading: true }, () => { sendPassword({ email, code: email_code, password, password_repeat, }) .then(() => { this.setState({ password_error: false, password_check_loading: false, recovery_form_step: 4, }); }) .catch(() => { this.setState({ password_error: true, password_check_loading: false }); }); }); } } _handle_onResendEmailCode = (event) => { this.setState({ email_code_error: false }, () => { this._handle_onEmailSubmit(event); }); } _handle_onEmailChange = (value) => { this.setState({ email: value, email_error: false }, () => { this.setState({ email_send_disabled: this._check_fields_disabled([ value, this.state.email ]) }); }); } _handle_onPasswordChange = (value) => { this.setState({ password: value, password_error: false }, () => { this.setState({ set_password_disabled: this._check_fields_disabled([ value, this.state.password ]) }); }); } _handle_onPasswordCheckChange = (value) => { this.setState({ password_repeat: value, password_error: false }, () => { this.setState({ set_password_disabled: this._check_fields_disabled([ value, this.state.password_repeat ]) }); }); } _handle_onEmailCodeChange = (value) => { this.setState({ email_code: value, email_code_submit_disabled: this._check_fields_disabled([ value ]), email_code_error: false }); } _handle_onPasswordChange = (value) => { let error = value === this.state.password_repeat ? false : true; error = value.length < 6 ? true : error; this.setState({ password: value, password_submit_disabled: error ? true : this._check_fields_disabled([ value ]), password_error: error }); } _handle_onPasswordRepeatChange = (value) => { let error = value === this.state.password ? false : true; error = value.length < 6 ? true : error; this.setState({ password_repeat: value, password_submit_disabled: error ? true : this._check_fields_disabled([ value ]), password_error: error }); } _check_fields_disabled = (values) => { for(let i in values) { if(values[i] === "") { return true; } } return false; } render() { const { email, email_code, tab, email_error, email_code_error, set_password_disabled, email_send_disabled, recovery_form_step, email_code_submit_disabled, email_code_resend_disabled, timer, email_auth_loading, email_check_loading, code_check_loading, password, password_repeat, password_submit_disabled, password_check_loading, password_error } = this.state; return ( ЛК Эволюция автолизинга

Восстановление пароля

Восстановить с помощью

Электронной почты
{ recovery_form_step === 1 && ( <>
this._handle_onEmailChange(event.target.value) } required={ true }/>

{ email_error ? 'Ошибка: Неверный адрес E-mail' : `\u00A0` }

) } { recovery_form_step === 2 && ( <>

На адрес E-mail { email } отправлен код подтверждения.

this._handle_onEmailCodeChange(event.target.value) } />
{ timer !== 0 ? (

Запросить код повторно можно через: { timer } { pluralize(timer, 'секунд', 'секунду', 'секунды', 'секунд') }

) : ( ) } {/* disabled={ email_code_resend_disabled }*/}

{ email_code_error ? 'Ошибка: Вы указали неверный код' : `\u00A0` }

) } { recovery_form_step === 3 && ( <>

Вы указали верный код. Введите новый пароль и повторите новый пароль

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

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

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

) } { recovery_form_step === 4 && ( <>

Поздравляем, пароль успешно изменен. Нажмите здесь для авторизации.

) }