Skip to content

Commit

Permalink
fix: the field is pre-filled with the requested domain name
Browse files Browse the repository at this point in the history
  • Loading branch information
maelgangloff committed Dec 29, 2024
1 parent 45e218c commit 16e3d3b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
3 changes: 2 additions & 1 deletion assets/components/search/DomainSearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ export type FieldType = {
ldhName: string
}

export function DomainSearchBar({onFinish}: { onFinish: (values: FieldType) => void }) {
export function DomainSearchBar({onFinish, initialValue}: { onFinish: (values: FieldType) => void, initialValue?: string }) {
return <Form
onFinish={onFinish}
autoComplete="off"
style={{width: '100%'}}
>
<Form.Item<FieldType>
name="ldhName"
initialValue={initialValue}
rules={[{
required: true,
message: t`Required`
Expand Down
14 changes: 8 additions & 6 deletions assets/pages/search/DomainSearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,26 @@ export default function DomainSearchPage() {

const onFinish: FormProps<FieldType>['onFinish'] = (values) => {
navigate('/search/domain/' + values.ldhName)
}

useEffect(() => {
if (query === undefined) return

setDomain(null)
getDomain(query).then(d => {
getDomain(values.ldhName).then(d => {
setDomain(d)
messageApi.success(t`Found !`)
}).catch((e: AxiosError) => {
setDomain(undefined)
showErrorAPI(e, messageApi)
})
}

useEffect(() => {
if (query === undefined) return

onFinish({ldhName: query})
}, [query])

return <Flex gap="middle" align="center" justify="center" vertical>
{contextHolder}
<DomainSearchBar onFinish={onFinish}/>
<DomainSearchBar initialValue={query} onFinish={onFinish}/>

<Skeleton loading={domain === null} active>
{
Expand Down
11 changes: 7 additions & 4 deletions src/Service/RDAPService.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@

readonly class RDAPService
{
/**
* @see https://www.iana.org/domains/root/db
*/
/* @see https://www.iana.org/domains/root/db */
public const ISO_TLD_EXCEPTION = ['ac', 'eu', 'uk', 'su', 'tp'];
public const INFRA_TLD = ['arpa'];
public const SPONSORED_TLD = [
Expand Down Expand Up @@ -175,9 +173,14 @@ private function getTld($domain): ?object
if (false === $lastDotPosition) {
throw new BadRequestException('Domain must contain at least one dot');
}

$tld = strtolower(idn_to_ascii(substr($domain, $lastDotPosition + 1)));
$tldEntity = $this->tldRepository->findOneBy(['tld' => $tld]);
if (null === $tldEntity) {
throw new NotFoundHttpException("The requested TLD is not yet supported, please try again with another one");
}

return $this->tldRepository->findOneBy(['tld' => $tld]);
return $tldEntity;
}

private function convertToIdn(string $fqdn): string
Expand Down

0 comments on commit 16e3d3b

Please sign in to comment.