Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Frontend] Show dyanamic content on navbar #145

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 38 additions & 22 deletions React-frontend/src/components/core/Navbar.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import { useSelector, useDispatch } from 'react-redux';
import Logo from '../../images/logo.png';
import Ham from '../../images/hamburger.png';
import { Link } from 'react-router-dom';
Expand All @@ -11,50 +12,65 @@ import {
} from 'mdbreact';
import { MDBBtn } from 'mdbreact';

function Nvb() {
import { logout } from '../../store/actions/auth';

const Nvb = () => {
const dispatch = useDispatch();
const { isLoading, isAuthenticated } = useSelector(state => state.auth);

const logoutHandler = () => {
dispatch(logout());
};

return (
<div>
<Navbar expand="lg" bg="dark" variant="dark">
<Nav className="mr-auto">
<Link class="navbar-brand" to="/">
<img src={Logo} height="50" width="50" alt="logo"></img>
<Navbar expand='lg' bg='dark' variant='dark'>
<Nav className='mr-auto'>
<Link class='navbar-brand' to='/'>
<img src={Logo} height='50' width='50' alt='logo'></img>
OpenMF
</Link>
</Nav>
<Nav>
<a href="https://github.com/scorelab/OpenMF/">
<MDBBtn outline color="success">
<a href='https://github.com/scorelab/OpenMF/'>
<MDBBtn outline color='success'>
Help
</MDBBtn>
</a>
<Link to="/login">
<MDBBtn outline color="primary">
Login
{!isLoading && isAuthenticated ? (
<MDBBtn onClick={logoutHandler} outline color='primary'>
Logout
</MDBBtn>
</Link>
) : (
<Link to='/login'>
<MDBBtn outline color='primary'>
Login
</MDBBtn>
</Link>
)}
<MDBDropdown>
<MDBDropdownToggle caret color="dark">
<MDBDropdownToggle caret color='dark'>
{
<img
className="thumbnail-image"
className='thumbnail-image'
src={Ham}
alt="down"
height="25"
width="28"
alt='down'
height='25'
width='28'
/>
}
</MDBDropdownToggle>
<MDBDropdownMenu className="dropdown-default">
<MDBDropdownItem href="#!">Contact Admin</MDBDropdownItem>
<MDBDropdownItem href="#!">Request Role</MDBDropdownItem>
<MDBDropdownItem href="#!">Contribute</MDBDropdownItem>
<MDBDropdownItem href="#!">Report bug</MDBDropdownItem>
<MDBDropdownMenu className='dropdown-default'>
<MDBDropdownItem href='#!'>Contact Admin</MDBDropdownItem>
<MDBDropdownItem href='#!'>Request Role</MDBDropdownItem>
<MDBDropdownItem href='#!'>Contribute</MDBDropdownItem>
<MDBDropdownItem href='#!'>Report bug</MDBDropdownItem>
</MDBDropdownMenu>
</MDBDropdown>
</Nav>
</Navbar>
</div>
);
}
};

export default Nvb;
4 changes: 3 additions & 1 deletion React-frontend/src/store/actions/auth.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import axios from '../../axios';
import { setAlert } from './alerts';
import history from '../../utils/history';

export const LOGIN = 'LOGIN';
export const LOGOUT = 'LOGOUT';
Expand All @@ -20,6 +21,7 @@ export const login = loginData => async dispatch => {
}
};

export const logout = () => dispatch => {
export const logout = () => async dispatch => {
history.push('/login');
dispatch({ type: LOGOUT });
};
4 changes: 4 additions & 0 deletions React-frontend/src/utils/history.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { createBrowserHistory } from 'history';

const history = createBrowserHistory();
export default history;