chore: 统一代码格式并配置开发工具
- 添加 ESLint 和 Prettier 配置以统一代码风格 - 配置项目级 TypeScript 设置 - 更新前后端依赖版本 - 修复代码格式问题(引号、分号、尾随逗号等) - 优化文件结构和导入路径
This commit is contained in:
@@ -1,42 +1,57 @@
|
||||
import { useState } from 'react';
|
||||
import { useNavigate, Link } from 'react-router-dom';
|
||||
import { Card, Input, Button, Form, toast, TextField, Label, FieldError } from '@heroui/react';
|
||||
import { signUp } from '../../lib/auth-client';
|
||||
import { useState } from 'react'
|
||||
import { useNavigate, Link as RouterLink } from 'react-router-dom'
|
||||
import {
|
||||
Card,
|
||||
Input,
|
||||
Button,
|
||||
Form,
|
||||
toast,
|
||||
TextField,
|
||||
Label,
|
||||
FieldError,
|
||||
} from '@heroui/react'
|
||||
import { buttonVariants } from '@heroui/styles'
|
||||
import { signUp } from '../../lib/auth-client'
|
||||
|
||||
export default function RegisterPage() {
|
||||
const [email, setEmail] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
const [loading, setLoading] = useState(false);
|
||||
const navigate = useNavigate();
|
||||
const [email, setEmail] = useState('')
|
||||
const [password, setPassword] = useState('')
|
||||
const [loading, setLoading] = useState(false)
|
||||
const navigate = useNavigate()
|
||||
|
||||
const handleRegister = async (e: React.FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
setLoading(true);
|
||||
e.preventDefault()
|
||||
setLoading(true)
|
||||
try {
|
||||
await signUp.email({
|
||||
email,
|
||||
password,
|
||||
name: email.split('@')[0], // Default name
|
||||
}, {
|
||||
onSuccess: () => {
|
||||
navigate('/');
|
||||
await signUp.email(
|
||||
{
|
||||
email,
|
||||
password,
|
||||
name: email.split('@')[0], // Default name
|
||||
},
|
||||
onError: (ctx) => {
|
||||
toast.danger(ctx.error.message);
|
||||
}
|
||||
});
|
||||
{
|
||||
onSuccess: () => {
|
||||
navigate('/')
|
||||
},
|
||||
onError: (ctx) => {
|
||||
toast.danger(ctx.error.message)
|
||||
},
|
||||
},
|
||||
)
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
console.error(err)
|
||||
} finally {
|
||||
setLoading(false);
|
||||
setLoading(false)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center min-h-[calc(100vh-64px)] p-4">
|
||||
<div className="flex min-h-[calc(100vh-64px)] flex-col items-center justify-center p-4">
|
||||
<Card className="w-full max-w-md">
|
||||
<Card.Header>
|
||||
<Card.Title className="text-2xl font-bold text-center w-full">注册 HLAE 中文站</Card.Title>
|
||||
<Card.Title className="w-full text-center text-2xl font-bold">
|
||||
注册 HLAE 中文站
|
||||
</Card.Title>
|
||||
</Card.Header>
|
||||
<Form validationBehavior="native" onSubmit={handleRegister}>
|
||||
<Card.Content className="flex flex-col gap-6">
|
||||
@@ -64,21 +79,42 @@ export default function RegisterPage() {
|
||||
<FieldError />
|
||||
</TextField>
|
||||
</Card.Content>
|
||||
<Card.Footer className="flex flex-col gap-3 mt-2">
|
||||
<Button type="submit" isPending={loading} fullWidth className="font-bold">
|
||||
<Card.Footer className="mt-2 flex flex-col gap-3">
|
||||
<Button
|
||||
type="submit"
|
||||
isPending={loading}
|
||||
fullWidth
|
||||
className="font-bold"
|
||||
>
|
||||
注册
|
||||
</Button>
|
||||
<Button as={Link} to="/login" variant="tertiary" fullWidth className="font-bold">
|
||||
<RouterLink
|
||||
to="/login"
|
||||
className={buttonVariants({
|
||||
variant: 'tertiary',
|
||||
fullWidth: true,
|
||||
className: 'font-bold',
|
||||
})}
|
||||
>
|
||||
已有账号?登录
|
||||
</Button>
|
||||
<div className="flex justify-center mt-2">
|
||||
<Link to="/" className="text-sm text-default-500 hover:text-primary transition-colors flex items-center gap-1">
|
||||
<span>← 返回首页</span>
|
||||
</Link>
|
||||
</RouterLink>
|
||||
<div className="mt-2 flex justify-center">
|
||||
<RouterLink
|
||||
to="/"
|
||||
className="text-default-500 hover:text-foreground text-sm"
|
||||
>
|
||||
返回首页
|
||||
</RouterLink>
|
||||
</div>
|
||||
</Card.Footer>
|
||||
</Form>
|
||||
</Card>
|
||||
<p className="mt-4 text-sm text-gray-500">
|
||||
已有账号?{' '}
|
||||
<RouterLink to="/login" className="text-primary hover:underline">
|
||||
去登录
|
||||
</RouterLink>
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user