fix: AuthModal 重开时重置表单 + 邀请页加入失败显示错误
- #13: useEffect 监听 open 变化时重置所有表单状态(用户名、密码、错误等) - #14: handleJoin catch 中捕获错误消息并渲染到页面
This commit is contained in:
@@ -29,6 +29,7 @@ export default function InvitePage() {
|
||||
const [userCount, setUserCount] = useState(0);
|
||||
const [scene, setScene] = useState<SceneType>("eat");
|
||||
const [joining, setJoining] = useState(false);
|
||||
const [joinError, setJoinError] = useState("");
|
||||
|
||||
const sceneConfig = getSceneConfig(scene);
|
||||
|
||||
@@ -48,10 +49,12 @@ export default function InvitePage() {
|
||||
|
||||
const handleJoin = async () => {
|
||||
setJoining(true);
|
||||
setJoinError("");
|
||||
try {
|
||||
await joinRoom(roomId, getUserId());
|
||||
router.push(`/room/${roomId}`);
|
||||
} catch {
|
||||
} catch (e) {
|
||||
setJoinError(e instanceof Error ? e.message : "加入失败,请重试");
|
||||
setJoining(false);
|
||||
}
|
||||
};
|
||||
@@ -187,6 +190,15 @@ export default function InvitePage() {
|
||||
animate={{ y: 0, opacity: 1 }}
|
||||
transition={{ duration: 0.5, delay: 0.3 }}
|
||||
>
|
||||
{joinError && (
|
||||
<motion.p
|
||||
className="mb-3 text-center text-xs font-medium text-rose-400"
|
||||
initial={{ opacity: 0, y: -4 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
>
|
||||
{joinError}
|
||||
</motion.p>
|
||||
)}
|
||||
<Button
|
||||
onClick={handleJoin}
|
||||
size="lg"
|
||||
|
||||
Reference in New Issue
Block a user