Proyectos de Subversion LeadersLinked - SPA

Rev

| Ultima modificación | Ver Log |

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