|
| 1 | +import React, {useState, useEffect} from 'react'; |
| 2 | +import { View, AsyncStorage, KeyboardAvoidingView, Platform, Image, Text, TextInput, StyleSheet, TouchableOpacity } from 'react-native'; |
| 3 | + |
| 4 | +import api from '../services/api'; |
| 5 | +import logo from '../assets/logo.png'; |
| 6 | + |
| 7 | + |
| 8 | +export default function Login({ navigation }) { |
| 9 | + const [email, setEmail] = useState(''); |
| 10 | + const [techs, setTechs] = useState(''); |
| 11 | + |
| 12 | + useEffect(() => { |
| 13 | + AsyncStorage.getItem('user').then(user => { |
| 14 | + if(user){ |
| 15 | + navigation.navigate('List'); |
| 16 | + } |
| 17 | + }) |
| 18 | + }, []); |
| 19 | + |
| 20 | + async function handleSubmit(){ |
| 21 | + const response = await api.post('/session',{ |
| 22 | + email |
| 23 | + }) |
| 24 | + const {_id} = response.data; |
| 25 | + |
| 26 | + await AsyncStorage.setItem('user', _id); |
| 27 | + await AsyncStorage.setItem('techs', techs); |
| 28 | + |
| 29 | + navigation.navigate('List'); |
| 30 | + } |
| 31 | + |
| 32 | + return ( |
| 33 | + <KeyboardAvoidingView /*enabled={Platform.OS === 'ios'}*/ behavior="padding" style = {styles.contanier}> |
| 34 | + <Image source={logo} /> |
| 35 | + <View style={styles.form}> |
| 36 | + <Text style={styles.label}>SEU E-MAIL *</Text> |
| 37 | + <TextInput |
| 38 | + style={styles.input} |
| 39 | + placeholder="Seu e-mail" |
| 40 | + placeholderTextColor="#999" |
| 41 | + keyboardType="email-address" |
| 42 | + autoCapitalize="none" |
| 43 | + autoCorrect={false} |
| 44 | + value={email} |
| 45 | + onChangeText = {setEmail} |
| 46 | + /> |
| 47 | + |
| 48 | + |
| 49 | + <Text style={styles.label}>TECNOLOGIAS *</Text> |
| 50 | + <TextInput |
| 51 | + style={styles.input} |
| 52 | + placeholder="Tecnologias de interesse" |
| 53 | + placeholderTextColor="#999" |
| 54 | + autoCapitalize="words" |
| 55 | + autoCorrect={false} |
| 56 | + onChangeText={setTechs} |
| 57 | + /> |
| 58 | + |
| 59 | + <TouchableOpacity onPress={handleSubmit} style={styles.button}> |
| 60 | + <Text style={styles.buttonText}>Encontrar spots</Text> |
| 61 | + </TouchableOpacity> |
| 62 | + </View> |
| 63 | + </KeyboardAvoidingView> |
| 64 | + ); |
| 65 | +} |
| 66 | + |
| 67 | +const styles = StyleSheet.create({ |
| 68 | + contanier :{ |
| 69 | + flex: 1, |
| 70 | + justifyContent: 'center', |
| 71 | + alignItems: 'center', |
| 72 | + }, |
| 73 | + |
| 74 | + form: { |
| 75 | + alignSelf: 'stretch', |
| 76 | + paddingHorizontal: 30, |
| 77 | + marginTop: 30, |
| 78 | + }, |
| 79 | + |
| 80 | + label: { |
| 81 | + fontWeight: 'bold', |
| 82 | + color: '#444', |
| 83 | + marginBottom: 8, |
| 84 | + }, |
| 85 | + |
| 86 | + input:{ |
| 87 | + borderWidth: 1, |
| 88 | + borderColor: '#ddd', |
| 89 | + paddingHorizontal: 20, |
| 90 | + fontSize: 16, |
| 91 | + color:'#444', |
| 92 | + height: 44, |
| 93 | + marginBottom: 20, |
| 94 | + borderRadius: 2, |
| 95 | + }, |
| 96 | + |
| 97 | + button:{ |
| 98 | + borderRadius: 2, |
| 99 | + backgroundColor: '#f05a5b', |
| 100 | + justifyContent: 'center', |
| 101 | + alignItems: 'center', |
| 102 | + height:42, |
| 103 | + }, |
| 104 | + |
| 105 | + buttonText:{ |
| 106 | + color: '#fff', |
| 107 | + fontWeight: 'bold', |
| 108 | + fontSize:16, |
| 109 | + }, |
| 110 | +}); |
| 111 | + |
0 commit comments