Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3727 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
3703 stevensc 1
import React, { useState } from 'react';
2
import { Link, useNavigate } from 'react-router-dom';
3
import { useSelector } from 'react-redux';
4
import { AppBar, Box, Container, Toolbar } from '@mui/material';
5
import Menu from '@mui/icons-material/Menu';
6
import Chat from '@mui/icons-material/Chat';
7
import Home from '@mui/icons-material/Home';
8
import Sell from '@mui/icons-material/Sell';
9
import School from '@mui/icons-material/School';
10
import People from '@mui/icons-material/People';
11
import Groups from '@mui/icons-material/Groups';
12
import BusinessCenter from '@mui/icons-material/BusinessCenter';
13
import Search from '@mui/icons-material/Search';
14
 
15
import { useNavbar } from '@hooks';
16
 
17
import MenuDrawer from './Drawer';
18
import NavigationItem from './navigation-item';
19
import UserOptions from './user-options';
20
import Input from '@components/UI/inputs/Input';
21
 
22
export default function Navbar() {
23
  const { menuData } = useNavbar();
24
 
25
  const {
26
    menu = [],
27
    image = '',
28
    fullName,
29
    linkAdmin,
30
    linkImpersonate,
31
    linkKnowledgeArea,
32
    routeKnowledgeArea,
33
    routeAbuseReport,
34
    urlImpersonate,
35
    urlAdmin,
36
    defaultNetwork
37
  } = menuData;
38
 
39
  const [showMenu, setShowMenu] = useState(false);
40
  const logo = useSelector(({ auth }) => auth.navbar_url);
41
  const labels = useSelector(({ intl }) => intl.labels);
42
  const navigate = useNavigate();
43
 
44
  const ICON_OPTIONS = [Home, People, BusinessCenter, Groups, Sell, Chat, School];
45
 
46
  const showDrawer = () => setShowMenu(true);
47
  const hideDrawer = () => setShowMenu(false);
48
 
49
  const handleSearch = ({ key, target }) => {
50
    if (key !== 'Enter') {
51
      return;
52
    }
53
 
54
    navigate(`/search/entity/user?keyword=${target.value}`);
55
    target.value = '';
56
    target.blur();
57
  };
58
 
59
  return (
60
    <>
61
      <AppBar
62
        sx={{
63
          position: 'sticky',
64
          boxShadow: 'none',
65
          borderBottom: '1px solid var(--border-primary)'
66
        }}
67
      >
68
        <Container>
69
          <Toolbar
70
            sx={{
71
              gap: 2,
72
              minHeight: 'none',
73
              paddingLeft: 0,
74
              paddingRight: 0
75
            }}
76
          >
77
            <Box
78
              sx={{
79
                display: 'flex',
80
                alignItems: 'center',
81
                gap: { xs: 0, md: 2 },
82
                flexGrow: 1,
83
                '& img': {
84
                  display: { xs: 'none', md: 'block' },
85
                  height: { xs: '50px', md: '60px' },
86
                  width: { xs: '50px', md: '60px' }
87
                }
88
              }}
89
            >
90
              <Link to='/'>
91
                <img src={logo} alt='Logo' />
92
              </Link>
93
              <Input
94
                placeholder={labels.search}
95
                icon={<Search />}
96
                variant='search'
97
                onKeyDown={handleSearch}
98
              />
99
            </Box>
100
 
101
            <Box
102
              sx={{
103
                alignItems: 'center',
104
                display: 'flex',
105
                '& > ul': {
106
                  display: 'flex',
107
                  flex: 1,
108
                  justifyContent: 'space-evenly',
109
                  gap: { xs: 1, md: 2 },
110
                  '& > li': {
111
                    position: 'relative',
112
                    display: 'flex',
3719 stevensc 113
                    '&:not(:nth-last-of-type(-n + 4))': {
3703 stevensc 114
                      display: { xs: 'none', md: 'flex' }
115
                    },
3719 stevensc 116
                    '&:nth-last-of-type(-n + 1)': {
3703 stevensc 117
                      display: { xs: 'flex', md: 'none' }
118
                    }
119
                  }
120
                }
121
              }}
122
            >
123
              <ul>
124
                {menu.map(({ label, href, childs }, index) => {
125
                  const Icon = ICON_OPTIONS[index];
126
 
127
                  return (
128
                    <NavigationItem key={index} url={href} childs={childs}>
129
                      <Icon />
130
                      {label}
131
                    </NavigationItem>
132
                  );
133
                })}
134
 
135
                <UserOptions
136
                  image={image}
137
                  name={fullName}
138
                  adminUrl={linkAdmin}
139
                  impersonateUrl={linkImpersonate}
140
                  defaultNetwork={defaultNetwork}
141
                  knowledgeAuth={linkKnowledgeArea}
142
                  routeKnowledge={routeKnowledgeArea}
143
                  routeAdmin={urlAdmin}
144
                  routeImpersonate={urlImpersonate}
145
                  routeAbuseReport={routeAbuseReport}
146
                />
147
 
148
                <NavigationItem onClick={showDrawer}>
149
                  <Menu />
150
                </NavigationItem>
151
              </ul>
152
            </Box>
153
          </Toolbar>
154
        </Container>
155
      </AppBar>
156
 
157
      <MenuDrawer items={menu} show={showMenu} onClose={hideDrawer} />
158
    </>
159
  );
160
}