2018-02-07 18:06:07 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
2016-11-16 18:12:36 +00:00
|
|
|
import { domOnlyProps } from '../../../utils/reduxFormUtils';
|
2016-06-23 22:29:55 +00:00
|
|
|
|
2016-06-27 18:00:45 +00:00
|
|
|
function LoginForm(props) {
|
2018-05-05 00:22:39 +00:00
|
|
|
const {
|
|
|
|
fields: { email, password }, handleSubmit, submitting, pristine
|
|
|
|
} = props;
|
2016-06-27 18:00:45 +00:00
|
|
|
return (
|
2016-12-19 21:49:37 +00:00
|
|
|
<form className="form" onSubmit={handleSubmit(props.validateAndLoginUser.bind(this, props.previousPath))}>
|
2016-12-15 23:43:58 +00:00
|
|
|
<p className="form__field">
|
2017-01-06 23:14:42 +00:00
|
|
|
<label htmlFor="email" className="form__label">Email or Username</label>
|
2016-06-27 18:00:45 +00:00
|
|
|
<input
|
2016-12-15 23:43:58 +00:00
|
|
|
className="form__input"
|
2017-01-06 23:14:42 +00:00
|
|
|
aria-label="email or username"
|
2016-06-27 18:00:45 +00:00
|
|
|
type="text"
|
2016-12-15 23:43:58 +00:00
|
|
|
id="email"
|
2016-11-16 18:12:36 +00:00
|
|
|
{...domOnlyProps(email)}
|
2016-06-27 18:00:45 +00:00
|
|
|
/>
|
2016-09-02 21:31:07 +00:00
|
|
|
{email.touched && email.error && <span className="form-error">{email.error}</span>}
|
2016-06-27 18:00:45 +00:00
|
|
|
</p>
|
2016-12-15 23:43:58 +00:00
|
|
|
<p className="form__field">
|
|
|
|
<label htmlFor="password" className="form__label">Password</label>
|
2016-06-27 18:00:45 +00:00
|
|
|
<input
|
2016-12-15 23:43:58 +00:00
|
|
|
className="form__input"
|
2016-08-01 01:38:46 +00:00
|
|
|
aria-label="password"
|
2016-06-27 18:00:45 +00:00
|
|
|
type="password"
|
2016-12-15 23:43:58 +00:00
|
|
|
id="password"
|
2016-11-16 18:12:36 +00:00
|
|
|
{...domOnlyProps(password)}
|
2016-06-27 18:00:45 +00:00
|
|
|
/>
|
2016-09-02 21:31:07 +00:00
|
|
|
{password.touched && password.error && <span className="form-error">{password.error}</span>}
|
2016-06-27 18:00:45 +00:00
|
|
|
</p>
|
2016-12-15 23:43:58 +00:00
|
|
|
<input type="submit" disabled={submitting || pristine} value="Log In" aria-label="login" />
|
2016-06-27 18:00:45 +00:00
|
|
|
</form>
|
|
|
|
);
|
2016-06-23 22:29:55 +00:00
|
|
|
}
|
|
|
|
|
2016-06-27 18:00:45 +00:00
|
|
|
LoginForm.propTypes = {
|
|
|
|
fields: PropTypes.shape({
|
2016-08-30 03:26:45 +00:00
|
|
|
email: PropTypes.object.isRequired,
|
|
|
|
password: PropTypes.object.isRequired
|
2016-06-27 18:00:45 +00:00
|
|
|
}).isRequired,
|
|
|
|
handleSubmit: PropTypes.func.isRequired,
|
2016-09-02 21:31:07 +00:00
|
|
|
validateAndLoginUser: PropTypes.func.isRequired,
|
|
|
|
submitting: PropTypes.bool,
|
2016-11-10 21:13:00 +00:00
|
|
|
pristine: PropTypes.bool,
|
2018-05-09 02:10:52 +00:00
|
|
|
invalid: PropTypes.bool,
|
2016-11-10 21:13:00 +00:00
|
|
|
previousPath: PropTypes.string.isRequired
|
2016-06-27 18:00:45 +00:00
|
|
|
};
|
|
|
|
|
2017-02-22 19:29:35 +00:00
|
|
|
LoginForm.defaultProps = {
|
|
|
|
submitting: false,
|
|
|
|
pristine: true,
|
|
|
|
invalid: false
|
|
|
|
};
|
|
|
|
|
2016-06-23 22:29:55 +00:00
|
|
|
export default LoginForm;
|