256 lines
9.0 KiB
TypeScript
Raw Normal View History

import {Badge, Layout, Menu, theme} from "antd";
import {
ApiOutlined,
BankOutlined,
CloudServerOutlined,
2024-07-27 12:59:40 +02:00
CompassOutlined,
FileProtectOutlined,
FileSearchOutlined,
2024-07-27 12:59:40 +02:00
HomeOutlined,
InfoCircleOutlined,
LineChartOutlined,
2024-07-26 18:31:47 +02:00
LoginOutlined,
LogoutOutlined,
QuestionCircleOutlined,
SearchOutlined,
TeamOutlined,
UserOutlined
} from "@ant-design/icons";
2024-07-26 23:55:12 +02:00
import {Link, Navigate, Route, Routes, useLocation, useNavigate} from "react-router-dom";
import TextPage from "./pages/TextPage";
import DomainSearchPage from "./pages/search/DomainSearchPage";
import EntitySearchPage from "./pages/search/EntitySearchPage";
import NameserverSearchPage from "./pages/search/NameserverSearchPage";
import TldPage from "./pages/info/TldPage";
import StatisticsPage from "./pages/info/StatisticsPage";
2024-07-27 17:19:25 +02:00
import WatchlistPage from "./pages/tracking/WatchlistPage";
2024-07-26 23:55:12 +02:00
import UserPage from "./pages/watchdog/UserPage";
2024-07-26 18:31:47 +02:00
import React, {useCallback, useEffect, useMemo, useState} from "react";
import {getUser} from "./utils/api";
2024-07-26 18:31:47 +02:00
import LoginPage, {AuthenticatedContext} from "./pages/LoginPage";
import ConnectorsPage from "./pages/tracking/ConnectorsPage";
import NotFoundPage from "./pages/NotFoundPage";
2024-07-27 17:19:25 +02:00
import {ItemType, MenuItemType} from "antd/lib/menu/interface";
2024-07-27 12:59:40 +02:00
import tos from "./content/tos.md";
import privacy from "./content/privacy.md";
import home from './content/home.md'
2024-07-27 17:19:25 +02:00
import faq from './content/faq.md'
2024-07-27 12:59:40 +02:00
export default function App() {
const {
token: {colorBgContainer, borderRadiusLG},
} = theme.useToken()
2024-07-26 18:31:47 +02:00
const navigate = useNavigate()
2024-07-26 18:31:47 +02:00
const location = useLocation()
2024-07-26 23:55:12 +02:00
const [isAuthenticated, setIsAuthenticated] = useState(false)
2024-07-26 18:31:47 +02:00
const authenticated = useCallback((authenticated: boolean) => {
setIsAuthenticated(authenticated)
}, []);
2024-07-26 18:31:47 +02:00
const contextValue = useMemo(() => ({
authenticated,
setIsAuthenticated
}), [authenticated, setIsAuthenticated]);
useEffect(() => {
2024-07-26 18:31:47 +02:00
getUser().then(() => {
setIsAuthenticated(true)
if (location.pathname === '/login') navigate('/search/domain')
}).catch(() => {
setIsAuthenticated(false)
2024-07-27 12:59:40 +02:00
navigate('/home')
2024-07-26 18:31:47 +02:00
})
}, []);
2024-07-27 12:59:40 +02:00
const menuItems: ItemType<MenuItemType>[] = [
{
key: 'home',
label: 'Home',
icon: <HomeOutlined/>,
onClick: () => navigate('/home')
},
2024-07-26 18:31:47 +02:00
{
2024-07-27 12:59:40 +02:00
key: 'search',
2024-07-26 18:31:47 +02:00
label: 'Search',
2024-07-27 12:59:40 +02:00
icon: <SearchOutlined/>,
2024-07-26 18:31:47 +02:00
children: [
{
2024-07-27 12:59:40 +02:00
key: 'domain-finder',
2024-07-27 01:35:00 +02:00
icon: <CompassOutlined/>,
2024-07-26 18:31:47 +02:00
label: 'Domain',
title: 'Domain Finder',
disabled: !isAuthenticated,
onClick: () => navigate('/search/domain')
},
{
2024-07-27 12:59:40 +02:00
key: 'entity-finder',
2024-07-26 18:31:47 +02:00
icon: <TeamOutlined/>,
label: 'Entity',
title: 'Entity Finder',
disabled: !isAuthenticated,
onClick: () => navigate('/search/entity')
},
{
2024-07-27 12:59:40 +02:00
key: 'ns-finder',
2024-07-26 18:31:47 +02:00
icon: <CloudServerOutlined/>,
label: 'Nameserver',
title: 'Nameserver Finder',
disabled: !isAuthenticated,
onClick: () => navigate('/search/nameserver')
}
]
},
{
2024-07-27 12:59:40 +02:00
key: 'info',
2024-07-26 18:31:47 +02:00
label: 'Information',
2024-07-26 23:55:12 +02:00
icon: <InfoCircleOutlined/>,
2024-07-26 18:31:47 +02:00
children: [
{
2024-07-27 12:59:40 +02:00
key: 'tld-list',
2024-07-26 18:31:47 +02:00
icon: <BankOutlined/>,
label: 'TLD',
2024-07-26 23:55:12 +02:00
title: 'TLD list',
2024-07-26 18:31:47 +02:00
disabled: !isAuthenticated,
onClick: () => navigate('/info/tld')
},
{
2024-07-27 12:59:40 +02:00
key: 'stats',
2024-07-26 18:31:47 +02:00
icon: <LineChartOutlined/>,
label: 'Statistics',
disabled: !isAuthenticated,
onClick: () => navigate('/info/stats')
}
]
},
{
2024-07-27 12:59:40 +02:00
key: 'tracking',
2024-07-26 18:31:47 +02:00
label: 'Tracking',
2024-07-26 23:55:12 +02:00
icon: <FileSearchOutlined/>,
2024-07-26 18:31:47 +02:00
children: [
{
2024-07-27 12:59:40 +02:00
key: 'watchlist',
2024-07-26 23:55:12 +02:00
icon: <Badge count={0} size="small"><FileSearchOutlined/></Badge>,
2024-07-26 18:31:47 +02:00
label: 'My Watchlists',
disabled: !isAuthenticated,
onClick: () => navigate('/tracking/watchlist')
},
{
2024-07-27 12:59:40 +02:00
key: 'connectors',
2024-07-26 18:31:47 +02:00
icon: <ApiOutlined/>,
label: 'My connectors',
disabled: !isAuthenticated,
onClick: () => navigate('/tracking/connectors')
}
]
},
{
2024-07-27 12:59:40 +02:00
key: 'watchdog',
2024-07-26 23:55:12 +02:00
label: 'My Watchdog',
2024-07-26 18:31:47 +02:00
icon: <UserOutlined/>,
2024-07-26 23:55:12 +02:00
children: [
{
2024-07-27 12:59:40 +02:00
key: 'account',
2024-07-26 23:55:12 +02:00
icon: <UserOutlined/>,
label: 'My Account',
disabled: !isAuthenticated,
onClick: () => navigate('/user')
},
{
2024-07-27 12:59:40 +02:00
key: 'tos',
2024-07-26 23:55:12 +02:00
icon: <InfoCircleOutlined/>,
label: 'TOS',
onClick: () => navigate('/tos')
},
{
2024-07-27 12:59:40 +02:00
key: 'privacy',
2024-07-26 23:55:12 +02:00
icon: <FileProtectOutlined/>,
label: 'Privacy Policy',
onClick: () => navigate('/privacy')
}
]
2024-07-26 18:31:47 +02:00
},
{
key: '5',
icon: <QuestionCircleOutlined/>,
label: 'FAQ',
onClick: () => navigate('/faq')
},
2024-07-26 23:55:12 +02:00
2024-07-26 18:31:47 +02:00
]
return <AuthenticatedContext.Provider value={contextValue}>
<Layout hasSider style={{minHeight: '100vh'}}>
2024-07-26 23:55:12 +02:00
<Layout.Sider collapsible>
2024-07-26 18:31:47 +02:00
<Menu
2024-07-27 12:59:40 +02:00
defaultSelectedKeys={['home']}
defaultOpenKeys={['search', 'info', 'tracking', 'watchdog']}
2024-07-26 18:31:47 +02:00
mode="inline"
theme="dark"
items={[...menuItems, isAuthenticated ? {
key: '8',
icon: <LogoutOutlined/>,
label: 'Log out',
danger: true,
onClick: () => window.location.replace("/logout")
} : {
key: '8',
icon: <LoginOutlined/>,
label: 'Log in',
onClick: () => navigate('/login')
}]}
/>
<div className="demo-logo-vertical"></div>
</Layout.Sider>
<Layout>
<Layout.Header style={{padding: 0, background: colorBgContainer}}/>
<Layout.Content style={{margin: '24px 16px 0'}}>
<div style={{
padding: 24,
minHeight: 360,
background: colorBgContainer,
borderRadius: borderRadiusLG,
}}>
<Routes>
2024-07-27 12:59:40 +02:00
<Route path="/" element={<Navigate to="/login"/>}/>
<Route path="/home" element={<TextPage markdown={home}/>}/>
2024-07-26 18:31:47 +02:00
<Route path="/search/domain" element={<DomainSearchPage/>}/>
<Route path="/search/entity" element={<EntitySearchPage/>}/>
<Route path="/search/nameserver" element={<NameserverSearchPage/>}/>
<Route path="/info/tld" element={<TldPage/>}/>
<Route path="/info/stats" element={<StatisticsPage/>}/>
2024-07-27 17:19:25 +02:00
<Route path="/tracking/watchlist" element={<WatchlistPage/>}/>
2024-07-26 18:31:47 +02:00
<Route path="/tracking/connectors" element={<ConnectorsPage/>}/>
<Route path="/user" element={<UserPage/>}/>
2024-07-27 17:19:25 +02:00
<Route path="/faq" element={<TextPage markdown={faq}/>}/>
2024-07-26 18:31:47 +02:00
<Route path="/tos" element={<TextPage markdown={tos}/>}/>
<Route path="/privacy" element={<TextPage markdown={privacy}/>}/>
<Route path="/login" element={<LoginPage/>}/>
<Route path="*" element={<NotFoundPage/>}/>
</Routes>
</div>
</Layout.Content>
<Layout.Footer style={{textAlign: 'center'}}>
2024-07-26 23:55:12 +02:00
<Link to='https://github.com/maelgangloff/domain-watchdog'>Domain
Watchdog</Link> ©{new Date().getFullYear()} Created by Maël Gangloff
2024-07-26 18:31:47 +02:00
</Layout.Footer>
</Layout>
</Layout>
2024-07-26 18:31:47 +02:00
</AuthenticatedContext.Provider>
}