Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev 4964 Rev 6094
Línea 1... Línea 1...
1
/* eslint-disable react/prop-types */
1
/* eslint-disable react/prop-types */
2
import React, { useEffect, useRef, useState } from 'react'
2
import React, { useEffect, useRef, useState } from 'react'
3
import Avatar from '../../../shared/Avatar/Avatar'
3
import Avatar from '../../../shared/Avatar/Avatar'
4
import axios from '../../../utils/axios'
4
import axios from '../../../utils/axios'
5
import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown';
5
import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown'
Línea 6... Línea 6...
6
 
6
 
7
const UserOptions = ({
7
const UserOptions = ({
8
    image = '',
8
  image = '',
9
    name = '',
9
  name = '',
10
    adminUrl = '',
10
  adminUrl = '',
11
    impersonateUrl = '',
11
  impersonateUrl = '',
12
    defaultNetwork = 'y'
12
  defaultNetwork = 'y',
13
}) => {
13
}) => {
14
    const [displayOptions, setDisplayOptions] = useState(false)
14
  const [displayOptions, setDisplayOptions] = useState(false)
Línea 15... Línea 15...
15
    const userDropdownContainer = useRef(null);
15
  const userDropdownContainer = useRef(null)
16
 
16
 
17
    useEffect(() => {
-
 
18
        const handleClickOutside = (event) => {
-
 
19
            if (userDropdownContainer?.current && !userDropdownContainer?.current?.contains(event.target)) {
-
 
20
                setDisplayOptions(false)
17
  useEffect(() => {
21
            }
18
    const handleClickOutside = (event) => {
22
        }
-
 
23
        document.addEventListener("mousedown", handleClickOutside);
-
 
24
 
19
      if (
25
        return () => {
20
        userDropdownContainer?.current &&
26
            document.removeEventListener("mousedown", handleClickOutside);
21
        !userDropdownContainer?.current?.contains(event.target)
27
        };
-
 
28
    }, [userDropdownContainer]);
-
 
29
 
22
      ) {
30
    const handleDisplay = async (e) => {
-
 
31
        e.preventDefault()
23
        setDisplayOptions(false)
-
 
24
      }
Línea 32... Línea -...
32
        setDisplayOptions(!displayOptions)
-
 
33
    }
-
 
34
 
25
    }
35
    const getAdminUrl = async (e) => {
26
    document.addEventListener('mousedown', handleClickOutside)
36
        e.preventDefault()
-
 
37
        try {
-
 
38
            const { data } = await axios.get('/backend/signin-admin')
-
 
39
            if (data.success) return window.open(data.data);
-
 
40
        } catch (error) {
27
 
-
 
28
    return () => {
Línea -... Línea 29...
-
 
29
      document.removeEventListener('mousedown', handleClickOutside)
41
            console.log('>>: error > ', error)
30
    }
-
 
31
  }, [userDropdownContainer])
-
 
32
 
-
 
33
  const handleDisplay = async (e) => {
-
 
34
    e.preventDefault()
42
        }
35
    setDisplayOptions(!displayOptions)
43
    }
36
  }
44
 
37
 
45
    return (
38
  const getAdminUrl = async (e) => {
-
 
39
    e.preventDefault()
46
        <li>
40
    try {
47
            <a
41
      const { data } = await axios.get('/backend/signin-admin')
-
 
42
      if (data.success) return window.open(data.data)
-
 
43
    } catch (error) {
48
                href="#"
44
      console.log('>>: error > ', error)
49
                className="header__option mobile"
45
    }
50
                onClick={handleDisplay}
46
  }
51
            >
47
 
52
                <Avatar
48
  return (
53
                    imageUrl={image}
49
    <li>
54
                    name={name}
50
      <a href="#" className="header__option mobile" onClick={handleDisplay}>
55
                    size='md'
-
 
-
 
51
        <Avatar imageUrl={image} name={name} size="md" />
-
 
52
        <span>
56
                />
53
          Me <ArrowDropDownIcon className="user__option-icon" />
57
                <span>Me <ArrowDropDownIcon className='user__option-icon' /></span>
54
        </span>
58
            </a>
55
      </a>
59
            <div className={`user__options-dropdown ${displayOptions ? 'fadeIn' : 'fadeOut'}`} ref={userDropdownContainer}>
56
      <div
-
 
57
        className={`user__options-dropdown ${
60
                <div className='user__options-description'>
58
          displayOptions ? 'fadeIn' : 'fadeOut'
61
                    <div className='user__options-info'>
59
        }`}
62
                        <Avatar
60
        ref={userDropdownContainer}
63
                            imageUrl={image}
61
      >
64
                            name={name}
62
        <div className="user__options-description">
65
                            size='xl'
63
          <div className="user__options-info">
66
                        />
64
            <Avatar imageUrl={image} name={name} size="xl" />
67
                        <h3>{name}</h3>
65
            <h3>{name}</h3>
68
                    </div>
66
          </div>
69
                    {/* <a href='#' className='btn__profile'>
67
          {/* <a href='#' className='btn__profile'>
70
                        View profile
68
                        View profile
71
                    </a> */}
69
                    </a> */}
72
                </div>
70
        </div>
73
                {(adminUrl || impersonateUrl) &&
71
        {(adminUrl || impersonateUrl) && (
74
                    <div className='user__options-item'>
72
          <div className="user__options-item">
75
                        <h3>Admin</h3>
73
            <h3>Admin</h3>
76
                        <ul>
74
            <ul>
77
                            {adminUrl &&
75
              {adminUrl && (
-
 
76
                <li>
-
 
77
                  <a href="#" onClick={getAdminUrl}>
78
                                <li>
78
                    Administración
79
                                    <a href="#" onClick={getAdminUrl} >Administración</a>
79
                  </a>
80
                                </li>
80
                </li>
81
                            }
81
              )}
82
                            {impersonateUrl &&
82
              {impersonateUrl && (
83
                                <li>
83
                <li>
84
                                    <a href="/impersonate">Personificar otro usuario</a>
84
                  <a href="/impersonate">Personificar otro usuario</a>
85
                                </li>
85
                </li>
86
                            }
86
              )}
87
                        </ul>
87
            </ul>
88
                    </div>
88
          </div>
89
                }
89
        )}
90
                <div className='user__options-item'>
90
        <div className="user__options-item">
-
 
91
          <h3>Cuenta</h3>
91
                    <h3>Cuenta</h3>
92
          <ul>
-
 
93
            <li>
92
                    <ul>
94
              <a href="/account-settings" target="secondary">
93
                        <li>
95
                Configuración de la cuenta
94
                            <a href="/account-settings" target='secondary'>Configuración de la cuenta</a>
96
              </a>
95
                        </li>
97
            </li>
96
                        {defaultNetwork === 'y' &&
98
            {defaultNetwork === 'y' && (
97
                            <>
99
              <>
-
 
100
                <li>
-
 
101
                  <a href="/privacy-policy" target="secondary">
98
                                <li>
102
                    Política de privacidad
99
                                    <a href="/privacy-policy" target='secondary'>Política de privacidad</a>
103
                  </a>
100
                                </li>
104
                </li>
101
                                <li>
105
                <li>
102
                                    <a href="/cookies" target='secondary'>Política de cookies</a>
106
                  <a href="/cookies" target="secondary">
-
 
107
                    Política de cookies
-
 
108
                  </a>
103
                                </li>
109
                </li>
104
                            </>
110
              </>
105
                        }
111
            )}
106
                    </ul>
112
          </ul>
107
                </div>
113
        </div>
108
                <div className='user__options-item'>
114
        <div className="user__options-item">
109
                    <ul>
115
          <ul>
110
                        <li className='logOutContainer'>
116
            <li className="logOutContainer">
111
                            <a className='logOutContainer__a' href="/signout">
117
              <a className="logOutContainer__a" href="/signout">
112
                                Cerrar sesión
118
                Cerrar sesión
113
                            </a>
119
              </a>
114
                        </li>
120
            </li>
115
                    </ul>
121
          </ul>
116
                </div>
122
        </div>
Línea 117... Línea -...
117
            </div >
-
 
118
        </li >
123
      </div>
-
 
124
    </li>