Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 6847 | 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'
6796 stevensc 2
import { Link } from 'react-router-dom'
6753 stevensc 3
import { axios } from '../../../utils'
6632 stevensc 4
import useOutsideClick from '../../../hooks/useOutsideClick'
6753 stevensc 5
 
6632 stevensc 6
import ListItemDropdown from './ListItemDropdown'
6753 stevensc 7
 
6632 stevensc 8
import './HeaderOptions.scss'
9
import './Dropdowns.scss'
6840 stevensc 10
import Badge from '../../UI/Badge'
6632 stevensc 11
 
12
const HeaderOptions = ({
13
  Icon = null,
14
  title = '',
15
  url = '',
16
  childs = [],
17
  ajaxRequest = 0,
18
  isMobile = false,
6848 stevensc 19
  count,
6632 stevensc 20
}) => {
21
  const [displayMenu, setDisplayMenu] = useState(false)
22
  const menu = useRef(null)
6753 stevensc 23
  useOutsideClick(menu, () => setDisplayMenu(false))
6632 stevensc 24
 
6796 stevensc 25
  const handleClick = (e) => {
26
    e.preventDefault()
6632 stevensc 27
    setDisplayMenu(!displayMenu)
28
  }
29
 
6796 stevensc 30
  const handleAjaxRequest = async (e) => {
6632 stevensc 31
    try {
6796 stevensc 32
      e.preventDefault()
6632 stevensc 33
      const { data } = await axios.get(url)
34
      if (data.success) {
35
        window.open(data.data, 'backend')
36
      }
37
    } catch (error) {
38
      console.log('>>: error > ', error)
39
    }
40
  }
41
 
42
  return (
43
    <li ref={menu} className={!isMobile && 'd-none d-lg-block'}>
6796 stevensc 44
      <Link
45
        to={`/${url}`}
6632 stevensc 46
        className={`header__option ${isMobile && 'mobile'} ${
47
          displayMenu && 'active'
48
        }`}
49
        onClick={(e) => {
6796 stevensc 50
          if (ajaxRequest) handleAjaxRequest(e)
51
          if (childs.length) handleClick(e)
6632 stevensc 52
        }}
53
      >
54
        {Icon && <Icon className="header__option-icon" />}
55
        <span>{title}</span>
6848 stevensc 56
        {Boolean(count) && <Badge count={count} />}
6796 stevensc 57
      </Link>
6632 stevensc 58
      <ListItemDropdown isShow={displayMenu} options={childs} />
59
    </li>
60
  )
61
}
62
 
63
export default HeaderOptions