|
1 | 1 | import React from 'react'; |
2 | 2 | import { Menu, Grid } from 'antd'; |
3 | 3 | import { NavLink } from 'react-router-dom'; |
| 4 | +import { LoginOutlined } from '@ant-design/icons'; |
| 5 | +import { logout } from 'src/components/Auth/Auth.thunks'; |
| 6 | +import { connect, ConnectedProps } from 'react-redux'; |
| 7 | +import { PATH } from 'src/constants/paths'; |
4 | 8 |
|
5 | 9 | const { useBreakpoint } = Grid; |
6 | 10 |
|
7 | | -export const RightMenu = () => { |
| 11 | +const mapStateToProps = (state: AppState) => ({ |
| 12 | + loading: state.auth.loading, |
| 13 | + isAuthenticated: state.app.isAuthenticated, |
| 14 | +}); |
| 15 | +const mapDispatchToProps = { |
| 16 | + logout, |
| 17 | +}; |
| 18 | + |
| 19 | +const connector = connect(mapStateToProps, mapDispatchToProps); |
| 20 | +interface Props extends ConnectedProps<typeof connector> {} |
| 21 | + |
| 22 | +const _RightMenu = (props: Props) => { |
| 23 | + const { loading, isAuthenticated, logout } = props; |
8 | 24 | const { md } = useBreakpoint(); |
9 | | - return ( |
| 25 | + const guestLinks = ( |
10 | 26 | <Menu mode={md ? 'horizontal' : 'inline'}> |
11 | 27 | <Menu.Item key="menukey-login"> |
12 | | - <NavLink className="navbar-item primary" to="/login"> |
| 28 | + <NavLink className="navbar-item primary" to={PATH.LOGIN}> |
13 | 29 | Sign In |
14 | 30 | </NavLink> |
15 | 31 | </Menu.Item> |
16 | 32 | <Menu.Item key="menukey-signup"> |
17 | | - <NavLink className="navbar-item" to="/signup"> |
| 33 | + <NavLink className="navbar-item" to={PATH.REGISTER}> |
18 | 34 | Register |
19 | 35 | </NavLink> |
20 | 36 | </Menu.Item> |
21 | 37 | </Menu> |
22 | 38 | ); |
| 39 | + const authLinks = ( |
| 40 | + <Menu mode={md ? 'horizontal' : 'inline'}> |
| 41 | + <Menu.Item key="menukey-login"> |
| 42 | + <NavLink |
| 43 | + className="navbar-item primary" |
| 44 | + to={PATH.HOME} |
| 45 | + onClick={logout} |
| 46 | + > |
| 47 | + <span> |
| 48 | + <LoginOutlined /> Log Out |
| 49 | + </span> |
| 50 | + </NavLink> |
| 51 | + </Menu.Item> |
| 52 | + </Menu> |
| 53 | + ); |
| 54 | + return <div>{!loading && isAuthenticated ? authLinks : guestLinks}</div>; |
23 | 55 | }; |
| 56 | + |
| 57 | +const RightMenu = connector(_RightMenu); |
| 58 | +export { RightMenu }; |
0 commit comments