-
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.
* initial screen for reset password. * add verify code screen. * add new password screen. * refactor. * finish reset password. * refactor. * remove comment.
- Loading branch information
Showing
17 changed files
with
510 additions
and
11 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
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
77 changes: 77 additions & 0 deletions
77
src/app/screens/ResetPassword/ForgotPasswordScreen/index.js
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,77 @@ | ||
import React, { useCallback, useState } from 'react'; | ||
import { View, SafeAreaView, TextInput, Text } from 'react-native'; | ||
|
||
import CustomButton from '@components/CustomButton'; | ||
import { ROUTES } from '@constants/routes'; | ||
import { COLORS } from '@constants/colors'; | ||
import { resetPassword } from '@services/AuthService'; | ||
|
||
import { validateEmail } from '@utils/email'; | ||
|
||
import styles from './styles'; | ||
|
||
function ForgotPasswordScreen({ navigation }) { | ||
const [email, setEmail] = useState(''); | ||
const [loading, setLoading] = useState(false); | ||
const [error, setError] = useState(''); | ||
|
||
const emailValid = validateEmail(email); | ||
const disable = !emailValid; | ||
|
||
const onEmailSubmit = useCallback(async () => { | ||
setLoading(true); | ||
const response = await resetPassword(email); | ||
if (response.ok) { | ||
navigation.navigate(ROUTES.VerifyCode, { email }); | ||
} else { | ||
setError(response.data.reason); | ||
} | ||
setLoading(false); | ||
}, [email, navigation]); | ||
|
||
const onNavigateToLogin = useCallback(() => { | ||
navigation.reset({ | ||
index: 0, | ||
routes: [{ name: ROUTES.Login }] | ||
}); | ||
}, [navigation]); | ||
|
||
return ( | ||
<SafeAreaView style={styles.container}> | ||
<Text style={styles.title}>Olvidaste tu contraseña?</Text> | ||
<Text style={styles.explanation}> | ||
Para reiniciar tu contraseña ingresa tu email registrado y te enviaremos | ||
un código de verificación. | ||
</Text> | ||
<View> | ||
<TextInput | ||
style={styles.input} | ||
onChangeText={setEmail} | ||
value={email} | ||
label="Email" | ||
placeholder="Email" | ||
keyboardType="email-address" | ||
/> | ||
<CustomButton | ||
text="ENVIAR CÓDIGO" | ||
style={[styles.loginButton, disable && styles.buttonDisable]} | ||
textStyle={disable ? styles.textDisable : styles.loginButtonText} | ||
onPress={onEmailSubmit} | ||
disable={disable} | ||
loading={loading} | ||
loaderColor={COLORS.white} | ||
/> | ||
<CustomButton | ||
text="CANCELAR" | ||
style={styles.loginButton} | ||
textStyle={styles.loginButtonText} | ||
onPress={onNavigateToLogin} | ||
disable={loading} | ||
/> | ||
</View> | ||
{!!error && <Text>{error}</Text>} | ||
</SafeAreaView> | ||
); | ||
} | ||
|
||
export default ForgotPasswordScreen; |
49 changes: 49 additions & 0 deletions
49
src/app/screens/ResetPassword/ForgotPasswordScreen/styles.js
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,49 @@ | ||
import { StyleSheet } from 'react-native'; | ||
import { COLORS } from '@constants/colors'; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
backgroundColor: COLORS.white | ||
}, | ||
title: { | ||
fontSize: 28, | ||
color: COLORS.main | ||
}, | ||
explanation: { | ||
margin: 30, | ||
marginTop: 10, | ||
textAlign: 'center', | ||
color: COLORS.gray | ||
}, | ||
input: { | ||
backgroundColor: COLORS.white, | ||
borderColor: COLORS.gray, | ||
borderWidth: 1, | ||
borderRadius: 5, | ||
marginBottom: 20, | ||
padding: 5, | ||
width: 200 | ||
}, | ||
loginButton: { | ||
backgroundColor: COLORS.main, | ||
borderStyle: 'solid', | ||
borderWidth: 1, | ||
borderColor: COLORS.main, | ||
marginBottom: 10 | ||
}, | ||
buttonDisable: { | ||
borderColor: COLORS.gray, | ||
backgroundColor: COLORS.gray | ||
}, | ||
loginButtonText: { | ||
color: COLORS.white | ||
}, | ||
textDisable: { | ||
color: COLORS.white | ||
} | ||
}); | ||
|
||
export default styles; |
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,97 @@ | ||
import React, { useCallback, useState } from 'react'; | ||
import { View, SafeAreaView, TextInput, Text } from 'react-native'; | ||
|
||
import CustomButton from '@components/CustomButton'; | ||
import OkModal from '@components/OkModal'; | ||
import { ROUTES } from '@constants/routes'; | ||
import { COLORS } from '@constants/colors'; | ||
import { newPassword } from '@services/AuthService'; | ||
|
||
import styles from './styles'; | ||
|
||
function NewPasswordScreen({ navigation, route }) { | ||
const [password, setPassword] = useState(''); | ||
const [confirmPw, setConfirmPw] = useState(''); | ||
const [loading, setLoading] = useState(false); | ||
const [error, setError] = useState(''); | ||
|
||
const [openModal, setOpenModal] = useState(false); | ||
|
||
const email = route?.params?.email; | ||
const code = route?.params?.code; | ||
|
||
const disable = !password.length > 0 || password !== confirmPw; | ||
|
||
const onNewPasswordSubmit = useCallback(async () => { | ||
setLoading(true); | ||
const response = await newPassword(email, code, password); | ||
if (response.ok) { | ||
setOpenModal(true); | ||
} else { | ||
setError(response.data.reason); | ||
} | ||
setLoading(false); | ||
}, [email, code, password]); | ||
|
||
const onCloseModal = useCallback(() => { | ||
setOpenModal(false); | ||
onNavigateToLogin(); | ||
}, [onNavigateToLogin]); | ||
|
||
const onNavigateToLogin = useCallback(() => { | ||
navigation.reset({ | ||
index: 0, | ||
routes: [{ name: ROUTES.Login }] | ||
}); | ||
}, [navigation]); | ||
|
||
return ( | ||
<SafeAreaView style={styles.container}> | ||
<OkModal | ||
text="Se cambió la contraseña correctamente" | ||
closeText="Volver a login" | ||
visible={openModal} | ||
onPress={onCloseModal} | ||
/> | ||
<Text style={styles.title}>Nueva Contraseña</Text> | ||
<Text style={styles.explanation}>Ingresa la nueva contraseña</Text> | ||
<View> | ||
<TextInput | ||
style={styles.input} | ||
onChangeText={setPassword} | ||
value={password} | ||
label="Password" | ||
placeholder="Nueva Contraseña" | ||
secureTextEntry | ||
/> | ||
<TextInput | ||
style={styles.input} | ||
onChangeText={setConfirmPw} | ||
value={confirmPw} | ||
label="Confirm Password" | ||
placeholder="Confirmar Contraseña" | ||
secureTextEntry | ||
/> | ||
<CustomButton | ||
text="CAMBIAR CONTRASEÑA" | ||
style={[styles.loginButton, disable && styles.buttonDisable]} | ||
textStyle={disable ? styles.textDisable : styles.loginButtonText} | ||
onPress={onNewPasswordSubmit} | ||
disable={disable} | ||
loading={loading} | ||
loaderColor={COLORS.white} | ||
/> | ||
<CustomButton | ||
text="CANCELAR" | ||
style={styles.loginButton} | ||
textStyle={styles.loginButtonText} | ||
onPress={onNavigateToLogin} | ||
disable={loading} | ||
/> | ||
</View> | ||
{!!error && <Text>{error}</Text>} | ||
</SafeAreaView> | ||
); | ||
} | ||
|
||
export default NewPasswordScreen; |
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,49 @@ | ||
import { StyleSheet } from 'react-native'; | ||
import { COLORS } from '@constants/colors'; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
backgroundColor: COLORS.white | ||
}, | ||
title: { | ||
fontSize: 28, | ||
color: COLORS.main | ||
}, | ||
explanation: { | ||
margin: 30, | ||
marginTop: 10, | ||
textAlign: 'center', | ||
color: COLORS.gray | ||
}, | ||
input: { | ||
backgroundColor: COLORS.white, | ||
borderColor: COLORS.gray, | ||
borderWidth: 1, | ||
borderRadius: 5, | ||
marginBottom: 20, | ||
padding: 5, | ||
width: 200 | ||
}, | ||
loginButton: { | ||
backgroundColor: COLORS.main, | ||
borderStyle: 'solid', | ||
borderWidth: 1, | ||
borderColor: COLORS.main, | ||
marginBottom: 10 | ||
}, | ||
buttonDisable: { | ||
borderColor: COLORS.gray, | ||
backgroundColor: COLORS.gray | ||
}, | ||
loginButtonText: { | ||
color: COLORS.white | ||
}, | ||
textDisable: { | ||
color: COLORS.white | ||
} | ||
}); | ||
|
||
export default styles; |
Oops, something went wrong.