fix validacion log in

This commit is contained in:
Maria Sanchez 2022-08-26 08:36:55 -06:00
parent 82588354e4
commit 9adba28ee1
1 changed files with 23 additions and 8 deletions

View File

@ -9,7 +9,8 @@ import {
Box, Box,
FormControl, FormControl,
Button, Button,
Image Image,
ErrorMessage
} from "native-base"; } from "native-base";
import logo from "../assets/logo-katoikia.png"; import logo from "../assets/logo-katoikia.png";
import { Entypo } from '@expo/vector-icons'; import { Entypo } from '@expo/vector-icons';
@ -83,6 +84,8 @@ export default function LogIn({ navigation }) {
// inqulino 4 y guarda 3 // inqulino 4 y guarda 3
const user = response.message const user = response.message
if(user !== null){
if(user.user_type == '4'){ if(user.user_type == '4'){
addUser(user); addUser(user);
@ -92,10 +95,17 @@ export default function LogIn({ navigation }) {
// cambiar por ComunicadosGuarda luego // cambiar por ComunicadosGuarda luego
navigation.navigate('Comunicados', {user}) navigation.navigate('Comunicados', {user})
} }
}else{
setErrors({ ...errors,
user: 'Debe ingresar credenciales válidos'
});
}
}) })
} catch (error) { } catch (error) {
console.log("ERROR: " +error); console.log("ERROR: " +error);
} }
} }
@ -148,7 +158,7 @@ export default function LogIn({ navigation }) {
<TextInput <TextInput
name='email' name='email'
type="text" type="text"
style={styles.input} style={'email' in errors ? styles.errorMessage : styles.input}
value={credentials.email} value={credentials.email}
placeholder='Correo electrónico' placeholder='Correo electrónico'
onChangeText={onHandleChange("email")} /> onChangeText={onHandleChange("email")} />
@ -158,6 +168,7 @@ export default function LogIn({ navigation }) {
fontSize: 'xs' fontSize: 'xs'
}}>Debe ingresar un correo electrónico</FormControl.ErrorMessage> } }}>Debe ingresar un correo electrónico</FormControl.ErrorMessage> }
</FormControl> </FormControl>
<FormControl isRequired isInvalid={'password' in errors}> <FormControl isRequired isInvalid={'password' in errors}>
<FormControl.Label Text='bold'> Contraseña </FormControl.Label> <FormControl.Label Text='bold'> Contraseña </FormControl.Label>
<View style={styles.viewSection}> <View style={styles.viewSection}>
@ -165,7 +176,7 @@ export default function LogIn({ navigation }) {
<TextInput <TextInput
name='password' name='password'
type="password" type="password"
style={styles.input} style={'password' in errors ? styles.errorMessage : styles.input}
value={credentials.password} value={credentials.password}
placeholder='Contraseña' placeholder='Contraseña'
onChangeText={onHandleChange("password")} /> onChangeText={onHandleChange("password")} />
@ -196,6 +207,10 @@ export default function LogIn({ navigation }) {
> >
<Text>Continuar</Text> <Text>Continuar</Text>
</Button> </Button>
{/* {'user' in errors && <ErrorMessage _text={{
fontSize: 'xs'
}}
>Debe ingresar credenciales válidos</ErrorMessage> } */}
</VStack></View> </VStack></View>
@ -214,21 +229,22 @@ const styles = StyleSheet.create({
flex: 1, flex: 1,
paddingTop: 10, paddingTop: 10,
paddingRight: 10, paddingRight: 10,
paddingBottom: 10,
paddingLeft: 0, paddingLeft: 0,
marginTop: 50, marginTop: 50,
marginBottom: 10,
borderRadius: 4 borderRadius: 4
}, },
errorMessage: { errorMessage: {
height: 40, height: 40,
margin: 10, margin: 10,
borderWidth: 0.5,
padding: 5, padding: 5,
flex: 1, flex: 1,
paddingTop: 10, paddingTop: 10,
paddingRight: 10, paddingRight: 10,
paddingBottom: 10,
paddingLeft: 0, paddingLeft: 0,
marginTop: 50,
borderRadius: 4,
borderColor: '#be123c'
}, },
iconStyle: { iconStyle: {
@ -242,8 +258,7 @@ const styles = StyleSheet.create({
flexDirection: 'row', flexDirection: 'row',
justifyContent: 'center', justifyContent: 'center',
alignItems: 'center', alignItems: 'center',
marginBottom: 50
marginBottom: 28
}, },
container: { container: {