-
Notifications
You must be signed in to change notification settings - Fork 0
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
14 changed files
with
251 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,49 @@ | ||
import React from 'react'; | ||
import { connect } from 'react-redux'; | ||
import PropTypes from 'prop-types'; | ||
import Articles from '../Articles/Articles'; | ||
import Dashboard from '../dashboard/Dashboard'; | ||
|
||
const LandingPage = () => ( | ||
<React.Fragment> | ||
<div className="first-section"> | ||
<div className="container"> | ||
<div className="row"> | ||
<div className="col-12 jumbotron mx-auto lp-intro lp-text"> | ||
<p>Authors Haven is the one stop hub for knowledge.</p> | ||
<p>Come take a look at thousands of articles.</p> | ||
<p>You can even share your own!!!</p> | ||
<a href="#start" className="btn ah-btn"> | ||
Join us and share your ideas | ||
</a> | ||
export const LandingPage = ({ isLoggedIn }) => | ||
( | ||
<div> | ||
{!isLoggedIn | ||
? (<React.Fragment> | ||
<div className="first-section"> | ||
<div className="container"> | ||
<div className="row"> | ||
<div className="col-12 jumbotron mx-auto lp-intro lp-text"> | ||
<p>Authors Haven is the one stop hub for knowledge.</p> | ||
<p>Come take a look at thousands of articles.</p> | ||
<p>You can even share your own!!!</p> | ||
<a href="#start" className="btn ah-btn"> | ||
Join us and share your ideas | ||
</a> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<div className="container-fluid article-list"> | ||
<Articles /> | ||
<div className="container-fluid article-list"> | ||
<Articles /> | ||
</div> | ||
</React.Fragment> | ||
) : ( | ||
<Dashboard /> | ||
) | ||
} | ||
</div> | ||
</React.Fragment> | ||
); | ||
); | ||
|
||
LandingPage.propTypes = { | ||
isLoggedIn: PropTypes.bool, | ||
}; | ||
|
||
LandingPage.defaultProps = { | ||
isLoggedIn: false, | ||
}; | ||
|
||
const mapStateToProps = state => ({ | ||
isLoggedIn: state.user.isLoggedIn, | ||
}); | ||
|
||
export default LandingPage; | ||
export default connect(mapStateToProps)(LandingPage); |
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
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,37 @@ | ||
import { Component } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import PropTypes from 'prop-types'; | ||
import '../../assets/App.css'; | ||
import { logOut } from '../../actions/userActions'; | ||
|
||
export class Logout extends Component { | ||
componentWillMount() { | ||
const { isLoggedIn } = this.props; | ||
if (isLoggedIn === true) { | ||
const { logOut } = this.props; | ||
logOut(); | ||
const { history } = this.props; | ||
history.push('/login'); | ||
} | ||
} | ||
|
||
render() { | ||
return null; | ||
} | ||
} | ||
|
||
Logout.propTypes = { | ||
logOut: PropTypes.func.isRequired, | ||
history: PropTypes.object.isRequired, | ||
isLoggedIn: PropTypes.bool, | ||
}; | ||
|
||
Logout.defaultProps = { | ||
isLoggedIn: false, | ||
}; | ||
|
||
const mapStateToProps = state => ({ | ||
isLoggedIn: state.user.isLoggedIn, | ||
}); | ||
|
||
export default connect(mapStateToProps, { logOut })(Logout); |
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,28 @@ | ||
import { Redirect, Route } from 'react-router-dom'; | ||
import React from 'react'; | ||
import decode from 'jwt-decode'; | ||
|
||
export const PrivateRoute = ({ component: Component, ...props }) => { | ||
const authenticate = token => { | ||
if (token) { | ||
const decoded_token = decode(token); | ||
if (decoded_token.exp > (Date.now()) / 1000) { | ||
return { decoded_token }; | ||
} | ||
} | ||
return false; | ||
}; | ||
|
||
const authenticated = authenticate(localStorage.getItem('auth_token')); | ||
|
||
return ( | ||
<Route | ||
{...props} | ||
render={props => | ||
(authenticated ? <Component {...props} /> : <Redirect to="/login" />) | ||
} | ||
/> | ||
); | ||
}; | ||
|
||
export default PrivateRoute; |
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
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,30 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import configureMockStore from 'redux-mock-store'; | ||
import { Logout } from '../../components/login/Logout'; | ||
|
||
|
||
describe('Login component', () => { | ||
const mockStore = configureMockStore(); | ||
let wrapper; | ||
const props = { | ||
history: { push: jest.fn() }, | ||
logOut: jest.fn(), | ||
isLoggedIn: true, | ||
}; | ||
|
||
|
||
beforeEach(() => { | ||
mockStore({}); | ||
wrapper = shallow(<Logout {...props} />); | ||
}); | ||
|
||
it('should redirect user to login page', () => { | ||
wrapper.setProps({ isLoggedIn: true }); | ||
expect(props.history.push).toBeCalledTimes(1); | ||
}); | ||
|
||
it('should render correctly', () => { | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
}); |
Oops, something went wrong.