import "./Auth.scss"; import { Button, Card, FormGroup, H2, InputGroup } from "@blueprintjs/core"; import * as React from "react"; import { connect } from "react-redux"; import { RouteComponentProps, withRouter } from "react-router"; import { Dispatch } from "redux"; import { signupStart } from "../redux/auth/actions"; import { IAppState } from "../redux/reducers"; interface ISignupComponentProps extends RouteComponentProps { inProgress: boolean; error: string | null; spinner: boolean; signup: (username: string, password: string, email: string) => void; } interface ISignupComponentState { username: string; password: string; email: string; } export class SignupComponent extends React.PureComponent< ISignupComponentProps, ISignupComponentState > { constructor(props: ISignupComponentProps) { super(props); this.submit = this.submit.bind(this); this.change = this.change.bind(this); this.updateFields = this.updateFields.bind(this); this.state = { username: "", password: "", email: "" }; } public change() { this.props.history.push("/login"); } public submit(e: T) { e.preventDefault(); const { username, password, email } = this.state; if (!this.props.inProgress) { this.props.signup(username, password, email); } } public updateFields(e: React.FormEvent) { const { value, name } = e.currentTarget; this.setState({ ...this.state, [name]: value }); } public render() { return ( <>

Signup

{this.props.error}
); } } function mapStateToProps(state: IAppState) { return { inProgress: state.auth.inProgress, error: state.auth.formError, spinner: state.auth.formSpinner, }; } function mapDispatchToProps(dispatch: Dispatch) { return { signup: (username: string, password: string, email: string) => dispatch(signupStart(username, password, email)), }; } export const Signup = withRouter( connect(mapStateToProps, mapDispatchToProps)(SignupComponent), );