2017-08-23 00:19:50 +05:30
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React, { Component } from 'react';
|
2016-05-02 18:43:18 +05:30
|
|
|
|
|
|
|
import { FormattedMessage as Message } from 'react-intl';
|
|
|
|
import Helmet from 'react-helmet';
|
|
|
|
|
|
|
|
import { Input, Button, Form, FormModel } from 'components/ui/form';
|
2016-05-26 20:21:17 +05:30
|
|
|
import { BackButton } from 'components/profile/ProfileForm';
|
2016-05-02 18:43:18 +05:30
|
|
|
import styles from 'components/profile/profileForm.scss';
|
2016-05-02 23:02:03 +05:30
|
|
|
|
2016-05-22 13:23:40 +05:30
|
|
|
import messages from './ChangeUsername.intl.json';
|
2016-05-02 18:43:18 +05:30
|
|
|
|
|
|
|
export default class ChangeUsername extends Component {
|
|
|
|
static displayName = 'ChangeUsername';
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
username: PropTypes.string.isRequired,
|
|
|
|
form: PropTypes.instanceOf(FormModel),
|
|
|
|
onChange: PropTypes.func.isRequired,
|
|
|
|
onSubmit: PropTypes.func.isRequired
|
|
|
|
};
|
|
|
|
|
|
|
|
static get defaultProps() {
|
|
|
|
return {
|
|
|
|
form: new FormModel()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {form, username} = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Form onSubmit={this.onFormSubmit}
|
|
|
|
form={form}
|
|
|
|
>
|
|
|
|
<div className={styles.contentWithBackButton}>
|
2016-05-26 20:21:17 +05:30
|
|
|
<BackButton />
|
2016-05-02 18:43:18 +05:30
|
|
|
|
|
|
|
<div className={styles.form}>
|
|
|
|
<div className={styles.formBody}>
|
|
|
|
<Message {...messages.changeUsernameTitle}>
|
|
|
|
{(pageTitle) => (
|
|
|
|
<h3 className={styles.title}>
|
|
|
|
<Helmet title={pageTitle} />
|
|
|
|
{pageTitle}
|
|
|
|
</h3>
|
|
|
|
)}
|
|
|
|
</Message>
|
|
|
|
|
|
|
|
<div className={styles.formRow}>
|
|
|
|
<p className={styles.description}>
|
|
|
|
<Message {...messages.changeUsernameDescription} />
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className={styles.formRow}>
|
|
|
|
<Input {...form.bindField('username')}
|
|
|
|
value={username}
|
|
|
|
onChange={this.onUsernameChange}
|
|
|
|
required
|
|
|
|
skin="light"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className={styles.formRow}>
|
|
|
|
<p className={styles.description}>
|
|
|
|
<Message {...messages.changeUsernameWarning} />
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2017-08-23 00:27:35 +05:30
|
|
|
<Button color="green"
|
|
|
|
block
|
|
|
|
label={messages.changeUsernameButton}
|
|
|
|
type="submit"
|
|
|
|
/>
|
2016-05-02 18:43:18 +05:30
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
onUsernameChange = (event) => {
|
|
|
|
this.props.onChange(event.target.value);
|
|
|
|
};
|
|
|
|
|
|
|
|
onFormSubmit = () => {
|
2017-02-27 11:17:31 +05:30
|
|
|
const {form} = this.props;
|
|
|
|
|
|
|
|
this.props.onSubmit(form)
|
|
|
|
.catch((resp) => {
|
|
|
|
if (resp.errors) {
|
|
|
|
form.setErrors(resp.errors);
|
|
|
|
} else {
|
|
|
|
return Promise.reject(resp);
|
|
|
|
}
|
|
|
|
});
|
2016-05-02 18:43:18 +05:30
|
|
|
};
|
|
|
|
}
|