From ff9dba9a4241a799970ef36866b595d6f6940531 Mon Sep 17 00:00:00 2001 From: Justin Shillingford Date: Mon, 29 Jun 2020 19:36:50 -0400 Subject: Added validationWarnings to LoginInput component --- src/components/common/LoginInput.tsx | 117 +++++++++++++++++++---------------- src/screens/Login.tsx | 14 ++--- 2 files changed, 68 insertions(+), 63 deletions(-) (limited to 'src') diff --git a/src/components/common/LoginInput.tsx b/src/components/common/LoginInput.tsx index 12bf0b3c..ba519480 100644 --- a/src/components/common/LoginInput.tsx +++ b/src/components/common/LoginInput.tsx @@ -1,61 +1,66 @@ import React from 'react'; -import {TextInput, StyleSheet} from 'react-native'; +import {Text, TextInput, StyleSheet} from 'react-native'; import PropTypes from 'prop-types'; const LoginInput = (props: LoginInputProps) => { return ( - props.onChangeText(input)} - defaultValue={props.type} - onSubmitEditing={props.onSubmitEditing} - blurOnSubmit={ - props.isUsername ? false : props.isPassword ? undefined : undefined - } - // ref={props.isUsername ? undefined : useRef()} - secureTextEntry={ - props.isUsername ? false : props.isPassword ? true : false - } - // focus={props.isUsername ? undefined : props.focusPasswordInput} - /> + <> + props.onChangeText(input)} + defaultValue={props.type} + onSubmitEditing={props.onSubmitEditing} + blurOnSubmit={ + props.isUsername ? false : props.isPassword ? undefined : undefined + } + // ref={props.isUsername ? undefined : useRef()} + secureTextEntry={ + props.isUsername ? false : props.isPassword ? true : false + } + // focus={props.isUsername ? undefined : props.focusPasswordInput} + /> + {!props.isValid && ( + {props.validationWarning} + )} + ); }; @@ -72,6 +77,10 @@ const styles = StyleSheet.create({ paddingLeft: 13, marginVertical: 15, }, + invalidCredentials: { + top: 180, + color: '#F4DDFF', + }, }); LoginInput.propTypes = { @@ -82,6 +91,8 @@ LoginInput.propTypes = { onSubmitEditing: PropTypes.func, // ref: PropTypes.any, focusPasswordInput: PropTypes.bool, + isValid: PropTypes.bool, + validationWarning: PropTypes.string, }; export default LoginInput; diff --git a/src/screens/Login.tsx b/src/screens/Login.tsx index 618507d8..77bc1b61 100644 --- a/src/screens/Login.tsx +++ b/src/screens/Login.tsx @@ -117,24 +117,18 @@ const Login = ({navigation}: LoginProps) => { isUsername={true} onChangeText={(user) => handleUsernameUpdate(user)} onSubmitEditing={() => handleUsernameSubmit()} + isValid={data.isValidUser} + validationWarning={'Username must be at least 6 characters long.'} /> - {data.isValidUser ? null : ( - - Username must be at least 6 characters long. - - )} handlePasswordUpdate(user)} focusPasswordInput={data.focusPasswordInput} onSubmitEditing={() => handleLogin()} + isValid={data.isValidPassword} + validationWarning={'Password must be at least 8 characters long.'} /> - {data.isValidPassword ? null : ( - - Password must be at least 8 characters long. - - )}