domain-watchdog/assets/pages/search/DomainSearchPage.tsx

78 lines
3.9 KiB
TypeScript
Raw Normal View History

2024-07-27 01:35:00 +02:00
import React, {useState} from "react";
2024-07-30 22:42:25 +02:00
import {Badge, Card, Divider, Empty, Flex, FormProps, message, Skeleton, Space, Tag, Typography} from "antd";
2024-07-27 01:35:00 +02:00
import {Domain, getDomain} from "../../utils/api";
import {AxiosError} from "axios"
2024-07-28 15:36:22 +02:00
import {t} from 'ttag'
import {DomainSearchBar, FieldType} from "../../components/search/DomainSearchBar";
import {EventTimeline} from "../../components/search/EventTimeline";
import {EntitiesList} from "../../components/search/EntitiesList";
2024-07-27 01:35:00 +02:00
2024-07-31 12:37:43 +02:00
const {Text} = Typography;
2024-07-27 14:40:08 +02:00
export default function DomainSearchPage() {
const [domain, setDomain] = useState<Domain | null>()
2024-07-27 01:35:00 +02:00
const [messageApi, contextHolder] = message.useMessage()
const onFinish: FormProps<FieldType>['onFinish'] = (values) => {
setDomain(null)
2024-07-27 16:45:20 +02:00
getDomain(values.ldhName).then(d => {
setDomain(d)
2024-07-28 15:36:22 +02:00
messageApi.success(t`Found !`)
2024-07-27 16:45:20 +02:00
}).catch((e: AxiosError) => {
2024-07-27 01:35:00 +02:00
const data = e?.response?.data as { detail: string }
setDomain(undefined)
2024-07-28 15:36:22 +02:00
messageApi.error(data.detail ?? t`An error occurred`)
2024-07-27 01:35:00 +02:00
})
}
return <Flex gap="middle" align="center" justify="center" vertical>
2024-07-28 15:36:22 +02:00
<Card title={t`Domain finder`} style={{width: '100%'}}>
2024-07-27 01:35:00 +02:00
{contextHolder}
<DomainSearchBar onFinish={onFinish}/>
2024-07-27 14:40:08 +02:00
<Skeleton loading={domain === null} active>
{
domain &&
(!domain.deleted ? <Space direction="vertical" size="middle" style={{width: '100%'}}>
<Badge.Ribbon text={`.${domain.tld.tld.toUpperCase()} (${domain.tld.type})`}
color={
domain.tld.type === 'ccTLD' ? 'purple' :
(domain.tld.type === 'gTLD' && domain.tld.specification13) ? "volcano" :
domain.tld.type === 'gTLD' ? "green"
: "cyan"
}>
2024-08-02 21:32:24 +02:00
<Card title={<>
{domain.ldhName}{domain.handle && <Text code>{domain.handle}</Text>}
</>}
size="small">
{domain.status.length > 0 &&
<>
2024-07-28 21:51:37 +02:00
<Divider orientation="left">{t`EPP Status Codes`}</Divider>
<Flex gap="4px 0" wrap>
{
domain.status.map(s =>
<Tag color={s === 'active' ? 'green' : 'blue'}>{s}</Tag>
)
2024-07-27 16:45:20 +02:00
}
</Flex>
</>
2024-07-27 16:45:20 +02:00
}
2024-07-28 21:51:37 +02:00
<Divider orientation="left">{t`Timeline`}</Divider>
<EventTimeline domain={domain}/>
{
domain.entities.length > 0 &&
<>
2024-07-28 21:51:37 +02:00
<Divider orientation="left">{t`Entities`}</Divider>
<EntitiesList domain={domain}/>
</>
}
</Card>
</Badge.Ribbon>
</Space>
: <Empty
description={t`Although the domain exists in my database, it has been deleted from the WHOIS by its registrar.`}/>)
}
</Skeleton>
2024-07-27 01:35:00 +02:00
</Card>
</Flex>
}