142 lines
4.4 KiB
TypeScript
Raw Normal View History

2024-12-30 23:50:15 +01:00
import {ItemType} from 'antd/lib/menu/interface'
import {t} from 'ttag'
2024-08-03 21:50:07 +02:00
import {
2024-08-04 01:47:12 +02:00
AimOutlined,
2024-08-03 21:50:07 +02:00
ApiOutlined,
BankOutlined,
CompassOutlined,
FileSearchOutlined,
HomeOutlined,
LineChartOutlined,
LoginOutlined,
LogoutOutlined,
SearchOutlined,
TableOutlined,
2024-08-07 01:29:26 +02:00
UserOutlined
2024-12-30 23:50:15 +01:00
} from '@ant-design/icons'
import {Menu} from 'antd'
import React from 'react'
import {useLocation, useNavigate} from 'react-router-dom'
2024-08-03 21:50:07 +02:00
export function Sider({isAuthenticated}: { isAuthenticated: boolean }) {
const navigate = useNavigate()
2024-12-28 21:17:13 +01:00
const location = useLocation()
2024-08-03 21:50:07 +02:00
2024-08-21 02:01:20 +02:00
const menuItems: ItemType[] = [
2024-08-03 21:50:07 +02:00
{
2024-12-28 21:17:13 +01:00
key: '/home',
2024-08-03 21:50:07 +02:00
label: t`Home`,
icon: <HomeOutlined/>,
onClick: () => navigate('/home')
},
{
key: 'search',
label: t`Search`,
icon: <SearchOutlined/>,
children: [
{
2024-12-28 21:17:13 +01:00
key: '/search/domain',
2024-08-03 21:50:07 +02:00
icon: <CompassOutlined/>,
label: t`Domain`,
title: t`Domain Finder`,
disabled: !isAuthenticated,
onClick: () => navigate('/search/domain')
},
2024-08-04 01:32:58 +02:00
{
2024-12-28 21:17:13 +01:00
key: '/search/tld',
2024-08-04 01:32:58 +02:00
icon: <BankOutlined/>,
label: t`TLD`,
title: t`TLD list`,
disabled: !isAuthenticated,
2024-08-22 19:26:34 +02:00
onClick: () => navigate('/search/tld')
2024-08-03 21:50:07 +02:00
}
2024-12-30 23:50:15 +01:00
/*
{
key: 'entity-finder',
icon: <TeamOutlined/>,
label: t`Entity`,
title: t`Entity Finder`,
disabled: true,
onClick: () => navigate('/search/entity')
},
{
key: 'ns-finder',
icon: <CloudServerOutlined/>,
label: t`Nameserver`,
title: t`Nameserver Finder`,
disabled: true,
onClick: () => navigate('/search/nameserver')
}
*/
2024-08-03 21:50:07 +02:00
]
},
{
key: 'tracking',
label: t`Tracking`,
2024-08-04 01:47:12 +02:00
icon: <AimOutlined/>,
2024-08-03 21:50:07 +02:00
children: [
{
2024-12-28 21:17:13 +01:00
key: '/tracking/watchlist',
icon: <FileSearchOutlined/>,
2024-08-03 21:50:07 +02:00
label: t`My Watchlists`,
disabled: !isAuthenticated,
onClick: () => navigate('/tracking/watchlist')
},
{
2024-12-28 21:17:13 +01:00
key: '/tracking/domains',
icon: <TableOutlined/>,
2024-12-28 21:39:52 +01:00
label: t`Tracking table`,
disabled: !isAuthenticated,
onClick: () => navigate('/tracking/domains')
},
2024-08-03 21:50:07 +02:00
{
2024-12-28 21:17:13 +01:00
key: '/tracking/connectors',
2024-08-03 21:50:07 +02:00
icon: <ApiOutlined/>,
label: t`My Connectors`,
disabled: !isAuthenticated,
onClick: () => navigate('/tracking/connectors')
}
]
},
{
2024-12-28 21:17:13 +01:00
key: '/stats',
2024-08-04 01:32:58 +02:00
icon: <LineChartOutlined/>,
label: t`Statistics`,
2024-08-22 19:26:34 +02:00
disabled: !isAuthenticated,
onClick: () => navigate('/stats')
2024-08-04 01:32:58 +02:00
}
2024-08-03 21:50:07 +02:00
]
2024-08-04 01:32:58 +02:00
if (isAuthenticated) {
menuItems.push(...[{
2024-12-28 21:17:13 +01:00
key: '/user',
2024-08-04 01:32:58 +02:00
icon: <UserOutlined/>,
label: t`My Account`,
onClick: () => navigate('/user')
}, {
2024-12-28 21:17:13 +01:00
key: '/logout',
2024-08-03 21:50:07 +02:00
icon: <LogoutOutlined/>,
label: t`Log out`,
danger: true,
2024-12-30 23:50:15 +01:00
onClick: () => window.location.replace('/logout')
2024-08-04 01:32:58 +02:00
}])
} else {
menuItems.push({
2024-12-28 21:17:13 +01:00
key: '/login',
2024-08-03 21:50:07 +02:00
icon: <LoginOutlined/>,
label: t`Log in`,
onClick: () => navigate('/login')
2024-08-04 01:32:58 +02:00
})
}
2024-12-30 23:50:15 +01:00
return (
<Menu
defaultOpenKeys={['search', 'info', 'tracking', 'doc']}
selectedKeys={[location.pathname.includes('/search/domain') ? '/search/domain' : location.pathname]}
mode='inline'
theme='dark'
items={menuItems}
/>
)
}