fix: the field is pre-filled with the requested domain name

This commit is contained in:
Maël Gangloff
2024-12-29 18:06:28 +01:00
parent 45e218c322
commit 16e3d3b33a
3 changed files with 18 additions and 12 deletions

View File

@@ -7,7 +7,7 @@ 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"
@@ -15,6 +15,7 @@ export function DomainSearchBar({onFinish}: { onFinish: (values: FieldType) => v
>
<Form.Item<FieldType>
name="ldhName"
initialValue={initialValue}
rules={[{
required: true,
message: t`Required`

View File

@@ -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>
{