Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 6632 | Rev 6796 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
6753 stevensc 1
import React, { useRef, useState } from 'react'
2
import { axios } from '../../../utils'
6632 stevensc 3
import useOutsideClick from '../../../hooks/useOutsideClick'
6753 stevensc 4
 
6632 stevensc 5
import ListItemDropdown from './ListItemDropdown'
6753 stevensc 6
 
6632 stevensc 7
import './HeaderOptions.scss'
8
import './Dropdowns.scss'
9
 
10
const HeaderOptions = ({
11
  Icon = null,
12
  title = '',
13
  url = '',
14
  childs = [],
15
  ajaxRequest = 0,
16
  isMobile = false,
17
  badgeCount = 0,
18
}) => {
19
  const [displayMenu, setDisplayMenu] = useState(false)
20
  const menu = useRef(null)
6753 stevensc 21
  useOutsideClick(menu, () => setDisplayMenu(false))
6632 stevensc 22
 
23
  const handleClick = () => {
24
    setDisplayMenu(!displayMenu)
25
  }
26
 
27
  const handleAjaxRequest = async () => {
28
    try {
29
      const { data } = await axios.get(url)
30
      if (data.success) {
31
        window.open(data.data, 'backend')
32
      }
33
    } catch (error) {
34
      console.log('>>: error > ', error)
35
    }
36
  }
37
 
38
  return (
39
    <li ref={menu} className={!isMobile && 'd-none d-lg-block'}>
40
      <a
41
        href={`/${url}`}
42
        className={`header__option ${isMobile && 'mobile'} ${
43
          displayMenu && 'active'
44
        }`}
45
        onClick={(e) => {
46
          if (ajaxRequest) {
47
            e.preventDefault()
48
            handleAjaxRequest()
49
            return
50
          }
51
          if (childs.length) {
52
            e.preventDefault()
53
            handleClick()
54
          }
55
        }}
56
        target="framename"
57
      >
58
        {Icon && <Icon className="header__option-icon" />}
59
        <span>{title}</span>
60
        <span
61
          className={`badge ${badgeCount ? 'd-block' : 'd-none'}`}
62
          style={{ top: '10px' }}
63
        >
64
          {badgeCount}
65
        </span>
66
      </a>
67
      <ListItemDropdown isShow={displayMenu} options={childs} />
68
    </li>
69
  )
70
}
71
 
72
export default HeaderOptions