diff --git a/react-native/core/utils.tsx b/react-native/core/utils.tsx index e69de29..3f94b2e 100644 --- a/react-native/core/utils.tsx +++ b/react-native/core/utils.tsx @@ -0,0 +1,21 @@ +export const emailValidator = (email: string) => { + const re = /\S+@\S+\.\S+/; + + if (!email || email.length <= 0) return 'Email cannot be empty.'; + if (!re.test(email)) return 'Ooops! We need a valid email address.'; + + return ''; +}; + +export const passwordValidator = (password: string) => { + if (!password || password.length <= 0) return 'Password cannot be empty.'; + + return ''; +}; + +export const nameValidator = (name: string) => { + if (!name || name.length <= 0) return 'Name cannot be empty.'; + + return ''; +}; + diff --git a/react-native/screens/LoginScreen.tsx b/react-native/screens/LoginScreen.tsx index 2c1cd8b..3d1b766 100644 --- a/react-native/screens/LoginScreen.tsx +++ b/react-native/screens/LoginScreen.tsx @@ -1,13 +1,129 @@ import React, { useState } from 'react'; import { StyleSheet, Text, SafeAreaView, View, Alert, Image } from 'react-native'; import { TextInput, Button } from 'react-native-paper'; +import { emailValidator, passwordValidator } from '../core/utils'; import { theme } from '../core/theme'; import type { Navigation } from '../types'; export default function LoginScreen({ navigation }: Navigation) { + const [email, setEmail] = useState(''); + const [password, setPassword] = useState(''); + + const errorAlert = (error: string) => + Alert.alert( + "Login Failed", + error, + [ + { text: "OK", onPress: () => console.log("OK Pressed") } + ] + ); + + const onLoginPressed = () => { + const emailError = emailValidator(email); + const passwordError = passwordValidator(password); + + if (emailError || passwordError) { + errorAlert(emailError ? emailError : passwordError); + return; + } + + navigation.navigate('Home'); + }; + return ( - - Login Screen - - ); -} \ No newline at end of file + + + + + Sign in + + + + setEmail(text)} + autoCapitalize="none" + textContentType="emailAddress" + autoComplete="email" + keyboardType="email-address" + /> + + setPassword(text)} + autoComplete="password" + secureTextEntry + /> + + + + + + + + + + ) +}; + +const styles = StyleSheet.create({ + container: { + margin: 20, + backgroundColor: theme.colors.background, + flex: 1, + flexDirection: 'column', + justifyContent: 'space-between' + }, + loginImage: { + width: 50, + height: 50, + }, + title: { + paddingTop: 40, + fontWeight: '700', + fontSize: 36, + }, + input: { + height: 40, + borderWidth: 1, + marginVertical: 10, + borderRadius: 4, + backgroundColor: '#fff' + }, + submit: { + height: 40, + marginBottom: 10 + }, + forgotPassword: { + width: '100%', + alignItems: 'flex-end', + marginBottom: 24, + }, +}); + \ No newline at end of file