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

38 lines
1.4 KiB
TypeScript
Raw Normal View History

2024-07-27 01:35:00 +02:00
import React, {useState} from "react";
2024-08-23 21:19:34 +02:00
import {Empty, Flex, FormProps, message, Skeleton} 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";
2024-08-20 15:22:14 +02:00
import {DomainResult} from "../../components/search/DomainResult";
2024-08-22 01:44:50 +02:00
import {showErrorAPI} from "../../utils/functions/showErrorAPI";
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) => {
setDomain(undefined)
2024-08-07 15:57:16 +02:00
showErrorAPI(e, messageApi)
2024-07-27 01:35:00 +02:00
})
}
return <Flex gap="middle" align="center" justify="center" vertical>
2024-08-23 21:19:34 +02:00
{contextHolder}
<DomainSearchBar onFinish={onFinish}/>
2024-07-27 14:40:08 +02:00
2024-08-23 21:19:34 +02:00
<Skeleton loading={domain === null} active>
{
domain &&
(!domain.deleted ? <DomainResult domain={domain}/>
: <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
</Flex>
}