sms verification: make QueryCode component dumb
This commit is contained in:
parent
f48a341c32
commit
377c16cf78
@ -18,18 +18,15 @@ import React, { Component, PropTypes } from 'react';
|
|||||||
|
|
||||||
import { Form, Input } from '../../../ui';
|
import { Form, Input } from '../../../ui';
|
||||||
|
|
||||||
const isValidCode = /^[A-Z0-9_-]{7,14}$/i;
|
|
||||||
|
|
||||||
export default class QueryCode extends Component {
|
export default class QueryCode extends Component {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
data: PropTypes.object.isRequired,
|
number: PropTypes.string.isRequired,
|
||||||
onData: PropTypes.func.isRequired,
|
isCodeValid: PropTypes.bool.isRequired,
|
||||||
onDataIsValid: PropTypes.func.isRequired,
|
setCode: PropTypes.func.isRequired
|
||||||
onDataIsInvalid: PropTypes.func.isRequired
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const { number, code } = this.props.data;
|
const { number, isCodeValid } = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form>
|
<Form>
|
||||||
@ -37,7 +34,7 @@ export default class QueryCode extends Component {
|
|||||||
<Input
|
<Input
|
||||||
label={ 'verification code' }
|
label={ 'verification code' }
|
||||||
hint={ 'Enter the code you received via SMS.' }
|
hint={ 'Enter the code you received via SMS.' }
|
||||||
error={ isValidCode.test(code) ? null : 'invalid code' }
|
error={ isCodeValid ? null : 'invalid code' }
|
||||||
onChange={ this.onChange }
|
onChange={ this.onChange }
|
||||||
onSubmit={ this.onSubmit }
|
onSubmit={ this.onSubmit }
|
||||||
/>
|
/>
|
||||||
@ -46,16 +43,9 @@ export default class QueryCode extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onChange = (_, code) => {
|
onChange = (_, code) => {
|
||||||
code = code.trim();
|
this.props.setCode(code.trim());
|
||||||
this.props.onData({ code });
|
|
||||||
|
|
||||||
if (isValidCode.test(code)) {
|
|
||||||
this.props.onDataIsValid();
|
|
||||||
} else {
|
|
||||||
this.props.onDataIsInvalid();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
onSubmit = (code) => {
|
onSubmit = (code) => {
|
||||||
this.onChange(null, code);
|
this.props.setCode(code.trim());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user