From b4480f4bf7a8dccf027fa23c213d836a1ec2af51 Mon Sep 17 00:00:00 2001 From: Belen Curcio Date: Mon, 13 Aug 2018 13:25:51 -0300 Subject: [PATCH] Adding SignUp Form Functionality --- src/core/client/auth/components/SignIn.tsx | 139 +++++++++++++----- src/core/client/auth/components/SignUp.tsx | 2 +- .../auth/containers/SignInContainer.tsx | 35 ++++- 3 files changed, 131 insertions(+), 45 deletions(-) diff --git a/src/core/client/auth/components/SignIn.tsx b/src/core/client/auth/components/SignIn.tsx index 9244aa2af..f1b94b61e 100644 --- a/src/core/client/auth/components/SignIn.tsx +++ b/src/core/client/auth/components/SignIn.tsx @@ -1,6 +1,13 @@ -import * as React from "react"; -import { StatelessComponent } from "react"; -import * as styles from "./SignIn.css"; +import React, { StatelessComponent } from "react"; +import { Field, Form } from "react-final-form"; +import { OnSubmit } from "talk-framework/lib/form"; + +import { + composeValidators, + required, + validateEmail, + validatePassword, +} from "talk-framework/lib/validation"; import { Button, @@ -9,43 +16,101 @@ import { InputLabel, TextField, Typography, + ValidationMessage, } from "talk-ui/components"; -const SignIn: StatelessComponent = props => { +import * as styles from "./SignIn.css"; + +interface FormProps { + email: string; + password: string; +} + +export interface SignInForm { + onSubmit: OnSubmit; +} + +const SignIn: StatelessComponent = props => { return ( - - - Sign in to join the conversation - - - Email Address - - - - Password - - - - - -
- - - Don't have an account? - - -
-
+
+ {({ handleSubmit, submitting }) => ( + + + + Sign in to join the conversation + + + + {({ input, meta }) => ( + + Email Address + + {meta.touched && + (meta.error || meta.submitError) && ( + + {meta.error || meta.submitError} + + )} + + )} + + + + {({ input, meta }) => ( + + Password + + {meta.touched && + (meta.error || meta.submitError) && ( + + {meta.error || meta.submitError} + + )} + + + + + )} + + +
+ + + Don't have an account? + + +
+
+
+ )} + ); }; diff --git a/src/core/client/auth/components/SignUp.tsx b/src/core/client/auth/components/SignUp.tsx index 76f7d952a..7924ff5e2 100644 --- a/src/core/client/auth/components/SignUp.tsx +++ b/src/core/client/auth/components/SignUp.tsx @@ -37,7 +37,7 @@ export interface SignUpForm { const SignUp: StatelessComponent = props => { return (
- {({ handleSubmit, submitting, invalid }) => ( + {({ handleSubmit, submitting }) => ( diff --git a/src/core/client/auth/containers/SignInContainer.tsx b/src/core/client/auth/containers/SignInContainer.tsx index aabf4641d..fa4fa2d80 100644 --- a/src/core/client/auth/containers/SignInContainer.tsx +++ b/src/core/client/auth/containers/SignInContainer.tsx @@ -1,10 +1,31 @@ -import * as React from "react"; -import { StatelessComponent } from "react"; +import { BadUserInputError } from "talk-framework/lib/errors"; +import SignIn, { SignInForm } from "../components/SignIn"; -import SignIn from "../components/SignIn"; +import React, { Component } from "react"; +import { SignInMutation, withSignInMutation } from "../mutations"; -const SignInContainer: StatelessComponent = () => { - return ; -}; +interface SignInContainerProps { + signIn: SignInMutation; +} -export default SignInContainer; +class SignInContainer extends Component { + private onSubmit: SignInForm["onSubmit"] = async (input, form) => { + try { + await this.props.signIn(input); + form.reset(); + } catch (error) { + if (error instanceof BadUserInputError) { + return error.invalidArgsLocalized; + } + // tslint:disable-next-line:no-console + console.error(error); + } + return undefined; + }; + public render() { + return ; + } +} + +const enhanced = withSignInMutation(SignInContainer); +export default enhanced;