2018-02-07 19:06:07 +01:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
2017-03-16 23:25:12 +01:00
|
|
|
import { domOnlyProps } from '../../../utils/reduxFormUtils';
|
2020-04-26 11:40:00 +02:00
|
|
|
import Button from '../../../common/Button';
|
2017-03-16 23:25:12 +01:00
|
|
|
|
|
|
|
function AccountForm(props) {
|
|
|
|
const {
|
2018-05-05 02:22:39 +02:00
|
|
|
fields: {
|
|
|
|
username, email, currentPassword, newPassword
|
|
|
|
},
|
2017-06-26 18:48:28 +02:00
|
|
|
user,
|
2017-03-16 23:25:12 +01:00
|
|
|
handleSubmit,
|
2017-06-26 18:48:28 +02:00
|
|
|
initiateVerification,
|
2017-03-16 23:25:12 +01:00
|
|
|
submitting,
|
|
|
|
invalid,
|
|
|
|
pristine
|
|
|
|
} = props;
|
2017-06-26 18:48:28 +02:00
|
|
|
|
|
|
|
const handleInitiateVerification = (evt) => {
|
|
|
|
evt.preventDefault();
|
|
|
|
initiateVerification();
|
|
|
|
};
|
|
|
|
|
2017-03-16 23:25:12 +01:00
|
|
|
return (
|
|
|
|
<form className="form" onSubmit={handleSubmit(props.updateSettings)}>
|
|
|
|
<p className="form__field">
|
|
|
|
<label htmlFor="email" className="form__label">Email</label>
|
|
|
|
<input
|
|
|
|
className="form__input"
|
|
|
|
aria-label="email"
|
|
|
|
type="text"
|
|
|
|
id="email"
|
|
|
|
{...domOnlyProps(email)}
|
|
|
|
/>
|
|
|
|
{email.touched && email.error && <span className="form-error">{email.error}</span>}
|
|
|
|
</p>
|
2017-06-26 18:48:28 +02:00
|
|
|
{
|
|
|
|
user.verified !== 'verified' &&
|
|
|
|
(
|
|
|
|
<p className="form__context">
|
|
|
|
<span className="form__status">Unconfirmed.</span>
|
|
|
|
{
|
|
|
|
user.emailVerificationInitiate === true ?
|
|
|
|
(
|
|
|
|
<span className="form__status"> Confirmation sent, check your email.</span>
|
|
|
|
) :
|
|
|
|
(
|
2020-04-26 11:40:00 +02:00
|
|
|
<Button
|
2017-06-26 18:48:28 +02:00
|
|
|
onClick={handleInitiateVerification}
|
2018-05-05 02:22:39 +02:00
|
|
|
>Resend confirmation email
|
2020-04-26 11:40:00 +02:00
|
|
|
</Button>
|
2017-06-26 18:48:28 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
</p>
|
|
|
|
)
|
|
|
|
}
|
2017-03-16 23:25:12 +01:00
|
|
|
<p className="form__field">
|
|
|
|
<label htmlFor="username" className="form__label">User Name</label>
|
|
|
|
<input
|
|
|
|
className="form__input"
|
|
|
|
aria-label="username"
|
|
|
|
type="text"
|
|
|
|
id="username"
|
|
|
|
defaultValue={username}
|
|
|
|
{...domOnlyProps(username)}
|
|
|
|
/>
|
|
|
|
{username.touched && username.error && <span className="form-error">{username.error}</span>}
|
|
|
|
</p>
|
|
|
|
<p className="form__field">
|
|
|
|
<label htmlFor="current password" className="form__label">Current Password</label>
|
|
|
|
<input
|
|
|
|
className="form__input"
|
|
|
|
aria-label="currentPassword"
|
|
|
|
type="password"
|
|
|
|
id="currentPassword"
|
|
|
|
{...domOnlyProps(currentPassword)}
|
|
|
|
/>
|
2017-06-06 04:33:32 +02:00
|
|
|
{
|
|
|
|
currentPassword.touched &&
|
|
|
|
currentPassword.error &&
|
|
|
|
<span className="form-error">{currentPassword.error}</span>
|
|
|
|
}
|
2017-03-16 23:25:12 +01:00
|
|
|
</p>
|
|
|
|
<p className="form__field">
|
|
|
|
<label htmlFor="new password" className="form__label">New Password</label>
|
|
|
|
<input
|
|
|
|
className="form__input"
|
|
|
|
aria-label="newPassword"
|
|
|
|
type="password"
|
|
|
|
id="newPassword"
|
|
|
|
{...domOnlyProps(newPassword)}
|
|
|
|
/>
|
|
|
|
{newPassword.touched && newPassword.error && <span className="form-error">{newPassword.error}</span>}
|
|
|
|
</p>
|
2020-04-26 11:40:00 +02:00
|
|
|
<Button
|
2017-06-06 04:33:32 +02:00
|
|
|
type="submit"
|
|
|
|
disabled={submitting || invalid || pristine}
|
2020-04-26 11:40:00 +02:00
|
|
|
>Save All Settings
|
|
|
|
</Button>
|
2017-03-16 23:25:12 +01:00
|
|
|
</form>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
AccountForm.propTypes = {
|
|
|
|
fields: PropTypes.shape({
|
2020-07-24 22:01:48 +02: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 18:48:28 +02:00
|
|
|
}).isRequired,
|
|
|
|
user: PropTypes.shape({
|
|
|
|
verified: PropTypes.number.isRequired,
|
|
|
|
emailVerificationInitiate: PropTypes.bool.isRequired,
|
2017-03-16 23:25:12 +01:00
|
|
|
}).isRequired,
|
|
|
|
handleSubmit: PropTypes.func.isRequired,
|
2017-06-26 18:48:28 +02:00
|
|
|
initiateVerification: PropTypes.func.isRequired,
|
2017-03-16 23:25:12 +01:00
|
|
|
updateSettings: PropTypes.func.isRequired,
|
|
|
|
submitting: PropTypes.bool,
|
|
|
|
invalid: PropTypes.bool,
|
|
|
|
pristine: PropTypes.bool,
|
|
|
|
};
|
|
|
|
|
|
|
|
AccountForm.defaultProps = {
|
|
|
|
submitting: false,
|
|
|
|
pristine: true,
|
|
|
|
invalid: false
|
|
|
|
};
|
|
|
|
|
|
|
|
export default AccountForm;
|