2018-02-07 18:06:07 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
2020-08-13 12:25:57 +00:00
|
|
|
import { withTranslation } from 'react-i18next';
|
2017-03-16 22:25:12 +00:00
|
|
|
import { domOnlyProps } from '../../../utils/reduxFormUtils';
|
2020-04-26 09:40:00 +00:00
|
|
|
import Button from '../../../common/Button';
|
2017-03-16 22:25:12 +00:00
|
|
|
|
|
|
|
function AccountForm(props) {
|
|
|
|
const {
|
2018-05-05 00:22:39 +00:00
|
|
|
fields: {
|
|
|
|
username, email, currentPassword, newPassword
|
|
|
|
},
|
2017-06-26 16:48:28 +00:00
|
|
|
user,
|
2017-03-16 22:25:12 +00:00
|
|
|
handleSubmit,
|
2017-06-26 16:48:28 +00:00
|
|
|
initiateVerification,
|
2017-03-16 22:25:12 +00:00
|
|
|
submitting,
|
|
|
|
invalid,
|
2020-07-24 21:11:10 +00:00
|
|
|
pristine,
|
2020-08-13 12:25:57 +00:00
|
|
|
t
|
2017-03-16 22:25:12 +00:00
|
|
|
} = props;
|
2017-06-26 16:48:28 +00:00
|
|
|
|
|
|
|
const handleInitiateVerification = (evt) => {
|
|
|
|
evt.preventDefault();
|
|
|
|
initiateVerification();
|
|
|
|
};
|
|
|
|
|
2017-03-16 22:25:12 +00:00
|
|
|
return (
|
|
|
|
<form className="form" onSubmit={handleSubmit(props.updateSettings)}>
|
|
|
|
<p className="form__field">
|
2020-08-13 12:25:57 +00:00
|
|
|
<label htmlFor="email" className="form__label">{t('AccountForm.Email')}</label>
|
2017-03-16 22:25:12 +00:00
|
|
|
<input
|
|
|
|
className="form__input"
|
2020-08-13 12:25:57 +00:00
|
|
|
aria-label={t('AccountForm.EmailARIA')}
|
2017-03-16 22:25:12 +00:00
|
|
|
type="text"
|
|
|
|
id="email"
|
|
|
|
{...domOnlyProps(email)}
|
|
|
|
/>
|
2020-07-24 21:11:10 +00:00
|
|
|
{email.touched && email.error && (
|
|
|
|
<span className="form-error">{email.error}</span>
|
|
|
|
)}
|
2017-03-16 22:25:12 +00:00
|
|
|
</p>
|
2017-06-26 16:48:28 +00:00
|
|
|
{
|
|
|
|
user.verified !== 'verified' &&
|
|
|
|
(
|
|
|
|
<p className="form__context">
|
2020-08-13 12:25:57 +00:00
|
|
|
<span className="form__status">{t('AccountForm.Unconfirmed')}</span>
|
2017-06-26 16:48:28 +00:00
|
|
|
{
|
|
|
|
user.emailVerificationInitiate === true ?
|
|
|
|
(
|
2020-08-13 12:25:57 +00:00
|
|
|
<span className="form__status"> {t('AccountForm.EmailSent')}</span>
|
2017-06-26 16:48:28 +00:00
|
|
|
) :
|
|
|
|
(
|
2020-04-26 09:40:00 +00:00
|
|
|
<Button
|
2017-06-26 16:48:28 +00:00
|
|
|
onClick={handleInitiateVerification}
|
2020-08-13 12:25:57 +00:00
|
|
|
>{t('AccountForm.Resend')}
|
2020-04-26 09:40:00 +00:00
|
|
|
</Button>
|
2017-06-26 16:48:28 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
</p>
|
|
|
|
)
|
|
|
|
}
|
2017-03-16 22:25:12 +00:00
|
|
|
<p className="form__field">
|
2020-08-13 12:25:57 +00:00
|
|
|
<label htmlFor="username" className="form__label">{t('AccountForm.UserName')}</label>
|
2017-03-16 22:25:12 +00:00
|
|
|
<input
|
|
|
|
className="form__input"
|
2020-08-13 12:25:57 +00:00
|
|
|
aria-label={t('AccountForm.UserNameARIA')}
|
2017-03-16 22:25:12 +00:00
|
|
|
type="text"
|
|
|
|
id="username"
|
|
|
|
defaultValue={username}
|
|
|
|
{...domOnlyProps(username)}
|
|
|
|
/>
|
2020-07-24 21:11:10 +00:00
|
|
|
{username.touched && username.error && (
|
|
|
|
<span className="form-error">{username.error}</span>
|
|
|
|
)}
|
2017-03-16 22:25:12 +00:00
|
|
|
</p>
|
|
|
|
<p className="form__field">
|
2020-08-13 12:25:57 +00:00
|
|
|
<label htmlFor="current password" className="form__label">{t('AccountForm.CurrentPassword')}</label>
|
2017-03-16 22:25:12 +00:00
|
|
|
<input
|
|
|
|
className="form__input"
|
2020-08-13 12:25:57 +00:00
|
|
|
aria-label={t('AccountForm.CurrentPasswordARIA')}
|
2017-03-16 22:25:12 +00:00
|
|
|
type="password"
|
|
|
|
id="currentPassword"
|
|
|
|
{...domOnlyProps(currentPassword)}
|
|
|
|
/>
|
2020-07-24 21:11:10 +00:00
|
|
|
{currentPassword.touched && currentPassword.error && (
|
2017-06-06 02:33:32 +00:00
|
|
|
<span className="form-error">{currentPassword.error}</span>
|
2020-07-24 21:11:10 +00:00
|
|
|
)}
|
2017-03-16 22:25:12 +00:00
|
|
|
</p>
|
|
|
|
<p className="form__field">
|
2020-08-13 12:25:57 +00:00
|
|
|
<label htmlFor="new password" className="form__label">{t('AccountForm.NewPassword')}</label>
|
2017-03-16 22:25:12 +00:00
|
|
|
<input
|
|
|
|
className="form__input"
|
2020-08-13 12:25:57 +00:00
|
|
|
aria-label={t('AccountForm.NewPasswordARIA')}
|
2017-03-16 22:25:12 +00:00
|
|
|
type="password"
|
|
|
|
id="newPassword"
|
|
|
|
{...domOnlyProps(newPassword)}
|
|
|
|
/>
|
2020-07-24 21:11:10 +00:00
|
|
|
{newPassword.touched && newPassword.error && (
|
|
|
|
<span className="form-error">{newPassword.error}</span>
|
|
|
|
)}
|
2017-03-16 22:25:12 +00:00
|
|
|
</p>
|
2020-04-26 09:40:00 +00:00
|
|
|
<Button
|
2017-06-06 02:33:32 +00:00
|
|
|
type="submit"
|
|
|
|
disabled={submitting || invalid || pristine}
|
2020-08-13 12:25:57 +00:00
|
|
|
>{t('AccountForm.SubmitSaveAllSettings')}
|
2020-04-26 09:40:00 +00:00
|
|
|
</Button>
|
2017-03-16 22:25:12 +00:00
|
|
|
</form>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
AccountForm.propTypes = {
|
|
|
|
fields: PropTypes.shape({
|
2020-07-24 21:11:10 +00:00
|
|
|
username: PropTypes.object.isRequired, // eslint-disable-line
|
|
|
|
email: PropTypes.object.isRequired, // eslint-disable-line
|
|
|
|
currentPassword: PropTypes.object.isRequired, // eslint-disable-line
|
|
|
|
newPassword: PropTypes.object.isRequired, // eslint-disable-line
|
2017-06-26 16:48:28 +00:00
|
|
|
}).isRequired,
|
|
|
|
user: PropTypes.shape({
|
|
|
|
verified: PropTypes.number.isRequired,
|
|
|
|
emailVerificationInitiate: PropTypes.bool.isRequired,
|
2017-03-16 22:25:12 +00:00
|
|
|
}).isRequired,
|
|
|
|
handleSubmit: PropTypes.func.isRequired,
|
2017-06-26 16:48:28 +00:00
|
|
|
initiateVerification: PropTypes.func.isRequired,
|
2017-03-16 22:25:12 +00:00
|
|
|
updateSettings: PropTypes.func.isRequired,
|
|
|
|
submitting: PropTypes.bool,
|
|
|
|
invalid: PropTypes.bool,
|
|
|
|
pristine: PropTypes.bool,
|
2020-08-13 12:25:57 +00:00
|
|
|
t: PropTypes.func.isRequired
|
2017-03-16 22:25:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
AccountForm.defaultProps = {
|
|
|
|
submitting: false,
|
|
|
|
pristine: true,
|
2020-07-24 21:11:10 +00:00
|
|
|
invalid: false,
|
2017-03-16 22:25:12 +00:00
|
|
|
};
|
|
|
|
|
2020-08-13 12:25:57 +00:00
|
|
|
export default withTranslation()(AccountForm);
|