source: frontend/src/components/Navbar.js@ cb0881d

Last change on this file since cb0881d was cb0881d, checked in by MBK <marija.karapandzova@…>, 4 months ago

Set up React frontend and add design styles

  • Property mode set to 100644
File size: 6.2 KB
Line 
1import React, { useState, useEffect } from 'react';
2import { Link, useNavigate, useLocation } from 'react-router-dom';
3
4function Navbar() {
5 const [user, setUser] = useState(null);
6 const [showMenu, setShowMenu] = useState(false);
7 const navigate = useNavigate();
8 const location = useLocation();
9
10 useEffect(() => {
11 const userStr = localStorage.getItem('user');
12 if (userStr) {
13 setUser(JSON.parse(userStr));
14 }
15 }, []);
16
17 const handleLogout = () => {
18 localStorage.removeItem('token');
19 localStorage.removeItem('user');
20 setUser(null);
21 navigate('/login');
22 };
23
24 const isActive = (path) => location.pathname === path;
25
26 const getInitials = () => {
27 if (!user) return '';
28 return `${user.firstName?.[0]}${user.lastName?.[0]}`.toUpperCase();
29 };
30
31 return (
32 <nav className="navbar">
33 <div className="navbar-brand">
34 <img src="/logo.png" alt="Medora Logo" style={{ height: '40px', width: 'auto' }} />
35 </div>
36
37 <div className="navbar-links">
38 <Link to="/" className={`navbar-link ${isActive('/') ? 'active' : ''}`}>
39 Overview
40 </Link>
41 {user?.role !== 'PATIENT' && user?.role !== 'LAB_TECHNICIAN' && user?.role !== 'BILLING_ADMIN' && (
42 <Link to="/patients" className={`navbar-link ${isActive('/patients') ? 'active' : ''}`}>
43 Patients
44 </Link>
45 )}
46 <Link to="/doctors" className={`navbar-link ${isActive('/doctors') ? 'active' : ''}`}>
47 Doctors
48 </Link>
49 <Link to="/departments" className={`navbar-link ${isActive('/departments') ? 'active' : ''}`}>
50 Departments
51 </Link>
52 {user?.role !== 'LAB_TECHNICIAN' && user?.role !== 'BILLING_ADMIN' && (
53 <>
54 <Link to="/appointments" className={`navbar-link ${isActive('/appointments') ? 'active' : ''}`}>
55 Appointments
56 </Link>
57 {user?.role === 'PATIENT' && (
58 <>
59 <Link to="/medical-records" className={`navbar-link ${isActive('/medical-records') ? 'active' : ''}`}>
60 Medical Records
61 </Link>
62 <Link to="/billing" className={`navbar-link ${isActive('/billing') ? 'active' : ''}`}>
63 Billing
64 </Link>
65 </>
66 )}
67 </>
68 )}
69 {(user?.role === 'ADMIN' || user?.role === 'LAB_TECHNICIAN' || user?.role === 'DOCTOR') && (
70 <Link to="/lab-tests" className={`navbar-link ${isActive('/lab-tests') ? 'active' : ''}`}>
71 Lab Tests
72 </Link>
73 )}
74 {!user?.role || user?.role === 'ADMIN' || user?.role === 'DOCTOR' ? (
75 <>
76 {user?.role !== 'LAB_TECHNICIAN' && user?.role !== 'BILLING_ADMIN' && (
77 <Link to="/medical-records" className={`navbar-link ${isActive('/medical-records') ? 'active' : ''}`}>
78 Medical Records
79 </Link>
80 )}
81 {user?.role !== 'PATIENT' && user?.role !== 'LAB_TECHNICIAN' && user?.role !== 'BILLING_ADMIN' && (
82 <>
83 <Link to="/medical-reports" className={`navbar-link ${isActive('/medical-reports') ? 'active' : ''}`}>
84 Medical Reports
85 </Link>
86 <Link to="/procedures" className={`navbar-link ${isActive('/procedures') ? 'active' : ''}`}>
87 Procedures
88 </Link>
89 <Link to="/referrals" className={`navbar-link ${isActive('/referrals') ? 'active' : ''}`}>
90 Referrals
91 </Link>
92 </>
93 )}
94 </>
95 ) : null}
96 {(user?.role === 'ADMIN' || user?.role === 'BILLING_ADMIN') && (
97 <Link to="/billing" className={`navbar-link ${isActive('/billing') ? 'active' : ''}`}>
98 Billing
99 </Link>
100 )}
101 </div>
102
103 <div className="navbar-right">
104 {user && (
105 <div className="navbar-avatar" style={{ position: 'relative' }}>
106 <div className="navbar-avatar-circle">{getInitials()}</div>
107 <div className="navbar-avatar-name">{user.firstName}</div>
108 <button
109 onClick={() => setShowMenu(!showMenu)}
110 style={{
111 background: 'none',
112 border: 'none',
113 cursor: 'pointer',
114 marginLeft: '4px',
115 color: 'var(--color-neutral-600)',
116 fontSize: '12px'
117 }}
118 >
119
120 </button>
121 {showMenu && (
122 <div style={{
123 position: 'absolute',
124 top: '100%',
125 right: 0,
126 background: 'white',
127 border: '1px solid var(--color-neutral-400)',
128 borderRadius: '6px',
129 minWidth: '150px',
130 marginTop: '4px',
131 boxShadow: '0 4px 6px rgba(0,0,0,0.1)',
132 zIndex: 1000
133 }}>
134 <div style={{
135 padding: '8px 0',
136 fontSize: '11px',
137 color: 'var(--color-neutral-600)',
138 borderBottom: '1px solid var(--color-neutral-400)',
139 paddingLeft: '12px',
140 paddingRight: '12px',
141 paddingTop: '8px',
142 paddingBottom: '8px'
143 }}>
144 {user.role}
145 </div>
146 <button
147 onClick={handleLogout}
148 style={{
149 width: '100%',
150 padding: '8px 12px',
151 background: 'none',
152 border: 'none',
153 textAlign: 'left',
154 cursor: 'pointer',
155 fontSize: '12px',
156 color: 'var(--color-status-red)',
157 transition: 'background 0.2s'
158 }}
159 onMouseEnter={(e) => e.target.style.background = 'var(--color-neutral-200)'}
160 onMouseLeave={(e) => e.target.style.background = 'none'}
161 >
162 Logout
163 </button>
164 </div>
165 )}
166 </div>
167 )}
168 </div>
169 </nav>
170 );
171}
172
173export default Navbar;
Note: See TracBrowser for help on using the repository browser.