Created
December 3, 2019 13:02
-
-
Save diego3g/252e9394345e21b459656b84fdc6ad03 to your computer and use it in GitHub Desktop.
RSXP Login
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
import React, { useState, useRef } from 'react'; | |
import { | |
TouchableWithoutFeedback, | |
KeyboardAvoidingView, | |
Keyboard, | |
Platform, | |
ActivityIndicator, | |
} from 'react-native'; | |
import { useSelector, useDispatch } from 'react-redux'; | |
import { signInRequest } from '../../store/modules/auth/actions'; | |
import { | |
Container, | |
Logo, | |
FormContainer, | |
InputContainer, | |
InputTitle, | |
Input, | |
EnvelopeIcon, | |
LockIcon, | |
SubmitButton, | |
SubmitButtonText, | |
NewAccountButton, | |
NewAccountButtonText, | |
ForgotPasswordButton, | |
ForgotPasswordButtonText, | |
} from './styles'; | |
export default function Login({ navigation }) { | |
const loading = useSelector(state => state.auth.loading); | |
const [email, setEmail] = useState(); | |
const [password, setPassword] = useState(); | |
const passwordInputRef = useRef(); | |
const dispatch = useDispatch(); | |
async function handleSubmit() { | |
if (!email || !password) return; | |
Keyboard.dismiss(); | |
dispatch(signInRequest(email, password)); | |
} | |
function handleCreateAccount() { | |
navigation.navigate('CreateAccount'); | |
} | |
return ( | |
<TouchableWithoutFeedback | |
onPress={Keyboard.dismiss} | |
enabled={Platform.OS === 'ios'} | |
> | |
<KeyboardAvoidingView | |
behavior={Platform.OS === 'ios' ? 'padding' : null} | |
style={{ flex: 1 }} | |
> | |
<Container> | |
<Logo /> | |
<FormContainer> | |
<InputTitle>E-MAIL</InputTitle> | |
<InputContainer> | |
<Input | |
placeholder="Digite seu e-mail" | |
autoCapitalize="none" | |
autoCorrect={false} | |
keyboardType="email-address" | |
onChangeText={text => setEmail(text)} | |
value={email} | |
returnKeyType="next" | |
onSubmitEditing={() => passwordInputRef.current.focus()} | |
/> | |
<EnvelopeIcon /> | |
</InputContainer> | |
<InputTitle>SENHA</InputTitle> | |
<InputContainer> | |
<Input | |
placeholder="Sua senha secreta" | |
autoCapitalize="none" | |
autoCorrect={false} | |
secureTextEntry | |
onChangeText={text => setPassword(text)} | |
value={password} | |
ref={passwordInputRef} | |
returnKeyType="send" | |
onSubmitEditing={handleSubmit} | |
/> | |
<LockIcon /> | |
</InputContainer> | |
<SubmitButton onPress={handleSubmit}> | |
{loading ? ( | |
<ActivityIndicator color="#FFF" size="small" /> | |
) : ( | |
<SubmitButtonText>EMBARCAR NO FOGUETE</SubmitButtonText> | |
)} | |
</SubmitButton> | |
<NewAccountButton onPress={handleCreateAccount}> | |
<NewAccountButtonText>AINDA NÃO TENHO CONTA</NewAccountButtonText> | |
</NewAccountButton> | |
<ForgotPasswordButton | |
onPress={() => navigation.navigate('ForgotPassword')} | |
> | |
<ForgotPasswordButtonText> | |
Esqueci minha senha | |
</ForgotPasswordButtonText> | |
</ForgotPasswordButton> | |
</FormContainer> | |
</Container> | |
</KeyboardAvoidingView> | |
</TouchableWithoutFeedback> | |
); | |
} |
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
import styled from 'styled-components/native'; | |
import { MaterialIcons } from '@expo/vector-icons'; | |
import { StyleSheet } from 'react-native'; | |
import logoImage from '../../../assets/logo.png'; | |
export const Container = styled.SafeAreaView` | |
flex: 1; | |
background: #100f12; | |
justify-content: center; | |
`; | |
export const Logo = styled.Image.attrs({ | |
source: logoImage, | |
})` | |
align-self: center; | |
margin-bottom: 50px; | |
`; | |
export const FormContainer = styled.View` | |
padding: 0 30px; | |
`; | |
export const InputTitle = styled.Text` | |
color: #999; | |
font-weight: bold; | |
`; | |
export const InputContainer = styled.View` | |
flex-direction: row; | |
border-bottom-width: ${StyleSheet.hairlineWidth}; | |
border-color: rgba(255, 255, 255, 0.2); | |
justify-content: space-between; | |
margin-bottom: 30px; | |
`; | |
export const Input = styled.TextInput.attrs({ | |
placeholderTextColor: '#999', | |
})` | |
height: 48px; | |
font-size: 17px; | |
color: #fff; | |
flex: 1; | |
`; | |
export const EnvelopeIcon = styled(MaterialIcons).attrs({ | |
name: 'mail-outline', | |
})` | |
color: #999; | |
font-size: 20px; | |
`; | |
export const LockIcon = styled(MaterialIcons).attrs({ | |
name: 'lock-outline', | |
})` | |
color: #999; | |
font-size: 20px; | |
`; | |
export const SubmitButton = styled.TouchableOpacity` | |
height: 50px; | |
background-color: #7159c1; | |
justify-content: center; | |
align-items: center; | |
`; | |
export const SubmitButtonText = styled.Text` | |
color: #e6e6e6; | |
font-size: 14px; | |
font-weight: bold; | |
letter-spacing: 2.8px; | |
`; | |
export const NewAccountButton = styled.TouchableOpacity` | |
height: 42px; | |
background-color: #00f5ff; | |
justify-content: center; | |
align-items: center; | |
margin-top: 10px; | |
`; | |
export const NewAccountButtonText = styled.Text` | |
color: #100f12; | |
font-size: 13px; | |
font-weight: bold; | |
letter-spacing: 2.8px; | |
`; | |
export const ForgotPasswordButton = styled.TouchableOpacity` | |
margin: 30px 0 50px; | |
align-items: center; | |
`; | |
export const ForgotPasswordButtonText = styled.Text` | |
color: #999; | |
font-size: 16px; | |
`; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment