-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add react-hook-form for form validation (#463)
* Add react-hooks-form package * Update login screen form * Updaye circleci node version * Style fixes * Code cleanup * Fix the auth error logic * Change configure url screen validation * Change reset password form validation * Remove tcomb-form-native package * Remove console/logs * Android/iOS beta version 1.3.27
- Loading branch information
Showing
14 changed files
with
291 additions
and
240 deletions.
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import React from 'react'; | ||
import { View, TextInput } from 'react-native'; | ||
import { StyleService, useStyleSheet } from '@ui-kitten/components'; | ||
import PropTypes from 'prop-types'; | ||
import Text from './Text'; | ||
|
||
const themedStyles = StyleService.create({ | ||
textViewError: { | ||
borderWidth: 1, | ||
borderColor: 'color-danger-900', | ||
borderRadius: 4, | ||
marginTop: 8, | ||
}, | ||
label: { | ||
color: 'text-basic-color', | ||
paddingBottom: 6, | ||
fontSize: 'text-primary-size', | ||
fontWeight: 'font-medium', | ||
}, | ||
errorLabel: { | ||
color: 'color-danger-900', | ||
textAlign: 'left', | ||
paddingTop: 2, | ||
paddingBottom: 2, | ||
fontSize: 'text-primary-size', | ||
}, | ||
inputStyle: { | ||
fontSize: 'input-font-size', | ||
color: 'text-basic-color', | ||
paddingVertical: 8, | ||
paddingHorizontal: 16, | ||
borderWidth: 1, | ||
borderRadius: 4, | ||
borderColor: 'color-basic-focus-border', | ||
height: 48, | ||
}, | ||
errorInputStyle: { | ||
fontSize: 'input-font-size', | ||
color: 'text-basic-color', | ||
paddingVertical: 8, | ||
paddingHorizontal: 16, | ||
borderWidth: 1, | ||
borderRadius: 4, | ||
borderColor: 'color-danger-900', | ||
height: 48, | ||
}, | ||
}); | ||
|
||
const propTypes = { | ||
onChangeText: PropTypes.func.isRequired, | ||
error: PropTypes.object, | ||
keyboardType: PropTypes.string, | ||
secureTextEntry: PropTypes.bool, | ||
label: PropTypes.string.isRequired, | ||
value: PropTypes.string.isRequired, | ||
}; | ||
const TextInputField = ({ onChangeText, error, keyboardType, secureTextEntry, label, value }) => { | ||
const styles = useStyleSheet(themedStyles); | ||
|
||
return ( | ||
<View> | ||
<Text style={styles.label}>{label}</Text> | ||
<TextInput | ||
style={error ? styles.errorInputStyle : styles.inputStyle} | ||
accessibilityLabel={label} | ||
keyboardType={keyboardType} | ||
secureTextEntry={secureTextEntry} | ||
onChangeText={onChangeText} | ||
value={value} | ||
autoCapitalize="none" | ||
autoComplete={false} | ||
autoCorrect={false} | ||
/> | ||
{error && <Text style={styles.errorLabel}>{error.message}</Text>} | ||
</View> | ||
); | ||
}; | ||
|
||
TextInputField.propTypes = propTypes; | ||
|
||
export default TextInputField; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,5 @@ | ||
import t from 'tcomb-form-native'; | ||
import validator from 'validator'; | ||
// eslint-disable-next-line no-useless-escape | ||
const emailRegex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; | ||
const nameRegex = /^.{2}/; | ||
const passwordRegex = /^.{6}/; | ||
const mobileNumberValidator = (mobileNumber) => { | ||
const regex = /^(?:(?:\+|0{0,2})91(\s*[-]\s*)?|[0]?)?[789]\d{9}$/g; | ||
return regex.test(mobileNumber); | ||
}; | ||
export const IndianMobileRegex = t.refinement(t.Number, mobileNumberValidator); | ||
export const URL_WITHOUT_HTTP_REGEX = | ||
/^(?:(ftp|http|https)?:\/\/)?(?:[\w-]+\.)+([a-z]|[A-Z]|[0-9]){2,6}$/gi; | ||
|
||
export const isStringEmail = (email) => { | ||
const re = emailRegex; | ||
return re.test(email); | ||
}; | ||
export const Email = t.refinement(t.String, (email) => isStringEmail(email)); | ||
|
||
export const isStringName = (name) => { | ||
const re = nameRegex; | ||
return re.test(name); | ||
}; | ||
export const Name = t.refinement(t.String, (name) => isStringName(name)); | ||
|
||
export const isStringUrl = (url) => { | ||
return validator.isURL(url); | ||
}; | ||
export const URL = t.refinement(t.String, (url) => isStringUrl(url)); | ||
|
||
export const isStringPassword = (password) => { | ||
const re = passwordRegex; | ||
return re.test(password); | ||
}; | ||
export const Password = t.refinement(t.String, (password) => isStringPassword(password)); | ||
|
||
export const isNumberValid = (number) => { | ||
const regex = /^\+?\d{1,8}(?:\.\d{1,2})?$/; | ||
return regex.test(number); | ||
}; | ||
export const EMAIL_REGEX = | ||
/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; |
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
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
Oops, something went wrong.