mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-20 11:15:37 +00:00
feat: update front layout
This commit is contained in:
parent
a15c1b2c2f
commit
467d0efa1c
@ -7,12 +7,14 @@ import {
|
|||||||
FileSearchOutlined,
|
FileSearchOutlined,
|
||||||
InfoCircleOutlined,
|
InfoCircleOutlined,
|
||||||
LineChartOutlined,
|
LineChartOutlined,
|
||||||
|
LoginOutlined,
|
||||||
|
LogoutOutlined,
|
||||||
QuestionCircleOutlined,
|
QuestionCircleOutlined,
|
||||||
SearchOutlined,
|
SearchOutlined,
|
||||||
TeamOutlined,
|
TeamOutlined,
|
||||||
UserOutlined
|
UserOutlined
|
||||||
} from "@ant-design/icons";
|
} from "@ant-design/icons";
|
||||||
import {Navigate, Route, Routes, useNavigate} from "react-router-dom";
|
import {Navigate, Route, Routes, useLocation, useNavigate} from "react-router-dom";
|
||||||
import TextPage from "./pages/TextPage";
|
import TextPage from "./pages/TextPage";
|
||||||
import tos from "./content/tos.md";
|
import tos from "./content/tos.md";
|
||||||
import privacy from "./content/privacy.md";
|
import privacy from "./content/privacy.md";
|
||||||
@ -23,32 +25,43 @@ import TldPage from "./pages/info/TldPage";
|
|||||||
import StatisticsPage from "./pages/info/StatisticsPage";
|
import StatisticsPage from "./pages/info/StatisticsPage";
|
||||||
import WatchlistsPage from "./pages/tracking/WatchlistsPage";
|
import WatchlistsPage from "./pages/tracking/WatchlistsPage";
|
||||||
import UserPage from "./pages/UserPage";
|
import UserPage from "./pages/UserPage";
|
||||||
import LoginPage from "./pages/LoginPage";
|
import React, {useCallback, useEffect, useMemo, useState} from "react";
|
||||||
import React, {useEffect, useState} from "react";
|
|
||||||
import {getUser} from "./utils/api";
|
import {getUser} from "./utils/api";
|
||||||
|
import FAQPage from "./pages/FAQPage";
|
||||||
|
import LoginPage, {AuthenticatedContext} from "./pages/LoginPage";
|
||||||
|
import ConnectorsPage from "./pages/tracking/ConnectorsPage";
|
||||||
|
import NotFoundPage from "./pages/NotFoundPage";
|
||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
|
|
||||||
const {
|
const {
|
||||||
token: {colorBgContainer, borderRadiusLG},
|
token: {colorBgContainer, borderRadiusLG},
|
||||||
} = theme.useToken()
|
} = theme.useToken()
|
||||||
const [isAuthenticated, setIsAuthenticated] = useState<boolean>(false);
|
|
||||||
const navigate = useNavigate()
|
|
||||||
|
|
||||||
|
const navigate = useNavigate()
|
||||||
|
const [isAuthenticated, setIsAuthenticated] = useState(false)
|
||||||
|
const location = useLocation()
|
||||||
|
|
||||||
|
const authenticated = useCallback((authenticated: boolean) => {
|
||||||
|
setIsAuthenticated(authenticated)
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const contextValue = useMemo(() => ({
|
||||||
|
authenticated,
|
||||||
|
setIsAuthenticated
|
||||||
|
}), [authenticated, setIsAuthenticated]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getUser().then(() => setIsAuthenticated(true)).catch(() => setIsAuthenticated(false))
|
getUser().then(() => {
|
||||||
|
setIsAuthenticated(true)
|
||||||
|
if (location.pathname === '/login') navigate('/search/domain')
|
||||||
|
}).catch(() => {
|
||||||
|
setIsAuthenticated(false)
|
||||||
|
if (location.pathname !== '/login') navigate('/login')
|
||||||
|
})
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|
||||||
return <Layout hasSider style={{minHeight: '100vh'}}>
|
const menuItems = [
|
||||||
<Layout.Sider>
|
|
||||||
<Menu
|
|
||||||
defaultSelectedKeys={['1-1']}
|
|
||||||
defaultOpenKeys={['1', '2', '3']}
|
|
||||||
mode="inline"
|
|
||||||
theme="dark"
|
|
||||||
items={[
|
|
||||||
{
|
{
|
||||||
key: '1',
|
key: '1',
|
||||||
label: 'Search',
|
label: 'Search',
|
||||||
@ -145,7 +158,29 @@ export default function App() {
|
|||||||
label: 'Privacy Policy',
|
label: 'Privacy Policy',
|
||||||
onClick: () => navigate('/privacy')
|
onClick: () => navigate('/privacy')
|
||||||
}
|
}
|
||||||
]}
|
]
|
||||||
|
|
||||||
|
|
||||||
|
return <AuthenticatedContext.Provider value={contextValue}>
|
||||||
|
<Layout hasSider style={{minHeight: '100vh'}}>
|
||||||
|
<Layout.Sider>
|
||||||
|
<Menu
|
||||||
|
defaultSelectedKeys={['1-1']}
|
||||||
|
defaultOpenKeys={['1', '2', '3']}
|
||||||
|
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>
|
<div className="demo-logo-vertical"></div>
|
||||||
</Layout.Sider>
|
</Layout.Sider>
|
||||||
@ -160,11 +195,6 @@ export default function App() {
|
|||||||
}}>
|
}}>
|
||||||
|
|
||||||
<Routes>
|
<Routes>
|
||||||
<Route path="/tos" element={<TextPage markdown={tos}/>}/>
|
|
||||||
<Route path="/privacy" element={<TextPage markdown={privacy}/>}/>
|
|
||||||
|
|
||||||
{isAuthenticated ?
|
|
||||||
<>
|
|
||||||
<Route path="/" element={<Navigate to="/search/domain"/>}/>
|
<Route path="/" element={<Navigate to="/search/domain"/>}/>
|
||||||
|
|
||||||
<Route path="/search/domain" element={<DomainSearchPage/>}/>
|
<Route path="/search/domain" element={<DomainSearchPage/>}/>
|
||||||
@ -175,13 +205,17 @@ export default function App() {
|
|||||||
<Route path="/info/stats" element={<StatisticsPage/>}/>
|
<Route path="/info/stats" element={<StatisticsPage/>}/>
|
||||||
|
|
||||||
<Route path="/tracking/watchlist" element={<WatchlistsPage/>}/>
|
<Route path="/tracking/watchlist" element={<WatchlistsPage/>}/>
|
||||||
|
<Route path="/tracking/connectors" element={<ConnectorsPage/>}/>
|
||||||
|
|
||||||
<Route path="/user" element={<UserPage/>}/>
|
<Route path="/user" element={<UserPage/>}/>
|
||||||
</>
|
|
||||||
:
|
|
||||||
<Route path="*" element={<LoginPage/>}/>
|
|
||||||
}
|
|
||||||
|
|
||||||
|
<Route path="/faq" element={<FAQPage/>}/>
|
||||||
|
<Route path="/tos" element={<TextPage markdown={tos}/>}/>
|
||||||
|
<Route path="/privacy" element={<TextPage markdown={privacy}/>}/>
|
||||||
|
|
||||||
|
<Route path="/login" element={<LoginPage/>}/>
|
||||||
|
|
||||||
|
<Route path="*" element={<NotFoundPage/>}/>
|
||||||
</Routes>
|
</Routes>
|
||||||
</div>
|
</div>
|
||||||
</Layout.Content>
|
</Layout.Content>
|
||||||
@ -190,4 +224,5 @@ export default function App() {
|
|||||||
</Layout.Footer>
|
</Layout.Footer>
|
||||||
</Layout>
|
</Layout>
|
||||||
</Layout>
|
</Layout>
|
||||||
|
</AuthenticatedContext.Provider>
|
||||||
}
|
}
|
||||||
@ -14,7 +14,6 @@ function Index() {
|
|||||||
<HashRouter>
|
<HashRouter>
|
||||||
<App/>
|
<App/>
|
||||||
</HashRouter>
|
</HashRouter>
|
||||||
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
8
assets/pages/FAQPage.tsx
Normal file
8
assets/pages/FAQPage.tsx
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import React from "react";
|
||||||
|
|
||||||
|
|
||||||
|
export default function FAQPage() {
|
||||||
|
return <p>
|
||||||
|
FAQ Page
|
||||||
|
</p>
|
||||||
|
}
|
||||||
@ -1,7 +1,74 @@
|
|||||||
import React from "react";
|
import React, {createContext, useContext, useEffect, useState} from "react";
|
||||||
|
import {Alert, Button, Card, Flex, Form, Input} from "antd";
|
||||||
|
import {login} from "../utils/api";
|
||||||
|
import {useNavigate} from "react-router-dom";
|
||||||
|
|
||||||
|
type FieldType = {
|
||||||
|
username: string;
|
||||||
|
password: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const AuthenticatedContext = createContext<any>(null)
|
||||||
|
|
||||||
export default function Page() {
|
export default function Page() {
|
||||||
return <p>
|
|
||||||
Login Page
|
const [error, setError] = useState()
|
||||||
</p>
|
const navigate = useNavigate()
|
||||||
|
const {isAuthenticated, setIsAuthenticated} = useContext(AuthenticatedContext)
|
||||||
|
|
||||||
|
const onFinish = (data: FieldType) => {
|
||||||
|
login(data.username, data.password).then(() => {
|
||||||
|
setIsAuthenticated(true)
|
||||||
|
navigate('/search/domain')
|
||||||
|
}).catch((e) => {
|
||||||
|
setIsAuthenticated(false)
|
||||||
|
setError(e.response.data.message)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return <Flex gap="middle" align="center" justify="center" vertical><Card
|
||||||
|
title="Log in"
|
||||||
|
style={{width: 500}}
|
||||||
|
>
|
||||||
|
{error &&
|
||||||
|
<Alert
|
||||||
|
type='error'
|
||||||
|
message='Error'
|
||||||
|
banner={true}
|
||||||
|
role='role'
|
||||||
|
description={error}
|
||||||
|
style={{marginBottom: '1em'}}
|
||||||
|
/>}
|
||||||
|
<Form
|
||||||
|
name="basic"
|
||||||
|
labelCol={{span: 8}}
|
||||||
|
wrapperCol={{span: 16}}
|
||||||
|
style={{maxWidth: 600}}
|
||||||
|
onFinish={onFinish}
|
||||||
|
autoComplete="off"
|
||||||
|
>
|
||||||
|
<Form.Item
|
||||||
|
label="Username"
|
||||||
|
name="username"
|
||||||
|
rules={[{required: true, message: 'Required'}]}
|
||||||
|
>
|
||||||
|
<Input/>
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
|
<Form.Item<FieldType>
|
||||||
|
label="Password"
|
||||||
|
name="password"
|
||||||
|
rules={[{required: true, message: 'Required'}]}
|
||||||
|
>
|
||||||
|
<Input.Password/>
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
|
<Form.Item wrapperCol={{offset: 8, span: 16}}>
|
||||||
|
<Button type="primary" htmlType="submit">
|
||||||
|
Submit
|
||||||
|
</Button>
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
</Card>
|
||||||
|
</Flex>
|
||||||
}
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
import {Button, Result} from "antd";
|
import {Result} from "antd";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
|
|
||||||
@ -7,6 +7,5 @@ export default function NotFoundPage() {
|
|||||||
status="404"
|
status="404"
|
||||||
title="404"
|
title="404"
|
||||||
subTitle="Sorry, the page you visited does not exist."
|
subTitle="Sorry, the page you visited does not exist."
|
||||||
extra={<Button type="primary">Back Home</Button>}
|
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
@ -2,6 +2,6 @@ import React from "react";
|
|||||||
|
|
||||||
export default function StatisticsPage() {
|
export default function StatisticsPage() {
|
||||||
return <p>
|
return <p>
|
||||||
Tld
|
Statistics Page
|
||||||
</p>
|
</p>
|
||||||
}
|
}
|
||||||
@ -2,6 +2,6 @@ import React from "react";
|
|||||||
|
|
||||||
export default function TldPage() {
|
export default function TldPage() {
|
||||||
return <p>
|
return <p>
|
||||||
Tld
|
Tld Page
|
||||||
</p>
|
</p>
|
||||||
}
|
}
|
||||||
@ -2,6 +2,6 @@ import React from "react";
|
|||||||
|
|
||||||
export default function DomainSearchPage() {
|
export default function DomainSearchPage() {
|
||||||
return <p>
|
return <p>
|
||||||
|
Domain Search Page
|
||||||
</p>
|
</p>
|
||||||
}
|
}
|
||||||
@ -2,6 +2,6 @@ import React from "react";
|
|||||||
|
|
||||||
export default function EntitySearchPage() {
|
export default function EntitySearchPage() {
|
||||||
return <p>
|
return <p>
|
||||||
|
Entity Search Page
|
||||||
</p>
|
</p>
|
||||||
}
|
}
|
||||||
@ -2,6 +2,6 @@ import React from "react";
|
|||||||
|
|
||||||
export default function NameserverSearchPage() {
|
export default function NameserverSearchPage() {
|
||||||
return <p>
|
return <p>
|
||||||
NS Finder
|
NS Search Page
|
||||||
</p>
|
</p>
|
||||||
}
|
}
|
||||||
@ -2,6 +2,6 @@ import React from "react";
|
|||||||
|
|
||||||
export default function ConnectorsPage() {
|
export default function ConnectorsPage() {
|
||||||
return <p>
|
return <p>
|
||||||
|
Connectors Page
|
||||||
</p>
|
</p>
|
||||||
}
|
}
|
||||||
@ -2,6 +2,6 @@ import React from "react";
|
|||||||
|
|
||||||
export default function WatchlistsPage() {
|
export default function WatchlistsPage() {
|
||||||
return <p>
|
return <p>
|
||||||
|
Watchlists Page
|
||||||
</p>
|
</p>
|
||||||
}
|
}
|
||||||
@ -8,21 +8,8 @@ interface Tld {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getTldList(params: object): Promise<Tld[]> {
|
export async function getTldList(params: object): Promise<Tld[]> {
|
||||||
let page = 1
|
return (await request<Tld[]>({
|
||||||
let response = (await request<Tld[]>({
|
|
||||||
url: 'tld',
|
url: 'tld',
|
||||||
params: {...params, page},
|
params,
|
||||||
})).data
|
})).data
|
||||||
const tldList: Tld[] = response;
|
|
||||||
|
|
||||||
while (response.length !== 0) {
|
|
||||||
page++
|
|
||||||
response = (await request<Tld[]>({
|
|
||||||
url: 'tld',
|
|
||||||
params: {...params, page},
|
|
||||||
})).data
|
|
||||||
|
|
||||||
tldList.push(...response)
|
|
||||||
}
|
|
||||||
return tldList
|
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user