import React, { useState, useEffect, useContext } from 'react' import { Link, useHistory, useLocation } from 'react-router-dom' import { AppBar, Toolbar, Tabs, Tab, Button, Menu, MenuItem } from '@mui/material' import OpenInNewIcon from '@mui/icons-material/OpenInNew' import SettingsIcon from '@mui/icons-material/Settings' import Username from './username' import { AppContext } from '../context/appContext' const NODE_ENV = process.env.NODE_ENV const PORT_API = process.env.PORT_API const baseUrl = NODE_ENV === 'development' ? `http://localhost:${PORT_API ?? 5000}` : '' const validTabs = ['/', '/SASjsDrive', '/SASjsStudio'] const Header = (props: any) => { const history = useHistory() const { pathname } = useLocation() const appContext = useContext(AppContext) const [tabValue, setTabValue] = useState( validTabs.includes(pathname) ? pathname : '/' ) const [anchorEl, setAnchorEl] = useState< (EventTarget & HTMLButtonElement) | null >(null) useEffect(() => { setTabValue(validTabs.includes(pathname) ? pathname : '/') }, [pathname]) const handleMenu = ( event: React.MouseEvent ) => { setAnchorEl(event.currentTarget) } const handleClose = () => { setAnchorEl(null) } const handleTabChange = (event: React.SyntheticEvent, value: string) => { setTabValue(value) } const handleLogout = () => { if (appContext.logout) { handleClose() appContext.logout() } } return ( theme.zIndex.drawer + 1 }} > logo { setTabValue('/') history.push('/') }} />
) } export default Header