Модальное окно не появляется после успешной проверки в процессе регистрации
Я разрабатываю экран регистрации на React Native, где использую react-native-modal для отображения двух разных модальных окон:
- Модальное окно для проверки электронной почты, которое появляется после начала процесса регистрации.
- Модальное окно успешного завершения, которое должно появиться после завершения проверки электронной почты.
Модальное окно проверки работает как ожидается, но модальное окно успешной верификации не появляется после успешной проверки. Я попытался вызвать его с помощью события onModalHide, но оно так и не отображается.
const [showSuccessModal, setShowSuccessModal] = useState(false);
// Модальное окно проверки
<ReactNativeModal
isVisible={verification.state === "pending"}
onModalHide={() => {
if (verification.state === "success") setShowSuccessModal(true);
}}
>
{/* Содержимое модального окна проверки */}
</ReactNativeModal>
// Модальное окно успешного завершения
<ReactNativeModal isVisible={showSuccessModal}>
{/* Содержимое модального окна успешного завершения */}
</ReactNativeModal>
На всякий случай вот полный код экрана
import { useSignUp } from "@clerk/clerk-expo";
import { Link, router } from "expo-router";
import { useState } from "react";
import { Alert, Image, ScrollView, Text, View } from "react-native";
import { ReactNativeModal } from "react-native-modal";
import CustomButton from "@/components/CustomButton";
import InputField from "@/components/InputField";
import OAuth from "@/components/OAuth";
import { icons, images } from "@/constants";
const SignUp = () => {
const { isLoaded, signUp, setActive } = useSignUp();
const [showSuccessModal, setShowSuccessModal] = useState(false);
const [form, setForm] = useState({
name: "",
email: "",
password: "",
});
const [verification, setVerification] = useState({
state: "default",
error: "",
code: "",
});
const onSignUpPress = async () => {
if (!isLoaded) {
return;
}
try {
await signUp.create({
emailAddress: form.email,
password: form.password,
});
await signUp.prepareEmailAddressVerification({ strategy: "email_code" });
setVerification({
...verification,
state: "pending",
});
} catch (err: any) {
Alert.alert("Error", err.errors[0].longMessage);
}
};
const onPressVerify = async () => {
if (!isLoaded) {
return;
}
try {
const completeSignUp = await signUp.attemptEmailAddressVerification({
code: verification.code,
});
if (completeSignUp.status === "complete") {
await setActive({ session: completeSignUp.createdSessionId });
setVerification({ ...verification, state: "success" });
} else {
setVerification({
...verification,
error: "Verification failed",
state: "failed",
});
}
} catch (err: any) {
setVerification({
...verification,
error: err.errors[0].longMessage,
state: "failed",
});
}
};
return (
<ScrollView className="flex-1 bg-white">
<View className="flex-1 bg-white">
<View className="relative w-full h-[250px]">
<Image source={images.signUpCar} className="z-0 w-full h-[250px]" />
<Text className="text-2xl text-black font-JakartaSemiBold absolute bottom-5 left-5">
Create Your Account
</Text>
</View>
<View className="p-5">
<InputField
label="Name"
placeholder="Enter name"
icon={icons.person}
value={form.name}
onChangeText={(value) => setForm({ ...form, name: value })}
/>
<InputField
label="Email"
placeholder="Enter email"
icon={icons.email}
textContentType="emailAddress"
value={form.email}
onChangeText={(value) => setForm({ ...form, email: value })}
/>
<InputField
label="Password"
placeholder="Enter password"
icon={icons.lock}
secureTextEntry={true}
textContentType="password"
value={form.password}
onChangeText={(value) => setForm({ ...form, password: value })}
/>
<CustomButton
title="Sign Up"
onPress={onSignUpPress}
className="mt-6"
/>
<OAuth />
<Link
href="/sign-in"
className="text-lg text-center text-general-200 mt-10"
>
Already have an account?{" "}
<Text className="text-primary-500">Log In</Text>
</Link>
</View>
<ReactNativeModal
isVisible={verification.state === "pending"}
onModalHide={() => {
if (verification.state === "success") setShowSuccessModal(true);
}}
>
<View className="bg-white px-7 py-9 rounded-2xl min-h-[300px]">
<Text className="text-2xl font-JakartaExtraBold mb-2">
Verification
</Text>
<Text className="font-Jakarta mb-5">
We've sent a verification code to {form.email}
</Text>
<InputField
label="code"
icon={icons.lock}
placeholder="1234"
value={verification.code}
keyboardType="numeric"
onChangeText={(code) =>
setVerification({ ...verification, code })
}
/>
{verification.error && (
<Text className="text-red-500 text-sm mt-1">
{verification.error}
</Text>
)}
<CustomButton
title="Verify Email"
onPress={onPressVerify}
className="mt-5 bg-success-500"
/>
</View>
</ReactNativeModal>
<ReactNativeModal isVisible={showSuccessModal}>
<View className="bg-white px-7 py-9 rounded-2xl min-h-[300px]">
<Image
source={images.check}
className="w-[110px] h-[110px] mx-auto my-5"
/>
<Text className="text-3xl font-JakartaBold text-center">
Verified
</Text>
<Text className="text-base text-gray-400 font-Jakarta text-center mt-2">
You have successfully verified your account.
</Text>
<CustomButton
title="Browse Home"
onPress={() => router.replace("/(root)/(tabs)/home")}
className="mt-5"
></CustomButton>
</View>
</ReactNativeModal>
</View>
</ScrollView>
);
};
export default SignUp;