/** * * AuthPage * */ import React from 'react'; import PropTypes from 'prop-types'; import { connect } from 'react-redux'; import { bindActionCreators, compose } from 'redux'; import { get, map } from 'lodash'; import cn from 'classnames'; // 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, } 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.authType); } } handleSubmit = (e) => { e.preventDefault(); // TODO formErrors this.props.setErrors(); console.log('ok'); } renderButton = () => { if (this.props.match.params.authType === 'login') { return (
); } return (
); } render() { const borderTop = this.props.match.params.authType === 'login' || this.props.match.params.authType === 'register' ? { borderTop: '2px solid #1C5DE7'} : { borderTop: '2px solid #F64D0A'}; const inputs = get(form, ['form', this.props.match.params.authType]); return (
{/* TODO Handle header */} strapi
{map(inputs, (input, key) => ( ))} {this.renderButton()}
); } } AuthPage.propTypes = { match: PropTypes.object.isRequired, modifiedData: PropTypes.object.isRequired, onChangeInput: PropTypes.func.isRequired, setErrors: PropTypes.func.isRequired, setForm: PropTypes.func.isRequired, }; const mapStateToProps = makeSelectAuthPage(); function mapDispatchToProps(dispatch) { return bindActionCreators( { onChangeInput, setErrors, setForm, }, dispatch ); } const withConnect = connect(mapStateToProps, mapDispatchToProps); /* Remove this line if the container doesn't have a route and * check the documentation to see how to create the container's store */ const withReducer = injectReducer({ key: 'authPage', reducer }); /* Remove the line below the container doesn't have a route and * check the documentation to see how to create the container's store */ const withSaga = injectSaga({ key: 'authPage', saga }); export default compose( withReducer, withSaga, withConnect, )(AuthPage);