import { useState } from 'react'; import { Form, Input, Button, App } from 'antd'; import { UserOutlined, LockOutlined } from '@ant-design/icons'; import { useTranslation } from 'react-i18next'; import { registerApi } from '@/api/auth'; interface RegisterFormProps { onSwitchLogin: () => void; } export function RegisterForm({ onSwitchLogin }: RegisterFormProps) { const { t } = useTranslation('login'); const { message } = App.useApp(); const [loading, setLoading] = useState(false); const [form] = Form.useForm(); const onFinish = async (values: { username: string; password: string }) => { setLoading(true); try { await registerApi({ username: values.username, password: values.password }); message.success(t('registerSuccess')); onSwitchLogin(); } catch { message.error(t('registerFail')); } finally { setLoading(false); } }; return (
} placeholder={t('enterUsername')} /> } placeholder={t('enterPassword')} /> ({ validator(_, value) { if (!value || getFieldValue('password') === value) return Promise.resolve(); return Promise.reject(new Error(t('passwordMismatch'))); }, }), ]} > } placeholder={t('confirmPasswordPlaceholder')} />
{t('backToAccount')}
); }