import { Fonts } from "@/constants/Fonts"; import { fetchApi } from "@/lib/server-api-util"; import { User } from "@/types/user"; import { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import { StyleSheet, TouchableOpacity, View } from "react-native"; import { ThemedText } from "../ThemedText"; import Button from "./ui/Button"; import TextInput from "./ui/TextInput"; interface LoginProps { setIsSignUp?: (isSignUp: string) => void; closeModal?: () => void; updateUrlParam?: (status: string, value: string) => void; setError: (error: string) => void; } const ForgetPwd = ({ setIsSignUp, updateUrlParam, setError }: LoginProps) => { const { t } = useTranslation(); const [loading, setLocading] = useState(false); const [isDisabled, setIsDisabled] = useState(false); const [email, setEmail] = useState(''); const [countdown, setCountdown] = useState(0); useEffect(() => { if (countdown > 0) { const timer = setTimeout(() => setCountdown(countdown - 1), 1000); return () => clearTimeout(timer); } else if (countdown === 0 && isDisabled) { setIsDisabled(false); } }, [countdown, isDisabled]); const handleSubmit = () => { if (!email) { setError(t('auth.forgetPwd.emailPlaceholder', { ns: 'login' })); return; } setLocading(true); const body = { email: email, } fetchApi('/iam/reset-password-session', { method: 'POST', body: JSON.stringify(body), headers: { 'Content-Type': 'application/json' } }) .then((_) => { setIsDisabled(true); setCountdown(60); }) .catch((error) => { setError(error.message || t('auth.forgetPwd.sendEmailError', { ns: 'login' })); }) .finally(() => { setLocading(false); }); }; const handleBackToLogin = () => { if (setIsSignUp) { setIsSignUp('login'); } if (updateUrlParam) { updateUrlParam('status', 'login'); } } return ( {/* 邮箱 */} {/* 发送邮箱 */}