Pattern improvement

This commit is contained in:
Qolzam
2017-09-28 18:15:18 +07:00
parent b198717ae9
commit 0a9db2449f
3 changed files with 57 additions and 27 deletions

13
app/api/StringAPI.jsx Normal file
View File

@@ -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
}

View File

@@ -320,6 +320,9 @@ static propTypes = {
fontSize: '12px', fontSize: '12px',
marginRight: '6px' marginRight: '6px'
}, },
postBody:{
wordWrap: "break-word"
},
dialog: { dialog: {
width: '', width: '',
maxWidth: '530px', maxWidth: '530px',
@@ -366,7 +369,7 @@ static propTypes = {
</CardMedia>) : ''} </CardMedia>) : ''}
<CardText> <CardText style={styles.postBody}>
{reactStringReplace(body,/#(\w+)/g, (match, i) => ( {reactStringReplace(body,/#(\w+)/g, (match, i) => (
<NavLink <NavLink
style={{color:'green'}} style={{color:'green'}}

View File

@@ -12,7 +12,8 @@ import FlatButton from 'material-ui/FlatButton'
import * as authorizeActions from 'authorizeActions' import * as authorizeActions from 'authorizeActions'
import * as globalActions from 'globalActions' import * as globalActions from 'globalActions'
// - Import app API
import StringAPI from 'StringAPI'
// - Create Signup componet class // - Create Signup componet class
@@ -93,47 +94,61 @@ export class Signup extends Component {
*/ */
handleForm = () => { handleForm = () => {
const {fullNameInput, emailInput, passwordInput, confirmInput} = this.state
const {register} = this.props
var error = false 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({ this.setState({
fullNameInputError: 'This field is required' passwordInputError: 'This field is required.'
})
error = true
}
if (this.state.emailInput === '') {
this.setState({
emailInputError: 'This field is required'
}) })
error = true error = true
} }
if (this.state.passwordInput === '') { if (confirmInput === '') {
this.setState({ this.setState({
passwordInputError: 'This field is required' confirmInputError: 'This field is required.'
}) })
error = true error = true
} }
if (this.state.confirmInput === '') { else if(confirmInput !== passwordInput){
this.setState({ this.setState({
confirmInputError: 'This field is required' passwordInputError: 'This field sould be equal to confirm password.',
}) confirmInputError: 'This field sould be equal to password.'
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'
}) })
error = true error = true
} }
if (!error) { if (!error) {
this.props.register({ register({
email: this.state.emailInput, email: emailInput,
password: this.state.passwordInput, password: passwordInput,
fullName: this.state.fullNameInput fullName: fullNameInput
}) })
} }
@@ -147,7 +162,6 @@ export class Signup extends Component {
const paperStyle = { const paperStyle = {
minHeight: 500, minHeight: 500,
width: 450, width: 450,
margin: 20,
textAlign: 'center', textAlign: 'center',
display: 'block', display: 'block',
margin: "auto" margin: "auto"