|
|
@@ -1,6 +1,7 @@
|
|
|
import { View, Text } from '@tarojs/components'
|
|
|
import { useEffect, useState } from 'react'
|
|
|
import { useForm } from 'react-hook-form'
|
|
|
+import { zodResolver } from '@hookform/resolvers/zod'
|
|
|
import Taro from '@tarojs/taro'
|
|
|
import { useAuth } from '@/utils/auth'
|
|
|
import { cn } from '@/utils/cn'
|
|
|
@@ -8,19 +9,14 @@ import { Button } from '@/components/ui/button'
|
|
|
import { Input } from '@/components/ui/input'
|
|
|
import { Form, FormField, FormItem, FormLabel, FormControl, FormMessage } from '@/components/ui/form'
|
|
|
import Navbar from '@/components/ui/navbar'
|
|
|
+import { registerSchema, type RegisterFormData } from '@/schemas/register.schema'
|
|
|
import './index.css'
|
|
|
|
|
|
-interface RegisterFormData {
|
|
|
- username: string
|
|
|
- email?: string
|
|
|
- password: string
|
|
|
- confirmPassword: string
|
|
|
-}
|
|
|
-
|
|
|
export default function Register() {
|
|
|
const { register, isLoading } = useAuth()
|
|
|
|
|
|
const form = useForm<RegisterFormData>({
|
|
|
+ resolver: zodResolver(registerSchema),
|
|
|
defaultValues: {
|
|
|
username: '',
|
|
|
email: '',
|
|
|
@@ -104,17 +100,6 @@ export default function Register() {
|
|
|
<FormField
|
|
|
control={form.control}
|
|
|
name="username"
|
|
|
- rules={{
|
|
|
- required: "请输入用户名",
|
|
|
- minLength: {
|
|
|
- value: 3,
|
|
|
- message: "用户名至少3个字符"
|
|
|
- },
|
|
|
- maxLength: {
|
|
|
- value: 20,
|
|
|
- message: "用户名最多20个字符"
|
|
|
- }
|
|
|
- }}
|
|
|
render={({ field }) => (
|
|
|
<FormItem>
|
|
|
<FormLabel>用户名</FormLabel>
|
|
|
@@ -137,12 +122,6 @@ export default function Register() {
|
|
|
<FormField
|
|
|
control={form.control}
|
|
|
name="email"
|
|
|
- rules={{
|
|
|
- pattern: {
|
|
|
- value: /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
|
|
|
- message: "请输入有效的邮箱地址"
|
|
|
- }
|
|
|
- }}
|
|
|
render={({ field }) => (
|
|
|
<FormItem>
|
|
|
<FormLabel>邮箱(可选)</FormLabel>
|
|
|
@@ -166,17 +145,6 @@ export default function Register() {
|
|
|
<FormField
|
|
|
control={form.control}
|
|
|
name="password"
|
|
|
- rules={{
|
|
|
- required: "请输入密码",
|
|
|
- minLength: {
|
|
|
- value: 6,
|
|
|
- message: "密码至少6位"
|
|
|
- },
|
|
|
- maxLength: {
|
|
|
- value: 20,
|
|
|
- message: "密码最多20位"
|
|
|
- }
|
|
|
- }}
|
|
|
render={({ field }) => (
|
|
|
<FormItem>
|
|
|
<FormLabel>密码</FormLabel>
|
|
|
@@ -202,10 +170,6 @@ export default function Register() {
|
|
|
<FormField
|
|
|
control={form.control}
|
|
|
name="confirmPassword"
|
|
|
- rules={{
|
|
|
- required: "请再次输入密码",
|
|
|
- validate: (value) => value === form.getValues("password") || "两次输入的密码不一致"
|
|
|
- }}
|
|
|
render={({ field }) => (
|
|
|
<FormItem>
|
|
|
<FormLabel>确认密码</FormLabel>
|