-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added login and logout actions in auth reducer
- Loading branch information
Showing
7 changed files
with
118 additions
and
20 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 |
---|---|---|
@@ -1,27 +1,57 @@ | ||
import React from 'react' | ||
import React, { Fragment } from 'react' | ||
import { Link } from 'react-router-dom' | ||
import { connect } from 'react-redux' | ||
import PropTypes from 'prop-types' | ||
|
||
import { logout } from '../../actions/auth' | ||
|
||
const Navbar = ({ auth: { isAuthenticated, loading }, logout }) => { | ||
const authLinks = ( | ||
<ul> | ||
<li> | ||
<a onClick={logout} href='#!'> | ||
<i className='fas fa-sign-out-alt'></i>{' '} | ||
<span className='hide-sm'>Logout</span> | ||
</a> | ||
</li> | ||
</ul> | ||
) | ||
|
||
const guestLinks = ( | ||
<ul> | ||
<li> | ||
<a href='#!'>Developers</a> | ||
</li> | ||
<li> | ||
<Link to='/register'>Register</Link> | ||
</li> | ||
<li> | ||
<Link to='/login'>Login</Link> | ||
</li> | ||
</ul> | ||
) | ||
|
||
const Navbar = () => { | ||
return ( | ||
<nav className='navbar bg-dark'> | ||
<h1> | ||
<Link to='/'> | ||
<i className='fas fa-code'></i> Developer HUB | ||
</Link> | ||
</h1> | ||
<ul> | ||
<li> | ||
<Link to='/profiles'>Developers</Link> | ||
</li> | ||
<li> | ||
<Link to='/register'>Register</Link> | ||
</li> | ||
<li> | ||
<Link to='/login'>Login</Link> | ||
</li> | ||
</ul> | ||
{!loading && ( | ||
<Fragment>{isAuthenticated ? authLinks : guestLinks}</Fragment> | ||
)} | ||
</nav> | ||
) | ||
} | ||
|
||
export default Navbar | ||
Navbar.prototype = { | ||
logout: PropTypes.func.isRequired, | ||
auth: PropTypes.object.isRequired, | ||
} | ||
|
||
const mapStateToProps = (state) => ({ | ||
auth: state.auth, | ||
}) | ||
|
||
export default connect(mapStateToProps, { logout })(Navbar) |
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