-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
306 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Link, Redirect } from 'react-router-dom'; | ||
import { connect } from 'react-redux'; | ||
import { Row } from 'react-materialize'; | ||
import GoogleLogin from 'react-google-login'; | ||
import FaGoogle from 'react-icons/lib/fa/google'; | ||
|
||
import Header from '../header/Header'; | ||
import { login } from '../../actions/login'; | ||
import Loading from '../Loading'; | ||
|
||
|
||
const Materialize = window.Materialize; | ||
|
||
/* | ||
eslint-disable | ||
*/ | ||
class Login extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
username: '', | ||
password: '', | ||
}; | ||
this.handleLogin = this.handleLogin.bind(this); | ||
this.handleChange = this.handleChange.bind(this); | ||
this.responseGoogle = this.responseGoogle.bind(this); | ||
} | ||
|
||
responseGoogle(response) { | ||
// const loginProfile = response.getBasicProfile(); | ||
console.log(response); | ||
} | ||
|
||
handleLogin(event) { | ||
event.preventDefault(); | ||
this.setState({ isLoading: true }); | ||
this.props.login(this.state) | ||
.then( | ||
(data) => { | ||
Materialize.toast( | ||
`Welcome Back, ${data.firstName || 'Reader'}`, | ||
2500, | ||
'teal darken-4' | ||
); | ||
}, | ||
(error) => { | ||
Materialize.toast(error.response.data.message, 2500, 'red darken-4'); | ||
this.setState({ isLoading: false }); | ||
} | ||
) | ||
.catch((err) => { | ||
Materialize.toast( | ||
`Ouch! Something went awry. It's probably our fault`, | ||
2500, | ||
'red darken-4' | ||
); | ||
this.setState({ isLoading: false }); | ||
}); | ||
} | ||
|
||
handleChange(event) { | ||
event.preventDefault(); | ||
const formField = event.target.name; | ||
const user = Object.assign({}, this.state); | ||
if (!!event.target.value.trim()) { | ||
user[formField] = event.target.value.trim(); | ||
} | ||
this.setState(() => user); | ||
} | ||
|
||
render() { | ||
const loadingState = this.state.isLoading ? | ||
<Loading text='logging in' /> : null | ||
return ( | ||
this.props.isLoggedIn === true ? | ||
<Redirect to='/dashboard'/> : | ||
<div> | ||
<Header | ||
navLinks={['login', 'sign up', 'library']} | ||
/> | ||
<main> | ||
<section className="account"> | ||
<Row> | ||
<div className="container"> | ||
<div className="center"> | ||
<div className="col m6 s12 welcome"> | ||
<h2>Hello Reader</h2> | ||
<h6>Welcome home avid reader</h6> | ||
</div> | ||
<div className="col m6 s12"> | ||
<form onSubmit={this.handleLogin}> | ||
<div className="col s12"> | ||
<h5>Login</h5> | ||
</div> | ||
<div className="col s12"> | ||
<div className="container"> | ||
<div className="input-field"> | ||
<input type="text" | ||
name="username" | ||
placeholder="Username" | ||
className="validate" | ||
required | ||
title="username is required for login" | ||
onChange={this.handleChange} | ||
/> | ||
</div> | ||
<div className="input-field"> | ||
<input type="password" | ||
name="password" | ||
placeholder="password" | ||
className="validate" | ||
required | ||
title="password is required for login" | ||
onChange={this.handleChange} | ||
/> | ||
</div> | ||
{loadingState} | ||
<div className="input-field"> | ||
<input | ||
type="submit" | ||
name="submit" | ||
value="LOGIN" | ||
className="btn waves-effect waves-light" | ||
style={{ width: '100%' }} | ||
/> | ||
</div> | ||
<div className="input-field"> | ||
{/* <GoogleLogin | ||
clientId={GOOGLE_CLIENT_ID} | ||
onSuccess={this.responseGoogle} | ||
onFailure={this.responseGoogle} | ||
className="btn red darken-4" | ||
style={{ width: '100%' }} | ||
> | ||
<FaGoogle | ||
style={{ | ||
color: '#032442', | ||
fontSize: '2rem', | ||
}} | ||
/> | ||
<span> Login with Google</span> | ||
</GoogleLogin> */} | ||
</div> | ||
<div> | ||
<p className="center">Don't have an account? | ||
<Link to="/signup"> Sign up</Link> | ||
</p> | ||
</div> | ||
<div> | ||
<p className="center">Forgot password? | ||
<Link to="/forgot-password"> Click here</Link> | ||
</p> | ||
</div> | ||
</div> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
</Row> | ||
</section> | ||
</main> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
Login.propTypes = { | ||
login: PropTypes.func.isRequired, | ||
}; | ||
|
||
const mapStateToProps = ({ authReducer }) => ( | ||
{ isLoggedIn: authReducer.isLoggedIn } | ||
); | ||
|
||
|
||
export default connect(mapStateToProps, { login })(Login); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { connect } from 'react-redux'; | ||
import { Col, Row } from 'react-materialize'; | ||
|
||
import Header from '../header/Header'; | ||
|
||
/** | ||
* Component to update user profile | ||
* @type {Object} | ||
*/ | ||
class UpdateProfile extends Component { | ||
/** | ||
* constructs instance of Component | ||
* @return {Object} JSX component | ||
*/ | ||
constructor() { | ||
super(); | ||
this.handleSubmit = this.handleSubmit.bind(this); | ||
} | ||
/** | ||
* handles form submission | ||
* @param {Object} event DOM onSubmit event | ||
* @return {mixed} sends a network request | ||
*/ | ||
handleSubmit(event) { | ||
event.preventDefault(); | ||
} | ||
|
||
/** | ||
* class method that renders a component to the DOM | ||
* @return {Object} JSX element | ||
*/ | ||
render() { | ||
return ( | ||
<div> | ||
<Header | ||
activeLink='dashboard' | ||
/> | ||
<main> | ||
<Row> | ||
<Col s={12} m={6} className="offset-m3"> | ||
<form onSubmit={this.handleSubmit}> | ||
<div style={{ marginBottom: '50px' }}> | ||
<h5 className="center" > | ||
Update your profile information | ||
</h5> | ||
</div> | ||
|
||
<div className="input-field"> | ||
<h6>First Name:</h6> | ||
<input | ||
id="firstName" | ||
defaultValue={this.props.user.firstName || ''} | ||
/> | ||
</div> | ||
<div className="input-field"> | ||
<h6>Last Name:</h6> | ||
<input | ||
id="lastName" | ||
defaultValue={this.props.user.lastName || ''} | ||
/> | ||
</div> | ||
<h6 className="red-text darken-4" > | ||
Leave the password fields empty unless you actually want | ||
to change your password | ||
</h6> | ||
<div className="input-field"> | ||
<h6>Current Password:</h6> | ||
<input | ||
id="" | ||
type="password" | ||
defaultValue="" | ||
/> | ||
</div> | ||
<div className="input-field"> | ||
<h6>New Password:</h6> | ||
<input | ||
type="password" | ||
id="newPassword" | ||
defaultValue="" | ||
/> | ||
</div> | ||
<div className="input-field"> | ||
<input | ||
className="btn teal darken-4 waves-effect waves-light" | ||
style={{ width: '100%' }} | ||
type="submit" | ||
value="Submit" | ||
/> | ||
</div> | ||
</form> | ||
</Col> | ||
</Row> | ||
</main> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
UpdateProfile.propTypes = { | ||
user: PropTypes.object.isRequired, | ||
}; | ||
|
||
const mapStateToProps = ({ authReducer }) => ({ | ||
user: authReducer.user, | ||
}); | ||
|
||
export default connect(mapStateToProps)(UpdateProfile); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters