import { fetchApi } from "@/lib/server-api-util"; import { useState } from "react"; import { useTranslation } from "react-i18next"; import { ActivityIndicator, TextInput, TouchableOpacity, View } from "react-native"; import { ThemedText } from "../ThemedText"; import { Steps } from "./phoneLogin"; interface LoginProps { setSteps: (steps: Steps) => void; setPhone: (phone: string) => void; phone: string; updateUrlParam: (status: string, value: string) => void; } const Phone = ({ setSteps, setPhone, phone, updateUrlParam }: LoginProps) => { const { t } = useTranslation(); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(''); const sendVerificationCode = async () => { if (!/^1[3-9]\d{9}$/.test(phone)) { setError(t("auth.telLogin.phoneInvalid", { ns: 'login' })); return; } try { setIsLoading(true); await fetchApi(`/iam/veritification-code`, { method: 'POST', body: JSON.stringify({ phone: phone }), }) setSteps('code') updateUrlParam("status", "code"); setIsLoading(false); } catch (error) { setPhone("") setIsLoading(false); // console.error(t("auth.telLogin.sendCodeError", { ns: 'login' }), error); } }; return {/* 手机号输入框 */} {t('auth.telLogin.title', { ns: 'login' })} {error} { setPhone(text); setError(''); }} keyboardType="email-address" autoCapitalize="none" /> {/* 发送验证码 */} {isLoading ? ( ) : ( {t('auth.telLogin.sendCode', { ns: 'login' })} )} } export default Phone