#1492 Adding support to resend verification email

This commit is contained in:
Amit Nandan P 2018-06-06 20:47:49 -05:00
parent c61392e9f3
commit 8c343b16e3
4 changed files with 51 additions and 3 deletions

View file

@ -1,6 +1,9 @@
import React from 'react';
import { connect } from 'react-redux';
import { doUserEmailVerify, doUserEmailVerifyFailure } from 'redux/actions/user';
import {
doUserEmailVerify,
doUserEmailVerifyFailure,
doUserResendVerificationEmail,
} from 'redux/actions/user';
import {
selectEmailVerifyIsPending,
selectEmailToVerify,
@ -17,6 +20,7 @@ const select = state => ({
const perform = dispatch => ({
verifyUserEmail: (code, recaptcha) => dispatch(doUserEmailVerify(code, recaptcha)),
verifyUserEmailFailure: error => dispatch(doUserEmailVerifyFailure(error)),
resendVerificationEmail: email => dispatch(doUserResendVerificationEmail(email)),
});
export default connect(select, perform)(UserEmailVerify);

View file

@ -1,5 +1,5 @@
// @flow
import React from 'react';
import * as React from 'react';
import Button from 'component/button';
import { Form, FormField, FormRow, Submit } from 'component/common/form';
@ -10,6 +10,7 @@ type Props = {
isPending: boolean,
verifyUserEmail: (string, string) => void,
verifyUserEmailFailure: string => void,
resendVerificationEmail: string => void,
};
type State = {
@ -25,6 +26,7 @@ class UserEmailVerify extends React.PureComponent<Props, State> {
};
(this: any).handleSubmit = this.handleSubmit.bind(this);
(this: any).handleResendVerification = this.handleResendVerification.bind(this);
}
handleCodeChanged(event: SyntheticInputEvent<*>) {
@ -43,6 +45,10 @@ class UserEmailVerify extends React.PureComponent<Props, State> {
}
}
handleResendVerification() {
this.props.resendVerificationEmail(this.props.email);
}
render() {
const { cancelButton, errorMessage, email, isPending } = this.props;
@ -71,6 +77,11 @@ class UserEmailVerify extends React.PureComponent<Props, State> {
<div className="card__actions">
<Submit label={__('Verify')} disabled={isPending} />
{cancelButton}
<Button
button="inverse"
label={__('Resend Verification Email')}
onClick={this.handleResendVerification}
/>
</div>
</Form>
);

View file

@ -117,6 +117,7 @@ export const USER_EMAIL_NEW_FAILURE = 'USER_EMAIL_NEW_FAILURE';
export const USER_EMAIL_VERIFY_STARTED = 'USER_EMAIL_VERIFY_STARTED';
export const USER_EMAIL_VERIFY_SUCCESS = 'USER_EMAIL_VERIFY_SUCCESS';
export const USER_EMAIL_VERIFY_FAILURE = 'USER_EMAIL_VERIFY_FAILURE';
export const USER_EMAIL_VERIFY_RETRY = 'USER_EMAIL_VERIFY_RETRY';
export const USER_PHONE_RESET = 'USER_PHONE_RESET';
export const USER_PHONE_NEW_STARTED = 'USER_PHONE_NEW_STARTED';
export const USER_PHONE_NEW_SUCCESS = 'USER_PHONE_NEW_SUCCESS';

View file

@ -196,6 +196,38 @@ export function doUserEmailNew(email) {
};
}
export function doUserResendVerificationEmail(email) {
return dispatch => {
dispatch({
type: ACTIONS.USER_EMAIL_VERIFY_RETRY,
email,
});
const success = () => {
dispatch({
type: ACTIONS.USER_EMAIL_NEW_SUCCESS,
data: { email },
});
dispatch(doUserFetch());
};
const failure = error => {
dispatch({
type: ACTIONS.USER_EMAIL_NEW_FAILURE,
data: { error },
});
};
Lbryio.call('user_email', 'resend_token', { email }, 'post')
.catch(error => {
if (error.response && error.response.status === 409) {
throw error;
}
})
.then(success, failure);
};
}
export function doUserEmailVerifyFailure(error) {
return {
type: ACTIONS.USER_EMAIL_VERIFY_FAILURE,