import PropTypes from 'prop-types' import { createElement, useContext, useEffect } from 'react' import { Flex, Typography, Button, Space, Divider, Card } from 'antd' import { UserOutlined } from '@ant-design/icons' import { useNavigate, useLocation } from 'react-router-dom' import LogoutIcon from '../../Icons/LogoutIcon' import { User } from '../../../database/models/User' import { buildActionUrl } from '../../../utils/modelActions' import { AuthContext } from '../context/AuthContext' import ObjectActions from './ObjectActions' import ElipsisText from './ElipsisText' const { Text } = Typography const ICON_ACTION_NAMES = ['info', 'edit'] const UserProfilePopover = ({ onClose }) => { const { userProfile, profileImageUrl, logout } = useContext(AuthContext) const navigate = useNavigate() const location = useLocation() const modelActions = User.actions || [] const iconActions = modelActions.filter((a) => ICON_ACTION_NAMES.includes(a.name) ) const objectData = { ...userProfile, _user: userProfile } useEffect(() => { onClose?.() // eslint-disable-next-line react-hooks/exhaustive-deps }, [location.pathname, location.search]) const runAction = (action) => { if (action.name === 'logout') { logout() } else if (userProfile?._id) { const url = buildActionUrl(User, action, userProfile._id, '', '') navigate(url) } onClose?.() } const isActionDisabled = (action) => { if (action.disabled && typeof action.disabled === 'function') { return action.disabled(objectData) } return false } const username = userProfile?.username const fullName = [userProfile?.firstName, userProfile?.lastName] .filter(Boolean) .join(' ') const email = userProfile?.email return ( {profileImageUrl ? ( ) : ( )} {fullName && ( {fullName} )} {email && ( @{username} {email} )} {!username && !fullName && !email && ( Unknown user )} {iconActions.map((action) => (