import React, { Component } from "react"; import { connect } from "react-redux"; import { Link } from "react-router-dom"; import { Dropdown, Menu } from "semantic-ui-react"; import { getSelfUserRequest } from "../actions/user/saga.actions"; import { sendLogoutRequest } from "../actions/auth/saga.actions"; class Navbar extends Component { componentWillMount() { const { dispatch, userToken, selfUser } = this.props; // If the user token exists and the self user object isn't loaded, dispatch if (userToken && Object.keys(selfUser).length === 0) { dispatch(getSelfUserRequest()); } } dispatchLogoutRequest = () => { this.props.dispatch(sendLogoutRequest()); }; render() { const { userToken, selfUser } = this.props; return ( ); } } function mapStateToProps(state) { return { userToken: state.auth.userToken, selfUser: state.user.selfUser }; } const NavbarView = ({ isAuthenticated, dispatchLogoutRequest, selfUser }) => ( Caremyway About {!isAuthenticated && Login Register } {!!isAuthenticated && My Profile {selfUser.client && Work Types } Settings Logout } ); export default connect(mapStateToProps)(Navbar);