2018-04-03 17:14:55 +02:00
|
|
|
// @flow
|
2018-06-07 03:47:49 +02:00
|
|
|
import * as React from 'react';
|
2018-03-26 23:32:43 +02:00
|
|
|
import Button from 'component/button';
|
2018-04-03 04:40:04 +02:00
|
|
|
import { Form, FormField, FormRow, Submit } from 'component/common/form';
|
2017-06-03 01:09:52 +02:00
|
|
|
|
2018-04-03 17:14:55 +02:00
|
|
|
type Props = {
|
|
|
|
cancelButton: React.Node,
|
|
|
|
errorMessage: ?string,
|
|
|
|
email: string,
|
|
|
|
isPending: boolean,
|
|
|
|
verifyUserEmail: (string, string) => void,
|
|
|
|
verifyUserEmailFailure: string => void,
|
2018-06-07 03:47:49 +02:00
|
|
|
resendVerificationEmail: string => void,
|
2018-04-03 17:14:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
type State = {
|
|
|
|
code: string,
|
|
|
|
};
|
|
|
|
|
|
|
|
class UserEmailVerify extends React.PureComponent<Props, State> {
|
|
|
|
constructor(props: Props) {
|
2017-06-03 01:09:52 +02:00
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
2017-12-21 22:08:54 +01:00
|
|
|
code: '',
|
2017-06-03 01:09:52 +02:00
|
|
|
};
|
2018-04-03 04:40:04 +02:00
|
|
|
|
2018-04-03 17:14:55 +02:00
|
|
|
(this: any).handleSubmit = this.handleSubmit.bind(this);
|
2018-06-07 03:47:49 +02:00
|
|
|
(this: any).handleResendVerification = this.handleResendVerification.bind(this);
|
2017-06-03 01:09:52 +02:00
|
|
|
}
|
|
|
|
|
2018-04-03 17:14:55 +02:00
|
|
|
handleCodeChanged(event: SyntheticInputEvent<*>) {
|
2017-06-03 01:09:52 +02:00
|
|
|
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;
|
2017-12-23 03:09:06 +01:00
|
|
|
try {
|
2017-12-26 14:25:26 +01:00
|
|
|
const verification = JSON.parse(atob(code));
|
2017-12-23 03:09:06 +01:00
|
|
|
this.props.verifyUserEmail(verification.token, verification.recaptcha);
|
|
|
|
} catch (error) {
|
2017-12-26 14:25:26 +01:00
|
|
|
this.props.verifyUserEmailFailure('Invalid Verification Token');
|
2017-12-23 03:09:06 +01:00
|
|
|
}
|
2017-06-03 01:09:52 +02:00
|
|
|
}
|
|
|
|
|
2018-06-07 03:47:49 +02:00
|
|
|
handleResendVerification() {
|
|
|
|
this.props.resendVerificationEmail(this.props.email);
|
|
|
|
}
|
|
|
|
|
2017-06-03 01:09:52 +02:00
|
|
|
render() {
|
2017-12-30 00:43:51 +01:00
|
|
|
const { cancelButton, errorMessage, email, isPending } = this.props;
|
2018-04-03 04:40:04 +02:00
|
|
|
|
2017-06-08 23:15:34 +02:00
|
|
|
return (
|
2018-04-03 04:40:04 +02:00
|
|
|
<Form onSubmit={this.handleSubmit}>
|
2017-12-07 19:07:30 +01:00
|
|
|
<p>Please enter the verification code emailed to {email}.</p>
|
2018-04-03 04:40:04 +02:00
|
|
|
<FormRow>
|
|
|
|
<FormField
|
|
|
|
stretch
|
|
|
|
name="code"
|
|
|
|
type="text"
|
|
|
|
placeholder="eyJyZWNhcHRjaGEiOiIw..."
|
|
|
|
label={__('Verification Code')}
|
|
|
|
error={errorMessage}
|
|
|
|
value={this.state.code}
|
|
|
|
onChange={event => this.handleCodeChanged(event)}
|
|
|
|
/>
|
|
|
|
</FormRow>
|
|
|
|
<div className="help">
|
2017-06-08 23:15:34 +02:00
|
|
|
<p>
|
2018-04-03 04:40:04 +02:00
|
|
|
{__('Email')} <Button button="link" href="mailto:help@lbry.io" label="help@lbry.io" />{' '}
|
|
|
|
or join our <Button button="link" href="https://chat.lbry.io" label="chat" />{' '}
|
2017-12-21 22:08:54 +01:00
|
|
|
{__('if you encounter any trouble with your code.')}
|
2017-06-08 23:15:34 +02:00
|
|
|
</p>
|
|
|
|
</div>
|
2018-04-03 04:40:04 +02:00
|
|
|
<div className="card__actions">
|
2017-12-21 22:08:54 +01:00
|
|
|
<Submit label={__('Verify')} disabled={isPending} />
|
2017-12-07 19:07:30 +01:00
|
|
|
{cancelButton}
|
2018-06-07 03:47:49 +02:00
|
|
|
<Button
|
|
|
|
button="inverse"
|
|
|
|
label={__('Resend Verification Email')}
|
|
|
|
onClick={this.handleResendVerification}
|
|
|
|
/>
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-08 23:15:34 +02:00
|
|
|
export default UserEmailVerify;
|