Skip to content

Feature log out #16

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

Open
wants to merge 3 commits into
base: development
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
1 change: 0 additions & 1 deletion application/src/components/main/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const mapStateToProps = state => ({

class Main extends Component {
render() {
console.log('props', this.props);
return (
<div className="main-body">
<h1>Bruce's Diner Ordering Application</h1>
Expand Down
12 changes: 9 additions & 3 deletions application/src/components/nav/nav.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React from "react";
import { Link } from "react-router-dom";
import { connect } from "react-redux";
import "./nav.css";
import { logoutUser } from "../../redux/actions/authActions";

const Nav = (props) => {
const Nav = ({ logoutUser }) => {
return (
<div className="nav-strip">
<Link to={"/order"} className="nav-link">
Expand All @@ -17,11 +19,15 @@ const Nav = (props) => {
</Link>
<Link to={"/login"} className="nav-link">
<div className="nav-link-style">
<label className="nav-label">Log Out</label>
<label className="nav-label" onClick={() => logoutUser()}>Log Out</label>
</div>
</Link>
</div>
);
}

export default Nav;
const mapDispatchToProps = dispatch => ({
logoutUser: e => dispatch(logoutUser(e))
})

export default connect(null, mapDispatchToProps)(Nav);
16 changes: 8 additions & 8 deletions application/src/redux/reducers/authReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { LOGIN, LOGOUT } from '../actions/types'
const INITIAL_STATE = { email: null, token: null };

export default (state = INITIAL_STATE, action) => {
switch (action.type) {
case LOGIN:
return { ...state, email: action.payload.login, token: action.payload.token }
case LOGOUT:
return { ...state, ...INITIAL_STATE }
default:
return state;
}
switch (action.type) {
case LOGIN:
return { ...state, email: action.payload.email, token: action.payload.token }
case LOGOUT:
return { ...INITIAL_STATE }
default:
return state;
}
}