Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

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