Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 4250 | Rev 5455 | 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 */
2
import React, { useEffect, useRef, useState } from 'react'
5397 stevensc 3
import UserDropdown from './UserDropdown'
4250 stevensc 4
 
5
const UserImageDropdown = ({ fullName, image, linkAdmin, linkImpersonate, sessionImage }) => {
5397 stevensc 6
  const [showUserDropdown, setShowUserDropdown] = useState(false)
7
  const userDropdownContainer = useRef(null)
8
  const userImg = useRef(null)
4250 stevensc 9
 
5397 stevensc 10
  const handleShowUserDropdown = () => setShowUserDropdown(!showUserDropdown)
4250 stevensc 11
 
5397 stevensc 12
  useEffect(() => {
13
    const handleClickOutside = (event) => {
14
      if (userDropdownContainer.current && !userDropdownContainer.current.contains(event.target)) {
15
        setShowUserDropdown(false)
16
      }
17
    }
18
    document.addEventListener('mousedown', handleClickOutside)
4250 stevensc 19
 
5397 stevensc 20
    return () => {
21
      document.removeEventListener('mousedown', handleClickOutside)
22
    }
23
  }, [userDropdownContainer])
4250 stevensc 24
 
5397 stevensc 25
  return (
4250 stevensc 26
        <div
27
            className='userImgContainer'
28
            onClick={handleShowUserDropdown}
29
            ref={userDropdownContainer}
30
        >
31
            <div className="d-flex align-items-center">
32
                <img
5397 stevensc 33
                    src={sessionImage || image}
4250 stevensc 34
                    alt="user-img"
35
                    className='userImg'
36
                    ref={userImg}
37
                />
38
                <div className="d-none d-sm-none d-md-inline-flex d-lg-inline-flex flex-column">
39
                    <h3>{fullName}</h3>
40
                    <span>Mi perfil</span>
41
                </div>
42
            </div>
43
            <div className="d-none d-sm-none d-md-block d-lg-block flex-column">
44
                <img src='/images/icons/options.png' className='img-icon options-lg' />
45
            </div>
46
 
47
            <UserDropdown
48
                linkAdmin={linkAdmin}
49
                linkImpersonate={linkImpersonate}
50
                show={showUserDropdown}
51
                onClose={handleShowUserDropdown}
52
                userDropdownContainer={userDropdownContainer}
53
            />
54
        </div>
5397 stevensc 55
  )
4250 stevensc 56
}
57
 
5397 stevensc 58
export default UserImageDropdown