/** * * AuthPage * */ import React from 'react'; import PropTypes from 'prop-types'; import { connect } from 'react-redux'; import { bindActionCreators, compose } from 'redux'; import { Link } from 'react-router-dom'; import { FormattedMessage } from 'react-intl'; import { findIndex, get, isBoolean, isEmpty, map } from 'lodash'; import cn from 'classnames'; // Logo import LogoStrapi from 'assets/images/logo_strapi.png'; // Design import Button from 'components/Button'; import Input from 'components/Input'; // Utils import injectSaga from 'utils/injectSaga'; import injectReducer from 'utils/injectReducer'; import { onChangeInput, setErrors, setForm, submit, } from './actions'; import form from './form.json'; import reducer from './reducer'; import saga from './saga'; import makeSelectAuthPage from './selectors'; import styles from './styles.scss'; export class AuthPage extends React.Component { // eslint-disable-line react/prefer-stateless-function componentDidMount() { this.props.setForm(this.props.match.params.authType, this.props.match.params.id); } componentWillReceiveProps(nextProps) { if (this.props.match.params.authType !== nextProps.match.params.authType) { this.props.setForm(nextProps.match.params.authType, nextProps.match.params.id); } if (nextProps.submitSuccess) { switch (this.props.match.params.authType) { case 'login': this.props.history.push('/'); break; case 'register': this.props.history.push(`/plugins/users-permissions/auth/register-success/${this.props.modifiedData.email}`); break; default: } } } handleSubmit = (e) => { e.preventDefault(); const formErrors = Object.keys(this.props.modifiedData).reduce((acc, key) => { if (isEmpty(get(this.props.modifiedData, key)) && !isBoolean(get(this.props.modifiedData, key))) { acc.push({ name: key, errors: [{ id: 'components.Input.error.validation.required' }] }); } if (!isEmpty(get(this.props.modifiedData, 'password')) && !isEmpty(get(this.props.modifiedData, 'confirmPassword')) && findIndex(acc, ['name', 'confirmPassword']) === -1) { if (get(this.props.modifiedData, 'password') !== get(this.props.modifiedData, 'confirmPassword')) { acc.push({ name: 'confirmPassword', errors: [{ id: 'users-permissions.components.Input.error.password.noMatch' }] }); } } return acc; }, []); this.props.setErrors(formErrors); if (isEmpty(formErrors)) { this.props.submit(); } } renderButton = () => { if (this.props.match.params.authType === 'login') { return (