From 4e0701708390237f270303f0794f4c33b2bcee83 Mon Sep 17 00:00:00 2001 From: dcipher00 Date: Fri, 18 Oct 2019 00:28:02 +0530 Subject: [PATCH 1/2] login page validated --- src/components/Authentication/LoginScreen.tsx | 40 +++++++++++++++++-- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/src/components/Authentication/LoginScreen.tsx b/src/components/Authentication/LoginScreen.tsx index 553c456..e3fc6ec 100644 --- a/src/components/Authentication/LoginScreen.tsx +++ b/src/components/Authentication/LoginScreen.tsx @@ -5,6 +5,20 @@ import Button from "react-native-button"; interface AppProps {} +const required = (value) => (value || typeof value === "number" ? undefined : "Required"); +const maxLength = (max) => (value) => + value && value.length > max ? `Must be ${max} characters or less` : undefined; +const minLength = (min) => (value) => + value && value.length < min ? `Must be ${min} characters or more` : undefined; + +const email = (value) => + value && !/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i.test(value) + ? "Invalid email address" + : undefined; + +const maxLength256 = maxLength(256); +const minLength2 = minLength(2); + export default class LoginScreen extends React.Component { static navigationOptions = { title: "Login", @@ -20,6 +34,26 @@ export default class LoginScreen extends React.Component { }; } + validate_field = () => { + const { username, password} = this.state + if(username !== email) { + alert("Please fill username") + return false + } + else if(password !== maxLength256 || password !== minLength2) { + alert ("Please fill password") + return false + } + return true + } + + making_api_call=()=> { + if(this.validate_field()) + { + this.props.navigation.navigate('ActivityScreen') + } + } + render() { const Image = require("../../../assets/splash.png"); return ( @@ -32,22 +66,22 @@ export default class LoginScreen extends React.Component { Welcome To frindi this.setState({ username })} placeholder={'Username'} style={styles.input} + validate={[email, required, maxLength256, minLength2]} /> this.setState({ password })} placeholder={'Password'} secureTextEntry={true} style={styles.input} + validate={[required]} /> From e14feaed8cb2aea00cefe0e73411f6f9a46d62c8 Mon Sep 17 00:00:00 2001 From: dcipher00 Date: Tue, 22 Oct 2019 21:20:24 +0530 Subject: [PATCH 2/2] Merging conflict Closes: #11 --- src/components/Authentication/LoginScreen.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/components/Authentication/LoginScreen.tsx b/src/components/Authentication/LoginScreen.tsx index 6a08783..2cd6dd2 100644 --- a/src/components/Authentication/LoginScreen.tsx +++ b/src/components/Authentication/LoginScreen.tsx @@ -56,6 +56,7 @@ export default class LoginScreen extends React.Component { onChangeText={(username) => this.setState({ username })} placeholder={'Username'} style={styles.input} + validate={[email, required, maxLength256, minLength2]} /> { placeholder={'Password'} secureTextEntry={true} style={styles.input} + validate={[required]} />