From 0a9db2449f9b828f2f68b748fd7b1545b134b18a Mon Sep 17 00:00:00 2001 From: Qolzam Date: Thu, 28 Sep 2017 18:15:18 +0700 Subject: [PATCH] Pattern improvement --- app/api/StringAPI.jsx | 13 ++++++++ app/components/Post.jsx | 5 ++- app/components/Signup.jsx | 66 ++++++++++++++++++++++++--------------- 3 files changed, 57 insertions(+), 27 deletions(-) create mode 100644 app/api/StringAPI.jsx diff --git a/app/api/StringAPI.jsx b/app/api/StringAPI.jsx new file mode 100644 index 0000000..1636e0c --- /dev/null +++ b/app/api/StringAPI.jsx @@ -0,0 +1,13 @@ +// - Import react component +import { storageRef } from 'app/firebase/' + +//- Import actions + +const isValidEmail = (email) => { + var re = /^(([^<>()\[\]\\.,;:\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,}))$/; + return re.test(email) +} + +export default { + isValidEmail +} \ No newline at end of file diff --git a/app/components/Post.jsx b/app/components/Post.jsx index b408e32..7d48cda 100644 --- a/app/components/Post.jsx +++ b/app/components/Post.jsx @@ -320,6 +320,9 @@ static propTypes = { fontSize: '12px', marginRight: '6px' }, + postBody:{ + wordWrap: "break-word" + }, dialog: { width: '', maxWidth: '530px', @@ -366,7 +369,7 @@ static propTypes = { ) : ''} - + {reactStringReplace(body,/#(\w+)/g, (match, i) => ( { + const {fullNameInput, emailInput, passwordInput, confirmInput} = this.state + const {register} = this.props + var error = false - if (this.state.fullNameInput === '') { + + // Validate full name + let fullNameCheck = fullNameInput.trim().toLowerCase() + + if (fullNameCheck.indexOf('test') > -1 + || fullNameCheck.indexOf('demo') > -1 + || fullNameCheck.indexOf('asd') > -1 + || fullNameCheck.length < 4) { + this.setState({ + fullNameInputError: 'Please enter a valid name.' + }) + error = true + } + + /* Validate email*/ + if (!StringAPI.isValidEmail(emailInput)) { + this.setState({ + emailInputError: 'Please enter a valid email.' + }) + error = true + + } + + /* Check password */ + if (passwordInput === '') { this.setState({ - fullNameInputError: 'This field is required' - }) - error = true - } - if (this.state.emailInput === '') { - this.setState({ - emailInputError: 'This field is required' + passwordInputError: 'This field is required.' }) error = true } - if (this.state.passwordInput === '') { + if (confirmInput === '') { this.setState({ - passwordInputError: 'This field is required' + confirmInputError: 'This field is required.' }) error = true } - if (this.state.confirmInput === '') { + else if(confirmInput !== passwordInput){ this.setState({ - confirmInputError: 'This field is required' - }) - error = true - - } - else if(this.state.confirmInput !== this.state.passwordInput){ - this.setState({ - passwordInputError: 'This field sould be equal to confirm password', - confirmInputError: 'This field sould be equal to password' + passwordInputError: 'This field sould be equal to confirm password.', + confirmInputError: 'This field sould be equal to password.' }) error = true } if (!error) { - this.props.register({ - email: this.state.emailInput, - password: this.state.passwordInput, - fullName: this.state.fullNameInput + register({ + email: emailInput, + password: passwordInput, + fullName: fullNameInput }) } @@ -147,7 +162,6 @@ export class Signup extends Component { const paperStyle = { minHeight: 500, width: 450, - margin: 20, textAlign: 'center', display: 'block', margin: "auto"