Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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