Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contruindo tela de login e Registro #10

Open
wants to merge 23 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
dc75f74
feat: adding ayncStorage and types of axios
joaoprferreira May 23, 2023
7cdaabe
refactor: removing propiets to resize elements in view
joaoprferreira May 23, 2023
8a44093
feat: Building env
joaoprferreira May 23, 2023
b5884c1
feta: Building api of services
joaoprferreira May 23, 2023
63d65f2
feat: Building types of api
joaoprferreira May 23, 2023
73fb7d3
feat: Building services of auth
joaoprferreira May 23, 2023
99d2111
feat: Building routes and adding Button of left inn header
joaoprferreira May 23, 2023
886eb3b
feat: Changing variables enviroment
joaoprferreira May 25, 2023
b5d455b
feat: adding base url
joaoprferreira May 25, 2023
74c7f9b
feat: adding right icon in form password
joaoprferreira May 25, 2023
1537052
feat: adding react native toast and icons
joaoprferreira May 25, 2023
ad13900
feat: typing Input props
joaoprferreira May 25, 2023
6aa442d
feat: Changing styles of input
joaoprferreira May 25, 2023
a5ea548
feat: adding forms and eye to password
joaoprferreira May 25, 2023
71ee03f
feat: adding color placeholderColor and labelColor
joaoprferreira May 25, 2023
119cfeb
feat: adding validation schema
joaoprferreira May 25, 2023
82fb9b5
feat: Changing style of register
joaoprferreira May 25, 2023
4e73466
feat: removing service of auth of user
joaoprferreira May 25, 2023
0fd009f
feat: adding style of login
joaoprferreira May 25, 2023
2943928
feat: Building hook of login
joaoprferreira May 25, 2023
d0524e4
feat: Building schema validation of register
joaoprferreira May 25, 2023
9873d64
feat: exporting Stack navigation ta typing
joaoprferreira May 25, 2023
de460b7
yarn lock
joaoprferreira May 25, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@
"test": "jest"
},
"dependencies": {
"@react-native-async-storage/async-storage": "^1.18.1",
"@types/node": "^18.16.0",
"@types/yup": "^0.32.0",
"axios": "^1.4.0",
"formik": "^2.2.9",
"react": "18.2.0",
"react-native": "0.71.7"
"react-native": "0.71.7",
"react-native-toast-message": "^2.1.6",
"yup": "^1.1.1"
},
"devDependencies": {
"@appbalance/ui": "^1.0.8",
Expand All @@ -38,6 +43,7 @@
"react-native-screens": "^3.20.0",
"react-native-svg": "^13.9.0",
"react-native-svg-transformer": "^1.0.0",
"react-native-vector-icons": "^9.2.0",
"react-test-renderer": "18.2.0",
"styled-components": "^5.3.10",
"typescript": "4.8.4"
Expand Down
10 changes: 10 additions & 0 deletions src/commons/constants/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const STAGE = {
// API

__DEV__: {
BASE_API:
'https://xfdewphuedg6qmsoha4ngq3kha0gkxdq.lambda-url.sa-east-1.on.aws',
},
};

export { STAGE };
3 changes: 3 additions & 0 deletions src/components/Input/@types/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import React from 'react';
import { TextInputProps } from 'react-native';

export interface InputProps extends TextInputProps {
placeholder: string | undefined;
onChangeText: (text: string) => void;
value: string | undefined;
height?: string;
marginBottom?: string;
labelColor?: string;
IconRight?: any;
}
35 changes: 26 additions & 9 deletions src/components/Input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,43 @@ import React from 'react';
import * as S from './styles';

import { InputProps } from './@types';
import { Text, View } from 'react-native';

import Button from '../elements/Button';

const Input = ({
value,
height,
placeholder,
onChangeText,
marginBottom,
labelColor,
IconRight,
...props
}: InputProps) => {
return (
<S.InputContainer marginBottom={marginBottom}>
{!!value?.length && (
<S.Label labelColor={labelColor}>{placeholder}</S.Label>
<S.InputContainer marginBottom={marginBottom} height={height}>
<View style={{ flexDirection: 'column', width: '90%' }}>
{!!value?.length && (
<S.Label labelColor={labelColor}>{placeholder}</S.Label>
)}
<S.Input
placeholder={placeholder}
onChangeText={onChangeText}
value={value}
{...props}
/>
</View>
{IconRight && (
<View
style={{
justifyContent: 'center',
}}>
<Button height="20px" width="20px" variant="text">
<Text>O</Text>
</Button>
</View>
)}
<S.Input
placeholder={placeholder}
onChangeText={onChangeText}
value={value}
{...props}
/>
</S.InputContainer>
);
};
Expand Down
13 changes: 8 additions & 5 deletions src/components/Input/styles.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import styled from 'styled-components/native';

export const InputContainer = styled.View<{ marginBottom?: string }>`
display: flex;
flex-direction: column;
export const InputContainer = styled.View<{
marginBottom?: string;
height?: string;
}>`
height: ${({ height }) => (height ? height : 'auto')};
min-height: 50px;
flex-direction: row;
border-bottom-width: 1px;
border-bottom-color: #141b41;

Expand All @@ -14,8 +18,7 @@ export const Label = styled.Text<{ labelColor?: string }>`
`;

export const Input = styled.TextInput`
width: 100%;
height: 50px;
width: 80%;
padding-left: 10px;
color: black;
`;
130 changes: 87 additions & 43 deletions src/pages/Login/index.tsx
Original file line number Diff line number Diff line change
@@ -1,68 +1,112 @@
import React from 'react';

import {
Image,
KeyboardAvoidingView,
Platform,
SafeAreaView,
ScrollView,
// View,
} from 'react-native';
import { Formik } from 'formik';

import * as S from './styles';
import Input from '../../components/Input';
import Typography from '../../components/elements/Typography';
import LogoPurple from '../../assets/icons/logoPurple.svg';
import { useNavigation } from '@react-navigation/native';
import { NativeStackScreenProps } from '@react-navigation/native-stack';
import Button from '../../components/elements/Button';
import { theme } from '../../commons/styles/theme';
import { useLogin } from './useLogin';
import Toast from 'react-native-toast-message';

type RootStackParamList = {
Home: undefined;
Profile: { userId: string };
Feed: { sort: 'latest' | 'top' } | undefined;
};

type Props = NativeStackScreenProps<RootStackParamList, 'Profile'>;

type ProfileScrrenProps = Props['navigation'];

function Login() {
const navigation = useNavigation<ProfileScrrenProps>();
const { onSubmit } = useLogin();

const initialValues = {
email: '',
password: '',
};

return (
<Formik initialValues={initialValues} onSubmit={() => { }}>
{({ handleChange, values }) => (
<SafeAreaView style={{ flex: 1 }}>
<KeyboardAvoidingView
behavior={Platform.OS == 'ios' ? 'padding' : 'height'}
style={{ height: 'auto' }}
keyboardVerticalOffset={0}>
<ScrollView style={{ height: '100%' }}>
<S.ContainerLogo>
<LogoPurple width={150} height={300} />
</S.ContainerLogo>
<S.ContainerForms>
<Input
placeholder="E-mail"
value={values.email}
onChangeText={handleChange('email')}
marginBottom="40px"
placeholderTextColor="#141b4153"
labelColor="#141b4153"
/>
<Input
placeholder="Senha"
value={values.password}
onChangeText={handleChange('password')}
placeholderTextColor="#141b4153"
labelColor="#141b4153"
/>
<S.ContainerResetPassoword>
<Typography>Esqueceu sua senha?</Typography>
<S.ButtonResetPassword>Redefinir</S.ButtonResetPassword>
</S.ContainerResetPassoword>
</S.ContainerForms>
<S.ContainerRegister>
<Typography>Ainda não tem cadastro?</Typography>
<S.ButtonRegister>Cadastre-se.</S.ButtonRegister>
</S.ContainerRegister>
</ScrollView>
</KeyboardAvoidingView>
</SafeAreaView>
)}
</Formik>
<>
<Formik initialValues={initialValues} onSubmit={onSubmit}>
{({ isSubmitting, handleChange, values, isValid, handleSubmit }) => (
<SafeAreaView style={{ flex: 1 }}>
<KeyboardAvoidingView
behavior={Platform.OS == 'ios' ? 'padding' : 'height'}
keyboardVerticalOffset={0}>
<ScrollView style={{ height: '100%' }}>
<S.ContainerLogo>
<LogoPurple width={150} height={300} />
</S.ContainerLogo>
<S.ContainerForms>
<Input
placeholder="E-mail"
value={values.email}
onChangeText={handleChange('email')}
marginBottom="40px"
placeholderTextColor="#141b4153"
labelColor="#141b4153"
/>

<Input
placeholder="Senha"
height="60px"
value={values.password}
onChangeText={handleChange('password')}
placeholderTextColor="#141b4153"
labelColor="#141b4153"
IconRight
secureTextEntry
/>
{/* <InputPassWord /> */}
<S.ContainerResetPassword>
<Typography>Esqueceu sua senha?</Typography>
<S.ButtonResetPassword>Redefinir</S.ButtonResetPassword>
</S.ContainerResetPassword>
<S.ContainerButton>
<Button
variant="contained"
fontSize="18px"
height="40px"
width="170px"
color={theme.palette.colors.white.main}
// disabled={isSubmitting || !isValid}
onPress={handleSubmit}>
Entrar
</Button>
</S.ContainerButton>
</S.ContainerForms>
<S.ContainerRegister>
<Typography>Ainda não tem cadastro?</Typography>
<S.ButtonRegister
onPress={() => navigation.navigate('Register')}>
Cadastre-se.
</S.ButtonRegister>
</S.ContainerRegister>
</ScrollView>
</KeyboardAvoidingView>
</SafeAreaView>
)}
</Formik>
<Toast
// config={TypeToast}
position="bottom"
bottomOffset={50}
visibilityTime={4000}
/>
</>
);
}

Expand Down
13 changes: 10 additions & 3 deletions src/pages/Login/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import { theme } from '../../commons/styles/theme';

export const Container = styled.View`
flex: 1;
background-color: aqua;
`;

export const ContainerForms = styled.View`
justify-content: center;
margin: 20px;
flex: 1;
height: 200px;
height: 280px;
`;

export const ContainerLogo = styled.View`
Expand All @@ -22,13 +23,19 @@ export const ContainerLogo = styled.View`
margin-top: 10%;
`;

export const ContainerResetPassoword = styled.View`
export const ContainerResetPassword = styled.View`
flex-direction: row;

height: 50px;
align-items: center;
`;

export const ContainerButton = styled.View`
height: 80px;
align-items: center;
justify-content: flex-end;
`;

export const ButtonResetPassword = styled(Button).attrs({
variant: 'text',
color: theme.palette.colors.primary.main,
Expand All @@ -49,6 +56,6 @@ export const ContainerRegister = styled.View`
flex-direction: row;
justify-content: center;
flex: 1;
height: 200px;
height: 150px;
align-items: flex-end;
`;
36 changes: 36 additions & 0 deletions src/pages/Login/useLogin/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { ToastAndroid } from 'react-native';
import Toast from 'react-native-toast-message';
import { authenticateUser } from '../../../services/auth';

interface IValues {
email: string;
password: string;
}

export const useLogin = () => {
const showToast = () => {
Toast.show({
type: 'success',
text1: ' 👋 Bem vindo ao balance',
});
};

// const showToastAndroid = () => {
// ToastAndroid.show('Bem vindo ao balance', ToastAndroid.SHORT);
// };

const onSubmit = async ({ email, password }: IValues, { setSubmitting }) => {
showToast();
// showToastAndroid();
const response = await authenticateUser({ email, password });
console.log('Executei', response);
if (!response.token) {
setSubmitting(true);
return;
}
};

return {
onSubmit,
};
};
Loading