1616import "./nav.css" ;
1717
1818import { Button , Dropdown , Menu , Avatar , Layout , Space } from "antd" ;
19- import { LogoutOutlined , DownOutlined } from "@ant-design/icons" ;
19+ import { LogoutOutlined , EditOutlined , ProfileOutlined , CaretDownOutlined } from "@ant-design/icons" ;
2020import React from "react" ;
21+ import roleTypes from "../../constants/roleTypes" ;
22+ import type { MenuProps } from 'antd' ;
2123import { useNavigate } from "react-router-dom" ;
2224import { connect , ConnectedProps } from "react-redux" ;
2325import { logOutUserAction } from "../../actions/userActions" ;
@@ -30,6 +32,7 @@ interface RootState {
3032 accessToken : string ;
3133 name : string ;
3234 isLoggedIn : boolean ;
35+ role : string ;
3336 } ;
3437 profileReducer : {
3538 profilePicData : string ;
@@ -48,7 +51,7 @@ interface NavbarProps extends PropsFromRedux {}
4851 * dropdown alos consists the logout button
4952 */
5053const Navbar : React . FC < NavbarProps > = ( props ) => {
51- const { logOutUser, isLoggedIn, name, profilePicData } = props ;
54+ const { logOutUser, isLoggedIn, name, role , profilePicData } = props ;
5255 const navigate = useNavigate ( ) ;
5356
5457 const logout = ( ) => {
@@ -59,39 +62,36 @@ const Navbar: React.FC<NavbarProps> = (props) => {
5962 } ) ;
6063 } ;
6164
62- const takeMenuAction = ( input : { key : string } ) => {
63- if ( input . key === "password" ) navigate ( `/reset-password` ) ;
64- else if ( input . key === "profile" ) navigate ( `/my-profile` ) ;
65- else if ( input . key === "logout" ) logout ( ) ;
66- } ;
67-
68- const menuSidebar = ( ) => (
69- < Menu onClick = { ( key ) => takeMenuAction ( key ) } >
70- < Menu . Item key = "password" > Change Password</ Menu . Item >
71- < Menu . Item key = "logout" >
72- < LogoutOutlined /> Logout
73- </ Menu . Item >
74- </ Menu >
75- ) ;
76-
7765 const takeNavigationAction = ( input : { key : string } ) => {
7866 if ( input . key === "dashboard" ) navigate ( `/` ) ;
7967 else if ( input . key === "shop" ) navigate ( `/shop` ) ;
8068 else if ( input . key === "forum" ) navigate ( `/forum` ) ;
8169 } ;
8270
71+ type MenuItem = Required < MenuProps > [ 'items' ] [ number ] ;
72+
73+ const menuitems : MenuItem [ ] = [ ]
74+ menuitems . push ( { key : "dashboard" , label : "Dashboard" } ) ;
75+ if ( role !== roleTypes . ROLE_MECHANIC ) {
76+ menuitems . push ( { key : "shop" , label : "Shop" } ) ;
77+ menuitems . push ( { key : "forum" , label : "Community" } ) ;
78+ }
79+
8380 const menuNavigation = ( ) => (
8481 < Menu
8582 onClick = { ( key ) => takeNavigationAction ( key ) }
8683 mode = "horizontal"
8784 theme = "dark"
88- >
89- < Menu . Item key = "dashboard" > Dashboard</ Menu . Item >
90- < Menu . Item key = "shop" > Shop</ Menu . Item >
91- < Menu . Item key = "forum" > Community</ Menu . Item >
92- </ Menu >
85+ items = { menuitems }
86+ />
9387 ) ;
9488
89+ const sideMenuItems : MenuProps [ 'items' ] = [
90+ { key : "profile" , label : "My Profile" , onClick : ( ) => navigate ( "/my-profile" ) , icon : < ProfileOutlined /> } ,
91+ { key : "password" , label : "Change Password" , onClick : ( ) => navigate ( "/reset-password" ) , icon : < EditOutlined /> } ,
92+ { key : "logout" , label : "Logout" , onClick : logout , icon : < LogoutOutlined /> } ,
93+ ]
94+
9595 return (
9696 < Header >
9797 < Space className = "top-nav-left" >
@@ -111,9 +111,9 @@ const Navbar: React.FC<NavbarProps> = (props) => {
111111 onClick = { ( ) => navigate ( "/my-profile" ) }
112112 />
113113 </ div >
114- < Dropdown overlay = { menuSidebar ( ) } placement = "bottomRight" >
114+ < Dropdown menu = { { items : sideMenuItems } } placement = "bottomRight" >
115115 < div className = "nav-items" >
116- < DownOutlined />
116+ < CaretDownOutlined />
117117 </ div >
118118 </ Dropdown >
119119 </ Space >
@@ -146,6 +146,7 @@ const mapStateToProps = (state: RootState) => ({
146146 name : state . userReducer . name ,
147147 isLoggedIn : state . userReducer . isLoggedIn ,
148148 profilePicData : state . profileReducer . profilePicData ,
149+ role : state . userReducer . role ,
149150} ) ;
150151
151152const mapDispatchToProps = {
0 commit comments