106 lines
4.0 KiB
TypeScript
Raw Normal View History

2019-12-30 10:47:29 +02:00
import React from 'react';
import { FormattedMessage as Message } from 'react-intl';
import { Helmet } from 'react-helmet-async';
2020-05-24 02:08:24 +03:00
import { Input, Button, Checkbox, Form, FormModel } from 'app/components/ui/form';
2019-12-30 10:47:29 +02:00
import { BackButton } from '../ProfileForm';
import styles from '../profileForm.scss';
import messages from './ChangePassword.intl.json';
2019-12-30 10:47:29 +02:00
interface Props {
2020-05-24 02:08:24 +03:00
form: FormModel;
onSubmit: (form: FormModel) => Promise<void>;
2019-12-30 10:47:29 +02:00
}
2019-12-30 10:47:29 +02:00
export default class ChangePassword extends React.Component<Props> {
2020-05-24 02:08:24 +03:00
static get defaultProps(): Partial<Props> {
return {
form: new FormModel(),
};
}
2020-05-24 02:08:24 +03:00
render() {
const { form } = this.props;
2020-05-24 02:08:24 +03:00
return (
<Form onSubmit={this.onFormSubmit} form={form}>
<div className={styles.contentWithBackButton}>
<BackButton />
2020-05-24 02:08:24 +03:00
<div className={styles.form}>
<div className={styles.formBody}>
<Message {...messages.changePasswordTitle}>
{(pageTitle) => (
<h3 className={styles.title}>
<Helmet title={pageTitle as string} />
{pageTitle}
</h3>
)}
</Message>
2020-05-24 02:08:24 +03:00
<div className={styles.formRow}>
<p className={styles.description}>
<Message {...messages.changePasswordDescription} />
<br />
<b>
<Message {...messages.achievementLossWarning} />
</b>
</p>
</div>
2020-05-24 02:08:24 +03:00
<div className={styles.formRow}>
<Input
{...form.bindField('newPassword')}
type="password"
required
skin="light"
label={messages.newPasswordLabel}
/>
</div>
2020-05-24 02:08:24 +03:00
<div className={styles.formRow}>
<p className={styles.description}>
<Message {...messages.passwordRequirements} />
</p>
</div>
2020-05-24 02:08:24 +03:00
<div className={styles.formRow}>
<Input
{...form.bindField('newRePassword')}
type="password"
required
skin="light"
label={messages.repeatNewPasswordLabel}
/>
</div>
2020-05-24 02:08:24 +03:00
<div className={styles.formRow}>
<Checkbox
{...form.bindField('logoutAll')}
defaultChecked
skin="light"
label={messages.logoutOnAllDevices}
/>
</div>
</div>
2020-05-24 02:08:24 +03:00
<Button color="green" block label={messages.changePasswordButton} type="submit" />
</div>
</div>
</Form>
);
}
2020-05-24 02:08:24 +03:00
onFormSubmit = () => {
const { form } = this.props;
2020-05-24 02:08:24 +03:00
this.props.onSubmit(form).catch((resp) => {
if (resp.errors) {
form.setErrors(resp.errors);
} else {
return Promise.reject(resp);
}
});
};
}