fix: AuthModal 重开时重置表单 + 邀请页加入失败显示错误

- #13: useEffect 监听 open 变化时重置所有表单状态(用户名、密码、错误等)
- #14: handleJoin catch 中捕获错误消息并渲染到页面
This commit is contained in:
2026-02-26 20:16:25 +08:00
parent 508903b67d
commit 50ae46fe15
2 changed files with 23 additions and 2 deletions
+10 -1
View File
@@ -1,6 +1,6 @@
"use client";
import { useState } from "react";
import { useState, useEffect } from "react";
import { motion } from "framer-motion";
import { X, Eye, EyeOff } from "lucide-react";
import { AVATARS } from "@/lib/avatars";
@@ -36,8 +36,17 @@ export default function AuthModal({ open, onClose, onAuth, defaultTab = "login"
setAvatar(AVATARS[0].emoji);
setShowPassword(false);
setError("");
setLoading(false);
};
useEffect(() => {
if (open) {
setTab(defaultTab);
resetForm();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [open]);
const switchTab = (t: Tab) => {
setTab(t);
resetForm();