(inProps: UserMenuProps)
| 66 | * |
| 67 | */ |
| 68 | export const UserMenu = (inProps: UserMenuProps) => { |
| 69 | const props = useThemeProps({ |
| 70 | props: inProps, |
| 71 | name: PREFIX, |
| 72 | }); |
| 73 | const [anchorEl, setAnchorEl] = useState(null); |
| 74 | const translate = useTranslate(); |
| 75 | const { isPending, identity } = useGetIdentity(); |
| 76 | const authProvider = useAuthProvider(); |
| 77 | const isLargeEnough = useMediaQuery<Theme>(theme => |
| 78 | theme.breakpoints.up('sm') |
| 79 | ); |
| 80 | |
| 81 | const { |
| 82 | children = authProvider ? <Logout /> : null, |
| 83 | className, |
| 84 | label = 'ra.auth.user_menu', |
| 85 | icon = defaultIcon, |
| 86 | } = props; |
| 87 | |
| 88 | const handleMenu = event => setAnchorEl(event.currentTarget); |
| 89 | const handleClose = useCallback(() => setAnchorEl(null), []); |
| 90 | const context = useMemo(() => ({ onClose: handleClose }), [handleClose]); |
| 91 | if (!children) return null; |
| 92 | const open = Boolean(anchorEl); |
| 93 | |
| 94 | return ( |
| 95 | <Root className={className}> |
| 96 | {isLargeEnough && !isPending && identity?.fullName ? ( |
| 97 | <Button |
| 98 | aria-label={label && translate(label, { _: label })} |
| 99 | className={UserMenuClasses.userButton} |
| 100 | color="inherit" |
| 101 | startIcon={ |
| 102 | identity.avatar ? ( |
| 103 | <Avatar |
| 104 | className={UserMenuClasses.avatar} |
| 105 | src={identity.avatar} |
| 106 | alt={identity.fullName} |
| 107 | /> |
| 108 | ) : ( |
| 109 | icon |
| 110 | ) |
| 111 | } |
| 112 | onClick={handleMenu} |
| 113 | variant="text" |
| 114 | > |
| 115 | {identity.fullName} |
| 116 | </Button> |
| 117 | ) : ( |
| 118 | <Tooltip title={label && translate(label, { _: 'Profile' })}> |
| 119 | <IconButton |
| 120 | aria-label={label && translate(label, { _: 'Profile' })} |
| 121 | aria-owns={open ? 'menu-appbar' : undefined} |
| 122 | aria-haspopup={true} |
| 123 | color="inherit" |
| 124 | onClick={handleMenu} |
| 125 | > |
nothing calls this directly
no test coverage detected