Files
EMI-ExpoAPP/components/Login.js
2022-12-23 22:23:11 -05:00

109 lines
2.8 KiB
JavaScript

import React, { useState } from 'react';
import { Text, View, StyleSheet, Image } from 'react-native';
import { TextInput, Button, HelperText } from 'react-native-paper';
import API from './../API.js';
import { useNavigation } from '@react-navigation/native';
import i18n from "../i18nMessages.js";
let LoginForm = () => {
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [error, setError] = useState('');
const navigation = useNavigation();
const loginCall = async ()=>{
let r = await API.logIn(email.trim(), password);
if (r.status === "ok") return navigation.reset({
index: 0,
routes: [{ name: 'MainNavigation' }],
});
//console.log(r)
setError(r.status);
//alert(i18n.t('message.wrongInformation'))
};
return (
<View style={styles.mainView}>
<Image
style={styles.logo}
source={require('./../assets/icon.png')}
/>
<Text style={styles.header}>EMI Social</Text>
<Text >{i18n.t("message.login")}</Text>
<TextInput
style={styles.input}
onChangeText={text => setEmail(text)}
defaultValue={email}
placeholder="email"
label={i18n.t("message.email")}
autoCapitalize='none'
autoComplete='email'
autoCorrect={false}
mode="outlined"
/>
{error !== '' && error !== 'incorrect password' ? <HelperText type="error" visible={true}>
{i18n.t("message.invalidEmail")}
</HelperText> : <></>}
<TextInput
style={styles.input}
onChangeText={text => setPassword(text)}
defaultValue={password}
placeholder="password"
textContentType="password"
label={i18n.t("message.password")}
secureTextEntry={true}
autoCapitalize='none'
autoComplete='email'
autoCorrect={false}
mode="outlined"
/>
{error === 'incorrect password' ? <HelperText type="error" visible={true}>
{i18n.t("message.reviewPassword")}
</HelperText> : <></>}
<Button
style={styles.button}
onPress={async () => {
await loginCall();
}}
>{i18n.t("message.submit")}</Button>
</View>
);
}
export default LoginForm;
const styles = StyleSheet.create({
mainView: {
backgroundColor: 'white',
flex: 1,
flexDirection: "column",
justifyContent: "center",
padding: 15,
width: "100%",
alignContent: 'center',
alignItems: 'center',
},
header: {
fontFamily: 'Helvetica-Bold',
fontSize: 42,
textAlign: "left",
paddingBottom: 15,
color: '#777',
alignContent: 'center'
},
logo:{
width: 250,
height: 250,
justifyContent: 'center',
alignItems: 'center',
},
input:{
backgroundColor: 'white',
width: "80%"
},
button:{
marginTop: 10,
}
});