2017-12-21 22:08:54 +01:00
|
|
|
import React from 'react';
|
|
|
|
import Link from 'component/link';
|
|
|
|
import { Form, FormRow, Submit } from 'component/form.js';
|
2017-06-03 01:09:52 +02:00
|
|
|
|
2018-01-11 07:16:03 +01:00
|
|
|
class UserFieldVerify extends React.PureComponent {
|
2017-06-03 01:09:52 +02:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
2017-12-21 22:08:54 +01:00
|
|
|
code: '',
|
2017-06-03 01:09:52 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
handleCodeChanged(event) {
|
|
|
|
this.setState({
|
2017-07-19 01:00:13 +02:00
|
|
|
code: String(event.target.value).trim(),
|
2017-06-03 01:09:52 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-09-11 03:25:24 +02:00
|
|
|
handleSubmit() {
|
|
|
|
const { code } = this.state;
|
2018-01-15 14:32:01 +01:00
|
|
|
const { fieldType } = this.props;
|
|
|
|
if (fieldType === 'phone') {
|
|
|
|
this.props.verifyUserPhone(code);
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
const verification = JSON.parse(atob(code));
|
|
|
|
this.props.verifyUserEmail(verification.token, verification.recaptcha);
|
|
|
|
} catch (error) {
|
|
|
|
this.props.verifyUserEmailFailure('Invalid Verification Token');
|
|
|
|
}
|
2017-12-23 03:09:06 +01:00
|
|
|
}
|
2017-06-03 01:09:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2018-01-15 15:30:10 +01:00
|
|
|
const {
|
|
|
|
cancelButton,
|
|
|
|
emailErrorMessage,
|
|
|
|
phoneErrorMessage,
|
|
|
|
email,
|
|
|
|
isPending,
|
|
|
|
phone,
|
|
|
|
} = this.props;
|
2017-06-08 23:15:34 +02:00
|
|
|
return (
|
2017-09-11 03:25:24 +02:00
|
|
|
<Form onSubmit={this.handleSubmit.bind(this)}>
|
2018-01-15 14:32:01 +01:00
|
|
|
<p>Please enter the verification code sent to {phone || email}.</p>
|
2017-06-08 23:15:34 +02:00
|
|
|
<FormRow
|
|
|
|
type="text"
|
2017-12-21 22:08:54 +01:00
|
|
|
label={__('Verification Code')}
|
2017-06-08 23:15:34 +02:00
|
|
|
name="code"
|
|
|
|
value={this.state.code}
|
|
|
|
onChange={event => {
|
|
|
|
this.handleCodeChanged(event);
|
|
|
|
}}
|
2018-01-15 15:30:10 +01:00
|
|
|
errorMessage={emailErrorMessage || phoneErrorMessage}
|
2017-06-08 23:15:34 +02:00
|
|
|
/>
|
|
|
|
{/* render help separately so it always shows */}
|
|
|
|
<div className="form-field__helper">
|
|
|
|
<p>
|
2017-12-21 22:08:54 +01:00
|
|
|
{__('Email')} <Link href="mailto:help@lbry.io" label="help@lbry.io" /> or join our{' '}
|
|
|
|
<Link href="https://chat.lbry.io" label="chat" />{' '}
|
|
|
|
{__('if you encounter any trouble with your code.')}
|
2017-06-08 23:15:34 +02:00
|
|
|
</p>
|
|
|
|
</div>
|
2017-12-07 19:07:30 +01:00
|
|
|
<div className="form-row-submit">
|
2017-12-21 22:08:54 +01:00
|
|
|
<Submit label={__('Verify')} disabled={isPending} />
|
2017-12-07 19:07:30 +01:00
|
|
|
{cancelButton}
|
2017-06-08 23:15:34 +02:00
|
|
|
</div>
|
2017-09-11 03:25:24 +02:00
|
|
|
</Form>
|
2017-06-08 23:15:34 +02:00
|
|
|
);
|
2017-06-03 01:09:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-11 07:16:03 +01:00
|
|
|
export default UserFieldVerify;
|