1
- import React , { useState } from "react" ;
1
+ import type { SubmitHandler } from "react-hook-form " ;
2
2
import { View } from "react-native" ;
3
3
import Animated , { FadeInDown , FadeOutUp } from "react-native-reanimated" ;
4
- import { useSignIn } from "@clerk/clerk-expo" ;
5
4
import { zodResolver } from "@hookform/resolvers/zod" ;
6
5
import { Controller , FormProvider , useForm } from "react-hook-form" ;
7
6
@@ -16,31 +15,28 @@ import { Text } from "~/components/ui/text";
16
15
import { Loader2 } from "~/lib/icons/loader-2" ;
17
16
import { cn } from "~/lib/utils" ;
18
17
19
- const ResetPasswordForm = ( ) => {
20
- const { signIn } = useSignIn ( ) ;
21
- const [ successfulCreation , setSuccessfulCreation ] = useState ( false ) ;
22
- const [ error , setError ] = useState ( "" ) ;
18
+ export interface ResetPasswordFormProps {
19
+ onSubmit : SubmitHandler < RequestPasswordReset > ;
20
+ isLoading : boolean ;
21
+ error : string ;
22
+ successfulCreation : boolean ;
23
+ onVerificationSuccess : ( ) => void ;
24
+ }
23
25
26
+ const ResetPasswordForm : React . FC < ResetPasswordFormProps > = ( {
27
+ onSubmit,
28
+ isLoading,
29
+ error,
30
+ successfulCreation,
31
+ onVerificationSuccess,
32
+ } ) => {
24
33
const form = useForm < RequestPasswordReset > ( {
25
34
resolver : zodResolver ( RequestPasswordResetSchema ) ,
26
35
defaultValues : {
27
36
email : "" ,
28
37
} ,
29
38
} ) ;
30
39
31
- const onSubmit = async ( data : RequestPasswordReset ) => {
32
- try {
33
- await signIn ! . create ( {
34
- strategy : "reset_password_email_code" ,
35
- identifier : data . email ,
36
- } ) ;
37
- setSuccessfulCreation ( true ) ;
38
- setError ( "" ) ;
39
- } catch ( err : unknown ) {
40
- setError ( err . errors [ 0 ] . message ) ;
41
- }
42
- } ;
43
-
44
40
return (
45
41
< View className = "flex-1 justify-center gap-8" >
46
42
< Text className = "text-3xl font-bold" > Reset Password</ Text >
@@ -88,9 +84,9 @@ const ResetPasswordForm = () => {
88
84
< Button
89
85
size = { "lg" }
90
86
onPress = { form . handleSubmit ( onSubmit ) }
91
- disabled = { form . formState . isSubmitting }
87
+ disabled = { isLoading }
92
88
>
93
- { form . formState . isSubmitting ? (
89
+ { isLoading ? (
94
90
< View className = "flex-row items-center justify-center gap-3" >
95
91
< Loader2
96
92
size = { 24 }
@@ -114,9 +110,7 @@ const ResetPasswordForm = () => {
114
110
) }
115
111
116
112
{ successfulCreation && (
117
- < ResetPasswordVerificationForm
118
- onSuccess = { ( ) => setSuccessfulCreation ( false ) }
119
- />
113
+ < ResetPasswordVerificationForm onSuccess = { onVerificationSuccess } />
120
114
) }
121
115
</ View >
122
116
) ;
0 commit comments