import React, { useState } from "react" import PropTypes from "prop-types" import { connect } from "react-redux" import { Redirect } from "react-router-dom" import { userSignUp } from "../../actions/users" const mapStateToProps = (state) => ({ isLogged: state.userStore.get("isLogged"), isLoading: state.userStore.get("loading"), error: state.userStore.get("error"), }); const mapDispatchToProps = { userSignUp }; const UserSignUp = (props) => { if (props.isLogged) { return (); } const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); const [passwordConfirm, setPasswordConfirm] = useState(""); const handleSubmit = (e) => { e.preventDefault(); props.userSignUp({ "username": username, "password": password, "password_confirm": passwordConfirm, }); } return (

Sign up


{props.error && props.error !== "" &&
{props.error}
}
handleSubmit(e)}>
setUsername(e.target.value)} />
setPassword(e.target.value)} />
setPasswordConfirm(e.target.value)} />
{props.isLoading && } {props.isLoading || }
); } UserSignUp.propTypes = { isLogged: PropTypes.bool.isRequired, isLoading: PropTypes.bool.isRequired, userSignUp: PropTypes.func.isRequired, error: PropTypes.string, }; export default connect(mapStateToProps, mapDispatchToProps)(UserSignUp);