Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 6632 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
6632 stevensc 1
import React, { useEffect, useRef, useState } from 'react'
2
import MoreVertIcon from '@mui/icons-material/MoreVert'
3
import useOutsideClick from '../../../../hooks/useOutsideClick'
4
 
6640 stevensc 5
import UserDropdown from './UserDropdown'
6
 
6632 stevensc 7
const UserImageDropdown = ({ fullName, image, linkAdmin, linkImpersonate }) => {
8
  const [sessionImage, setSessionImage] = useState(image)
9
  const [showUserDropdown, setShowUserDropdown] = useState(false)
10
  const userDropdownContainer = useRef(null)
11
 
6640 stevensc 12
  useOutsideClick(userDropdownContainer, () => setShowUserDropdown(false))
6632 stevensc 13
 
6640 stevensc 14
  const toggleDropdown = () => {
15
    setShowUserDropdown(!showUserDropdown)
16
  }
17
 
6632 stevensc 18
  const checkSessionImage = () => {
19
    const session_image = sessionStorage.getItem('user_session_image')
6640 stevensc 20
 
21
    if (!session_image) return
22
 
23
    setSessionImage(session_image)
24
    sessionStorage.removeItem('user_session_image')
6632 stevensc 25
  }
26
 
27
  useEffect(() => {
28
    const imageInterval = setInterval(() => checkSessionImage(), 1000)
6640 stevensc 29
 
6632 stevensc 30
    return () => {
31
      clearInterval(imageInterval)
32
    }
33
  }, [])
34
 
35
  useEffect(() => {
6640 stevensc 36
    setSessionImage(image)
37
  }, [image])
6632 stevensc 38
 
39
  return (
40
    <div
41
      className="userImgContainer"
6640 stevensc 42
      onClick={toggleDropdown}
6632 stevensc 43
      ref={userDropdownContainer}
44
    >
45
      <img src={sessionImage} alt="user-img" />
46
      <div className="d-inline-flex flex-column">
47
        <h3>{fullName}</h3>
48
        <span>Mi perfil</span>
49
      </div>
50
      <MoreVertIcon />
51
      <UserDropdown
6640 stevensc 52
        show={showUserDropdown}
6632 stevensc 53
        linkAdmin={linkAdmin}
54
        linkImpersonate={linkImpersonate}
55
      />
56
    </div>
57
  )
58
}
59
 
60
export default UserImageDropdown