aboutsummaryrefslogtreecommitdiffstats
path: root/panel/src/components/Navbar.jsx
blob: 938e00acdd3f62b991f2cf0db1de4dbd9d64b0f4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import React, { useState } from 'react';
import { Link, useNavigate } from 'react-router-dom';
import MenuIcon from '@mui/icons-material/Menu';
import CloseIcon from '@mui/icons-material/Close';
import $ from 'jquery';
import 'magnific-popup';
import 'magnific-popup/dist/magnific-popup.css';
import './Navbar.css';

const Navbar = () => {
  const [isMenuOpen, setIsMenuOpen] = useState(false);
  const navigate = useNavigate();

  const handleLinkClick = (path) => {
    $.magnificPopup.close();
    setIsMenuOpen(false);
    navigate(path);
  };

  const toggleMenu = () => {
    if (!isMenuOpen) {
      $.magnificPopup.open({
        items: {
          src: '#navbar-popup',
          type: 'inline'
        },
        midClick: true,
        closeOnBgClick: true,
        callbacks: {
          open: () => setIsMenuOpen(true),
          close: () => setIsMenuOpen(false),
        },
      });
    } else {
      $.magnificPopup.close();
    }
  };

  return (
    <nav className="navbar">
      <div className="navbar-container">
        <div className="menu-icon" onClick={toggleMenu}>
          {isMenuOpen ? <CloseIcon /> : <MenuIcon />}
        </div>
        <ul className="navbar-list">
          <li className="navbar-item"><Link to="/dashboard">Dashboard</Link></li>
          <li className="navbar-item"><Link to="/manage-ads">Manage Ads</Link></li>
          <li className="navbar-item"><Link to="/roles">Roles</Link></li>
          <li className="navbar-item"><Link to="/logout">Logout</Link></li>
        </ul>
        <div id="navbar-popup" className="mfp-hide">
          <ul className="navbar-list-popup">
            <li className="navbar-item"><Link to="/dashboard" onClick={() => handleLinkClick('/dashboard')}>Dashboard</Link></li>
            <li className="navbar-item"><Link to="/manage-ads" onClick={() => handleLinkClick('/manage-ads')}>Manage Ads</Link></li>
            <li className="navbar-item"><Link to="/roles" onClick={() => handleLinkClick('/roles')}>Roles</Link></li>
            <li className="navbar-item"><Link to="/logout" onClick={() => handleLinkClick('/logout')}>Logout</Link></li>
          </ul>
        </div>
      </div>
    </nav>
  );
};

export default Navbar;