'use client' import { useState } from 'react' import { useRouter } from 'next/navigation' import { useForm } from 'react-hook-form' import { useAuth } from '@/components/providers/auth-provider' import { Button } from '@nice/ui/components/button' import { Input } from '@nice/ui/components/input' import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from '@nice/ui/components/form' import { Alert, AlertDescription } from '@nice/ui/components/alert' import { DeptSelect } from '@/components/selector/dept-select' import Link from 'next/link' interface RegisterForm { username: string password: string confirmPassword: string email?: string organizationId?: string } export default function RegisterPage() { const router = useRouter() const { register: registerUser, isLoading } = useAuth() const [error, setError] = useState(null) const form = useForm({ defaultValues: { username: '', password: '', confirmPassword: '', email: '', organizationId: '' } }) const handleSubmit = async (data: RegisterForm) => { // 验证密码确认 if (data.password !== data.confirmPassword) { form.setError('confirmPassword', { message: '两次输入的密码不一致' }) return } setError(null) try { await registerUser({ data: { username: data.username, password: data.password, organizationId: data.organizationId, } }) // 注册成功,跳转到登录页 router.push('/auth/login?message=register_success') } catch (err) { setError(err instanceof Error ? err.message : '注册失败,请重试') } } return (
{/* 欢迎标题 */}

注册风火账号

{/* 错误消息 */} {error && ( {error} )}
{/* 注册表单 */}
{/* 用户名输入 */} ( 用户名 )} /> {/* 所属部门选择 */} ( 所属部门 (可选) )} /> {/* 密码输入 */} ( 密码 )} /> {/* 确认密码输入 */} ( 确认密码 )} /> {/* 注册按钮 */} {/* 登录链接 */}
已有账号? 立即登录
) }