import { DashboardOutlined, GithubOutlined, LoginOutlined, LogoutOutlined, MenuOutlined, SettingOutlined, UserOutlined, UserSwitchOutlined, WarningOutlined } from '@ant-design/icons' import { Button, Checkbox, Form, Layout, Menu, Modal, Popover, Tag, Typography } from 'antd' import Avatar from 'antd/lib/avatar/avatar' import React, { useState } from 'react' import { useThemeSwitcher } from 'react-css-theme-switcher' import { useHistory } from 'react-router' import { Link, useLocation } from 'react-router-dom' import { apiUrl, req } from '../../utils/Fetcher' interface Props { user?: any } const Navbar: React.FC = ({ user }) => { const history = useHistory() const { pathname } = useLocation() const { currentTheme } = useThemeSwitcher() const [logoutConfirmation, setLogoutConfirmation] = useState(false) const [popoverVisibility, setPopoverVisibility] = useState(false) const [destroySession, setDestroySession] = useState(false) // const { data: usage } = useSWR('/users/me/usage', fetcher) const logout = async () => { await req.post('/auth/logout', {}, destroySession ? { params: { destroySession: 1 } } : undefined) window.localStorage.removeItem('experimental') return window.location.replace('/') } return <>
{/\/startup/.test(pathname) ? : }
{!/\/startup/.test(pathname) && <> {user ? <>{/\/dashboard/.test(pathname) || /\/settings/.test(pathname) || /\/admin/.test(pathname) ? <>
Bandwidth: { } Unlimited
{ setPopoverVisibility(false) if (key === 'admin' && user?.role === 'admin') { history.push('/admin') } else if (key === 'settings') { history.push('/settings') } else if (key === 'logout') { setLogoutConfirmation(true) } }}> {user?.role === 'admin' && }>Admin} }>Settings }>Logout }> } : } } mode="horizontal" triggerSubMenuAction="click" theme={currentTheme === 'dark' ? 'light' : 'dark'} style={{ background: currentTheme === 'dark' ? '#1f1f1f' : '#0088CC', position: 'relative', display: 'flex', justifyContent: 'right' }}> history.push('/dashboard')} key="dashboard">Dashboard window.open('https://github.com/mgilangjanuar/teledrive', '_blank')} key="github" icon={}>GitHub }
Confirmation } visible={logoutConfirmation} onCancel={() => setLogoutConfirmation(false)} onOk={logout} cancelButtonProps={{ shape: 'round' }} okButtonProps={{ danger: true, type: 'primary', shape: 'round' }}> Are you sure to logout? setDestroySession(target.checked)}> Also delete my active session } export default Navbar