diff --git a/src/core/client/auth/components/SignIn.tsx b/src/core/client/auth/components/SignIn.tsx index 1abb35faf..6c06d4e9f 100644 --- a/src/core/client/auth/components/SignIn.tsx +++ b/src/core/client/auth/components/SignIn.tsx @@ -31,23 +31,24 @@ export interface SignInForm { onSubmit: OnSubmit; goToSignUp: () => void; goToForgotPassword: () => void; - error: string | null; } const SignIn: StatelessComponent = props => { return (
- {({ handleSubmit, submitting }) => ( + {({ handleSubmit, submitting, submitError }) => ( Sign in to join the conversation - {props.error && ( + + {submitError && ( - {props.error} + {submitError} )} + ; goToSignIn: () => void; - error: string | null; } const SignUp: StatelessComponent = props => { return ( - {({ handleSubmit, submitting }) => ( + {({ handleSubmit, submitError }) => ( Sign up to join the conversation - {props.error && ( + + {submitError && ( - {props.error} + {submitError} )} + { - public state = { error: null }; private setView = (view: View) => { this.props.setView({ view, @@ -33,16 +31,10 @@ class SignInContainer extends Component< private onSubmit: SignInForm["onSubmit"] = async (input, form) => { try { await this.props.signIn(input); - form.reset(); + return form.reset(); } catch (error) { - this.setState({ error: error.message }); - if (error instanceof BadUserInputError) { - return error.invalidArgsLocalized; - } - // tslint:disable-next-line:no-console - console.error(error); + return { [FORM_ERROR]: error.message }; } - return undefined; }; private goToForgotPassword = () => this.setView("FORGOT_PASSWORD"); private goToSignUp = () => this.setView("SIGN_UP"); @@ -52,7 +44,6 @@ class SignInContainer extends Component< onSubmit={this.onSubmit} goToForgotPassword={this.goToForgotPassword} goToSignUp={this.goToSignUp} - error={this.state.error} /> ); } diff --git a/src/core/client/auth/containers/SignUpContainer.tsx b/src/core/client/auth/containers/SignUpContainer.tsx index 776dc2f32..f18115557 100644 --- a/src/core/client/auth/containers/SignUpContainer.tsx +++ b/src/core/client/auth/containers/SignUpContainer.tsx @@ -1,5 +1,5 @@ +import { FORM_ERROR } from "final-form"; import React, { Component } from "react"; -import { BadUserInputError } from "talk-framework/lib/errors"; import SignUp, { SignUpForm } from "../components/SignUp"; import { @@ -24,7 +24,6 @@ class SignUpContainer extends Component< SignUpContainerProps, SignUpContainerState > { - public state = { error: "" }; private setView = (view: View) => { this.props.setView({ view, @@ -32,27 +31,15 @@ class SignUpContainer extends Component< }; private onSubmit: SignUpForm["onSubmit"] = async (input, form) => { try { - await this.props.signUp(input); + return await this.props.signUp(input); form.reset(); } catch (error) { - this.setState({ error: error.message }); - if (error instanceof BadUserInputError) { - return error.invalidArgsLocalized; - } - // tslint:disable-next-line:no-console - console.error(error); + return { [FORM_ERROR]: error.message }; } - return undefined; }; private goToSignIn = () => this.setView("SIGN_IN"); public render() { - return ( - - ); + return ; } }