accounts-frontend/src/components/auth/forgotPassword/ForgotPasswordBody.js

91 lines
2.8 KiB
JavaScript
Raw Normal View History

2016-05-14 16:56:17 +05:30
import React from 'react';
import { FormattedMessage as Message } from 'react-intl';
import { Input, Captcha } from 'components/ui/form';
2017-08-23 00:09:08 +05:30
import { getLogin } from 'components/auth/reducer';
import { PanelIcon } from 'components/ui/Panel';
2016-05-14 16:56:17 +05:30
import BaseAuthBody from 'components/auth/BaseAuthBody';
import styles from './forgotPassword.scss';
import messages from './ForgotPassword.intl.json';
export default class ForgotPasswordBody extends BaseAuthBody {
static displayName = 'ForgotPasswordBody';
static panelId = 'forgotPassword';
static hasGoBack = true;
state = {
isLoginEdit: !this.getLogin()
};
autoFocusField = this.state.isLoginEdit ? 'login' : null;
2016-05-14 16:56:17 +05:30
render() {
const login = this.getLogin();
const isLoginEditShown = this.state.isLoginEdit;
2016-05-14 16:56:17 +05:30
return (
<div>
{this.renderErrors()}
2017-08-23 00:09:08 +05:30
<PanelIcon icon="lock" />
{isLoginEditShown ? (
<div>
<p className={styles.descriptionText}>
<Message {...messages.specifyEmail} />
</p>
<Input {...this.bindField('login')}
icon="envelope"
color="lightViolet"
required
placeholder={messages.accountEmail}
defaultValue={login}
/>
</div>
) : (
<div>
<div className={styles.login}>
{login}
<span className={styles.editLogin} onClick={this.onClickEdit} />
</div>
<p className={styles.descriptionText}>
<Message {...messages.pleasePressButton} />
</p>
</div>
)}
<Captcha {...this.bindField('captcha')} delay={600} />
2016-05-14 16:56:17 +05:30
</div>
);
}
serialize() {
const data = super.serialize();
if (!data.login) {
data.login = this.getLogin();
}
return data;
}
getLogin() {
2017-08-23 00:09:08 +05:30
const login = getLogin(this.context);
const { user } = this.context;
2017-08-23 00:09:08 +05:30
return login || user.username || user.email || '';
}
onClickEdit = () => {
this.setState({
isLoginEdit: true
});
this.context.requestRedraw();
// TODO: requestRedraw должен возвращать promise, по которому нужно ставить фокус на поле
// иначе же, если фокус ставить сразу, то форма скачет
setTimeout(() => {this.form.focus('login');}, 300);
};
2016-05-14 16:56:17 +05:30
}