/******************************************************************************** * Copyright (c) 2019 TypeFox and others * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. * * SPDX-License-Identifier: EPL-2.0 ********************************************************************************/ import { FunctionComponent, useContext, useRef, useState } from 'react'; import { Avatar, Menu, Typography, MenuItem, Link, Divider, IconButton } from '@mui/material'; import { Link as RouteLink } from 'react-router-dom'; import { UserSettingsRoutes } from './user-settings-routes'; import { AdminDashboardRoutes } from '../admin-dashboard/admin-dashboard-routes'; import { MainContext } from '../../context'; import { LogoutForm } from './logout'; export const UserAvatar: FunctionComponent = () => { const [open, setOpen] = useState(false); const context = useContext(MainContext); const avatarButton = useRef(); const logoutFormRef = useRef(null); const handleAvatarClick = () => { setOpen(!open); }; const handleClose = () => { setOpen(false); }; const user = context.user; if (!user) { return null; } return <> avatarButton.current = ref} > Logged in as {user.loginName} Settings { user.role && user.role === 'admin' ? Admin Dashboard : '' } logoutFormRef.current?.submit()}> Log Out ; };