import React from 'react';
import PropTypes from 'prop-types';
import { compose } from 'redux';
import { connect } from 'react-redux';
import { FormattedMessage, injectIntl, intlShape } from 'react-intl';
import { propTypes } from '../../util/types';
import {
isPasswordRecoveryEmailNotFoundError,
isPasswordRecoveryEmailNotVerifiedError,
} from '../../util/errors';
import { isScrollingDisabled } from '../../ducks/UI.duck';
import {
Page,
InlineTextButton,
IconKeys,
LayoutSingleColumn,
LayoutWrapperMain,
LayoutWrapperTopbar,
LayoutWrapperFooter,
Footer,
} from '../../components';
import { PasswordRecoveryForm } from '../../forms';
import { TopbarContainer } from '../../containers';
import {
recoverPassword,
retypePasswordRecoveryEmail,
clearPasswordRecoveryError,
} from './PasswordRecoveryPage.duck';
import DoorIcon from './DoorIcon';
import css from './PasswordRecoveryPage.css';
export const PasswordRecoveryPageComponent = props => {
const {
scrollingDisabled,
initialEmail,
submittedEmail,
recoveryError,
recoveryInProgress,
passwordRequested,
onChange,
onSubmitEmail,
onRetypeEmail,
intl,
} = props;
const title = intl.formatMessage({
id: 'PasswordRecoveryPage.title',
});
const resendEmailLink = (
onSubmitEmail(submittedEmail)}>
);
const fixEmailLink = (
);
const submitEmailContent = (
onSubmitEmail(values.email)}
initialValues={{ email: initialEmail }}
recoveryError={recoveryError}
/>
);
const submittedEmailText = passwordRequested ? (
{initialEmail}
) : (
{submittedEmail}
);
const emailSubmittedContent = (
{recoveryInProgress ? (
) : (
)}
);
const initialEmailText = {initialEmail};
const emailNotVerifiedContent = (
);
const genericErrorContent = (
);
let content;
if (isPasswordRecoveryEmailNotVerifiedError(recoveryError)) {
content = emailNotVerifiedContent;
} else if (isPasswordRecoveryEmailNotFoundError(recoveryError)) {
content = submitEmailContent;
} else if (recoveryError) {
content = genericErrorContent;
} else if (submittedEmail || passwordRequested) {
content = emailSubmittedContent;
} else {
content = submitEmailContent;
}
return (
{content}
);
};
PasswordRecoveryPageComponent.defaultProps = {
sendVerificationEmailError: null,
initialEmail: null,
submittedEmail: null,
recoveryError: null,
};
const { bool, func, string } = PropTypes;
PasswordRecoveryPageComponent.propTypes = {
scrollingDisabled: bool.isRequired,
initialEmail: string,
submittedEmail: string,
recoveryError: propTypes.error,
recoveryInProgress: bool.isRequired,
passwordRequested: bool.isRequired,
onChange: func.isRequired,
onSubmitEmail: func.isRequired,
onRetypeEmail: func.isRequired,
// from injectIntl
intl: intlShape.isRequired,
};
const mapStateToProps = state => {
const {
initialEmail,
submittedEmail,
recoveryError,
recoveryInProgress,
passwordRequested,
} = state.PasswordRecoveryPage;
return {
scrollingDisabled: isScrollingDisabled(state),
initialEmail,
submittedEmail,
recoveryError,
recoveryInProgress,
passwordRequested,
};
};
const mapDispatchToProps = dispatch => ({
onChange: () => dispatch(clearPasswordRecoveryError()),
onSubmitEmail: email => dispatch(recoverPassword(email)),
onRetypeEmail: () => dispatch(retypePasswordRecoveryEmail()),
});
const PasswordRecoveryPage = compose(
connect(
mapStateToProps,
mapDispatchToProps
),
injectIntl
)(PasswordRecoveryPageComponent);
export default PasswordRecoveryPage;