Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3201 | Rev 3701 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 3201 Rev 3585
Línea 1... Línea 1...
1
import React, { useState } from 'react'
1
import React, { useState } from 'react';
2
import { Link, useNavigate } from 'react-router-dom'
2
import { Link, useNavigate } from 'react-router-dom';
3
import { Badge, styled } from '@mui/material'
3
import { Badge, styled } from '@mui/material';
4
 
4
 
5
import { useOutsideClick } from '@hooks'
5
import { useOutsideClick } from '@hooks';
6
 
6
 
7
import ListItemDropdown from './ListItemDropdown'
7
import ListItemDropdown from './ListItemDropdown';
8
 
8
 
9
import './Dropdowns.scss'
-
 
10
import { getAdminUrl } from '@app/services/admin'
9
import { getAdminUrl } from '@app/services/admin';
11
import { useDispatch } from 'react-redux'
10
import { useDispatch } from 'react-redux';
12
import { addNotification } from '@app/redux/notification/notification.actions'
11
import { addNotification } from '@app/redux/notification/notification.actions';
Línea 13... Línea 12...
13
 
12
 
14
const NavItem = styled(Link)(({ theme }) => ({
13
const NavItem = styled(Link)(({ theme }) => ({
15
  position: 'relative',
14
  position: 'relative',
16
  display: 'flex',
15
  display: 'flex',
Línea 38... Línea 37...
38
    minWidth: '60px'
37
    minWidth: '60px'
39
  },
38
  },
40
  [theme.breakpoints.down('md')]: {
39
  [theme.breakpoints.down('md')]: {
41
    fontSize: 0
40
    fontSize: 0
42
  }
41
  }
43
}))
42
}));
Línea 44... Línea 43...
44
 
43
 
45
const NavigationItem = ({
-
 
46
  ajax = 0,
-
 
47
  url = '',
-
 
48
  childs = [],
-
 
49
  count = 0,
-
 
50
  onClick,
-
 
51
  children
-
 
52
}) => {
44
const NavigationItem = ({ ajax = 0, url = '', childs = [], count = 0, onClick, children }) => {
Línea 53... Línea 45...
53
  const [displayMenu, setDisplayMenu] = useState(false)
45
  const [displayMenu, setDisplayMenu] = useState(false);
54
 
46
 
Línea 55... Línea 47...
55
  const navigate = useNavigate()
47
  const navigate = useNavigate();
Línea 56... Línea 48...
56
  const dispatch = useDispatch()
48
  const dispatch = useDispatch();
Línea 57... Línea 49...
57
 
49
 
58
  const [menu] = useOutsideClick(() => setDisplayMenu(false))
50
  const [menu] = useOutsideClick(() => setDisplayMenu(false));
59
 
51
 
60
  const toggleMenu = () => setDisplayMenu(!displayMenu)
52
  const toggleMenu = () => setDisplayMenu(!displayMenu);
61
 
53
 
62
  const openAdmin = async () => {
54
  const openAdmin = async () => {
63
    try {
55
    try {
64
      const adminUrl = await getAdminUrl(url)
56
      const adminUrl = await getAdminUrl(url);
Línea 65... Línea 57...
65
      window.open(adminUrl, '_blank')
57
      window.open(adminUrl, '_blank');
66
    } catch (error) {
58
    } catch (error) {
Línea 67... Línea 59...
67
      dispatch(addNotification({ style: 'danger', msg: error.message }))
59
      dispatch(addNotification({ style: 'danger', msg: error.message }));
68
    }
60
    }
69
  }
61
  };
70
 
62
 
Línea 71... Línea 63...
71
  const handleClick = async (e) => {
63
  const handleClick = async (e) => {
72
    e.preventDefault()
64
    e.preventDefault();
73
 
65
 
74
    if (ajax) {
66
    if (ajax) {
Línea 75... Línea 67...
75
      openAdmin()
67
      openAdmin();
76
      return
68
      return;
77
    }
69
    }
78
 
70
 
Línea 79... Línea 71...
79
    if (onClick) {
71
    if (onClick) {
80
      onClick()
72
      onClick();
Línea 81... Línea 73...
81
      return
73
      return;
82
    }
74
    }
83
 
-
 
84
    if (childs.length) {
-
 
85
      toggleMenu()
-
 
86
      return
75
 
87
    }
-
 
88
 
76
    if (childs.length) {
Línea 89... Línea 77...
89
    navigate(`/${url}`)
77
      toggleMenu();
90
  }
78
      return;
91
 
79
    }
92
  return (
80
 
93
    <li ref={menu}>
81
    navigate(`/${url}`);
94
      <NavItem
82
  };
Línea 95... Línea -...
95
        to={url}
-
 
96
        onClick={handleClick}
-
 
97
        className={displayMenu ? 'active' : ''}
-
 
98
      >
83
 
99
        {children}
-
 
100
 
84
  return (
101
        <Badge
85
    <li ref={menu}>
102
          badgeContent={count}
86
      <NavItem to={url} onClick={handleClick} className={displayMenu ? 'active' : ''}>
Línea 103... Línea 87...
103
          color='error'
87
        {children}