-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from bambu-group-03/recover_password
Recover password
- Loading branch information
Showing
6 changed files
with
139 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { createNativeStackNavigator } from '@react-navigation/native-stack'; | ||
import * as React from 'react'; | ||
import { FormType, RecoverPasswordScreen } from './recover-password-screen'; | ||
Check failure on line 3 in src/screens/login/login-navigator.tsx GitHub Actions / Lint TS (eslint, prettier)
|
||
import Login from '.'; | ||
import { SubmitHandler } from 'react-hook-form'; | ||
|
||
export type LoginStackParamList = { | ||
Login: undefined; | ||
RecoverPasswordScreen: { | ||
email: string; | ||
}; | ||
}; | ||
|
||
const Stack = createNativeStackNavigator<LoginStackParamList>(); | ||
|
||
export const LoginNavigator = () => { | ||
return ( | ||
<Stack.Navigator> | ||
<Stack.Screen name="Login" component={Login} /> | ||
</Stack.Navigator> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { View, Text, ControlledInput, Button } from '@/ui'; | ||
import { LoginStackParamList } from './login-navigator'; | ||
import { RouteProp, useNavigation, useRoute } from '@react-navigation/native'; | ||
import { useState } from 'react'; | ||
import * as z from 'zod'; | ||
import { SubmitHandler, useForm } from 'react-hook-form'; | ||
import { zodResolver } from '@hookform/resolvers/zod'; | ||
import { sendPasswordReset } from './firebase'; | ||
|
||
const onResetSubmit: ResetFormProps['onResetSubmit'] = (data) => { | ||
try { | ||
sendPasswordReset(data.email).then(() => {}); | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
}; | ||
|
||
const schema = z.object({ | ||
email: z | ||
.string({ | ||
required_error: 'Email is required', | ||
}) | ||
.email('Invalid email format'), | ||
}); | ||
|
||
export type FormType = z.infer<typeof schema>; | ||
|
||
export type ResetFormProps = { | ||
onResetSubmit?: SubmitHandler<FormType>; | ||
}; | ||
|
||
export const RecoverPasswordScreen = () => { | ||
const route = | ||
useRoute<RouteProp<LoginStackParamList, 'RecoverPasswordScreen'>>(); | ||
const { email } = route.params; | ||
|
||
const [emailRecover, setEmailRecover] = useState(email); | ||
|
||
const { handleSubmit, control } = useForm<FormType>({ | ||
resolver: zodResolver(schema), | ||
}); | ||
|
||
let navigate = useNavigation(); | ||
|
||
return ( | ||
<View className="flex-1 justify-center p-4 "> | ||
<Text testID="form-title" variant="h1" className="pb-6 text-center"> | ||
Reset Password | ||
</Text> | ||
|
||
<ControlledInput | ||
testID="email-input" | ||
placeholder={emailRecover} | ||
control={control} | ||
name="email" | ||
label="Email" | ||
/> | ||
<Button | ||
testID="login-button" | ||
label="Reset Password" | ||
onPress={handleSubmit(onResetSubmit)} | ||
variant="primary" | ||
/> | ||
|
||
<Button | ||
testID="go-back-button" | ||
label="Volver atras" | ||
onPress={() => { | ||
navigate.navigate('Login'); | ||
}} | ||
variant="primary" | ||
/> | ||
</View> | ||
); | ||
}; |