mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
61 lines
1.7 KiB
TypeScript
61 lines
1.7 KiB
TypeScript
import {Button, Form, Input, message} from "antd";
|
|
import {t} from "ttag";
|
|
import React, {useState} from "react";
|
|
import {register} from "../utils/api";
|
|
import {useNavigate} from "react-router-dom";
|
|
|
|
import {showErrorAPI} from "../utils/functions/showErrorAPI";
|
|
|
|
|
|
type FieldType = {
|
|
username: string;
|
|
password: string;
|
|
}
|
|
|
|
export function RegisterForm() {
|
|
|
|
const [error, setError] = useState<string>()
|
|
const navigate = useNavigate()
|
|
const [messageApi, contextHolder] = message.useMessage()
|
|
|
|
const onFinish = (data: FieldType) => {
|
|
register(data.username, data.password).then(() => {
|
|
navigate('/home')
|
|
}).catch((e) => {
|
|
showErrorAPI(e, messageApi)
|
|
})
|
|
}
|
|
return <>
|
|
{contextHolder}
|
|
<Form
|
|
name="basic"
|
|
labelCol={{span: 8}}
|
|
wrapperCol={{span: 16}}
|
|
style={{maxWidth: 600}}
|
|
onFinish={onFinish}
|
|
autoComplete="off"
|
|
>
|
|
<Form.Item
|
|
label={t`Email address`}
|
|
name="username"
|
|
rules={[{required: true, message: t`Required`}]}
|
|
>
|
|
<Input autoFocus/>
|
|
</Form.Item>
|
|
|
|
<Form.Item<FieldType>
|
|
label={t`Password`}
|
|
name="password"
|
|
rules={[{required: true, message: t`Required`}]}
|
|
>
|
|
<Input.Password/>
|
|
</Form.Item>
|
|
|
|
<Form.Item wrapperCol={{offset: 8, span: 16}}>
|
|
<Button block type="primary" htmlType="submit">
|
|
{t`Register`}
|
|
</Button>
|
|
</Form.Item>
|
|
</Form>
|
|
</>
|
|
} |