Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev Autor Línea Nro. Línea
6694 stevensc 1
import React from 'react'
2
import { axios } from '../../../../utils'
3
import { Link } from 'react-router-dom'
4
 
6796 stevensc 5
const LinkItem = ({ href, ajax, childs, icon, label }) => {
6694 stevensc 6
  const handleAjaxRequest = async (event, url) => {
7
    event.preventDefault()
8
    try {
9
      const { data } = await axios.get(url)
10
      if (data.success) window.open(data.data, '_backend')
11
    } catch (error) {
12
      console.log('>>: error > ', error)
6753 stevensc 13
      throw new Error(error)
6694 stevensc 14
    }
15
  }
16
 
17
  return (
6695 stevensc 18
    <>
6694 stevensc 19
      <Link
20
        to={`/${href}`}
21
        onClick={(e) => {
22
          if (ajax) {
23
            handleAjaxRequest(e, href)
24
            return
25
          }
26
 
27
          if (childs.length) {
28
            e.preventDefault()
29
          }
30
        }}
31
      >
6796 stevensc 32
        {icon}
6694 stevensc 33
        <p>{label}</p>
34
      </Link>
35
      {Boolean(childs.length) && (
36
        <nav className="navLinkDropdown">
37
          <ul>
38
            {childs.map((child, _i) => (
39
              <li key={_i}>
40
                <Link
41
                  to={`/${child.href}`}
42
                  onClick={(e) => child.childs?.length && e.preventDefault()}
43
                >
44
                  {child.label}
45
                  {Boolean(child.childs?.length) && (
46
                    <i className="fa fa-angle-right" />
47
                  )}
48
                </Link>
49
                {Boolean(child.childs?.length) && (
50
                  <nav className="navigation-level_three">
51
                    <ul>
52
                      {child.childs?.map((levelThree, index) => (
53
                        <li key={index}>
6707 stevensc 54
                          <Link to={`/${levelThree.href}`}>
55
                            {levelThree.label}
56
                          </Link>
6694 stevensc 57
                        </li>
58
                      ))}
59
                    </ul>
60
                  </nav>
61
                )}
62
              </li>
63
            ))}
64
          </ul>
65
        </nav>
66
      )}
6695 stevensc 67
    </>
6694 stevensc 68
  )
69
}
70
 
71
export default LinkItem