2019-12-30 14:17:29 +05:30
|
|
|
import React from 'react';
|
2016-05-02 18:43:18 +05:30
|
|
|
import { FormattedMessage as Message } from 'react-intl';
|
2019-12-30 12:59:39 +05:30
|
|
|
import { Helmet } from 'react-helmet-async';
|
2019-12-08 00:32:00 +05:30
|
|
|
import { Input, Button, Form, FormModel } from 'app/components/ui/form';
|
|
|
|
import { BackButton } from 'app/components/profile/ProfileForm';
|
2016-05-02 23:02:03 +05:30
|
|
|
|
2019-12-30 14:17:29 +05:30
|
|
|
import styles from '../profileForm.scss';
|
2016-05-22 13:23:40 +05:30
|
|
|
import messages from './ChangeUsername.intl.json';
|
2016-05-02 18:43:18 +05:30
|
|
|
|
2019-12-30 14:17:29 +05:30
|
|
|
interface Props {
|
2020-05-24 04:38:24 +05:30
|
|
|
username: string;
|
|
|
|
form: FormModel;
|
|
|
|
onChange: (name: string) => void;
|
|
|
|
onSubmit: (form: FormModel) => Promise<void>;
|
2019-12-30 14:17:29 +05:30
|
|
|
}
|
2019-11-27 14:33:32 +05:30
|
|
|
|
2019-12-30 14:17:29 +05:30
|
|
|
export default class ChangeUsername extends React.Component<Props> {
|
2020-05-24 04:38:24 +05:30
|
|
|
static get defaultProps(): Partial<Props> {
|
|
|
|
return {
|
|
|
|
form: new FormModel(),
|
|
|
|
};
|
|
|
|
}
|
2019-11-27 14:33:32 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
render() {
|
|
|
|
const { form, username } = this.props;
|
2019-11-27 14:33:32 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
return (
|
|
|
|
<Form onSubmit={this.onFormSubmit} form={form}>
|
|
|
|
<div className={styles.contentWithBackButton}>
|
|
|
|
<BackButton />
|
2019-11-27 14:33:32 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
<div className={styles.form}>
|
|
|
|
<div className={styles.formBody}>
|
|
|
|
<Message {...messages.changeUsernameTitle}>
|
|
|
|
{(pageTitle) => (
|
|
|
|
<h3 className={styles.title}>
|
|
|
|
<Helmet title={pageTitle as string} />
|
|
|
|
{pageTitle}
|
|
|
|
</h3>
|
|
|
|
)}
|
|
|
|
</Message>
|
2019-11-27 14:33:32 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
<div className={styles.formRow}>
|
|
|
|
<p className={styles.description}>
|
|
|
|
<Message {...messages.changeUsernameDescription} />
|
|
|
|
</p>
|
|
|
|
</div>
|
2019-11-27 14:33:32 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
<div className={styles.formRow}>
|
|
|
|
<Input
|
|
|
|
{...form.bindField('username')}
|
|
|
|
value={username}
|
|
|
|
onChange={this.onUsernameChange}
|
|
|
|
required
|
|
|
|
skin="light"
|
|
|
|
/>
|
|
|
|
</div>
|
2019-11-27 14:33:32 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
<div className={styles.formRow}>
|
|
|
|
<p className={styles.description}>
|
|
|
|
<Message {...messages.changeUsernameWarning} />
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
2019-11-27 14:33:32 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
<Button color="green" block label={messages.changeUsernameButton} type="submit" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
}
|
2019-11-27 14:33:32 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
onUsernameChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
|
|
this.props.onChange(event.target.value);
|
|
|
|
};
|
2019-11-27 14:33:32 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
onFormSubmit = () => {
|
|
|
|
const { form } = this.props;
|
2019-11-27 14:33:32 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
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
|
|
|
}
|