Changeset b248810 for jobvista-frontend/src/views/static
- Timestamp:
- 06/10/24 22:34:32 (5 months ago)
- Branches:
- main
- Children:
- befb988
- Parents:
- 28b3398
- Location:
- jobvista-frontend/src/views/static
- Files:
-
- 3 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
jobvista-frontend/src/views/static/Header.js
r28b3398 rb248810 1 1 import {Link, NavLink} from "react-router-dom"; 2 2 import "./Header.css" 3 import { jwtDecode } from "jwt-decode"; 3 4 import {useDispatch, useSelector} from 'react-redux'; 4 5 import {useEffect, useState} from "react"; … … 6 7 import Roles from "../../enumerations/Roles"; 7 8 import {useNavigate} from "react-router"; 9 import {AUTH_TOKEN} from "../../axios/axiosInstance"; 8 10 9 11 export const Header = (props) => { … … 16 18 const [username, setUsername] = useState(""); 17 19 20 const [user, setUser] = useState(""); 21 18 22 const signOut = () => { 19 23 dispatch(AuthActions.signOut()); 20 24 window.location = "/"; 21 25 } 26 27 useEffect(() => { 28 const token = localStorage.getItem(AUTH_TOKEN); 29 if (token!=null) { 30 try { 31 const decodedToken = jwtDecode(token); 32 setUser({ 33 name: decodedToken.name, 34 role: decodedToken.role, 35 hasAccess: decodedToken.hasAccess, 36 }); 37 } catch (error) { 38 console.error('Failed to decode token', error); 39 } 40 } 41 }, [auth]); 22 42 23 43 useEffect(() => { … … 49 69 </> 50 70 } 71 {role===Roles.ADMIN && 72 <> 73 <NavLink to="/admin-panel" className="nav-item nav-link">Admin Panel</NavLink> 74 </> 75 76 } 51 77 <NavLink to="/about" className="nav-item nav-link">About</NavLink> 52 78 <NavLink to="/contact" className="nav-item nav-link">Support</NavLink> … … 57 83 <img src="/images/user.png" width="45" height="45"/> 58 84 <div className="auth-box"> 59 <p className="user"><b>{username}</b></p> 60 <p className="role">{role==Roles.RECRUITER ? "Recruiter" : "Job Seeker"}</p> 85 <p className="user"><b>{user.name}</b></p> 86 {user.role==Roles.RECRUITER && <p className="role">Recruiter</p>} 87 {user.role==Roles.JOBSEEKER && <p className="role">Job Seeker</p>} 88 {user.role==Roles.ADMIN && <p className="role">Admin</p>} 89 {/*<p className="role">{user.role==Roles.RECRUITER ? "Recruiter" : "Job Seeker"}</p>*/} 61 90 </div> 62 91
Note:
See TracChangeset
for help on using the changeset viewer.