From 8a7ea9cdef4a813cd2476c00023c455b19308d5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bel=C3=A9n=20Curcio?= Date: Sun, 12 Aug 2018 23:08:23 -0300 Subject: [PATCH] First integration of forms --- src/core/client/auth/components/SignUp.tsx | 123 +++++++++++------- .../auth/containers/SignUpContainer.tsx | 35 ++++- .../ui/components/TextField/TextField.tsx | 8 ++ 3 files changed, 113 insertions(+), 53 deletions(-) diff --git a/src/core/client/auth/components/SignUp.tsx b/src/core/client/auth/components/SignUp.tsx index 49cce2aa1..4428a8467 100644 --- a/src/core/client/auth/components/SignUp.tsx +++ b/src/core/client/auth/components/SignUp.tsx @@ -1,5 +1,8 @@ import * as React from "react"; import { StatelessComponent } from "react"; +import { Field, Form } from "react-final-form"; +import { OnSubmit } from "talk-framework/lib/form"; +import { required } from "talk-framework/lib/validation"; import * as styles from "./SignUp.css"; import { @@ -11,53 +14,81 @@ import { Typography, } from "talk-ui/components"; -const SignUp: StatelessComponent = props => { +interface FormProps { + email: string; + username: string; + password: string; + confirmPassword: string; +} + +export interface SignUpForm { + onSubmit: OnSubmit; +} + +const SignUp: StatelessComponent = props => { return ( - - - - Sign up to join the conversation - - - Email Address - - - - Username - - A unique identifier displayed on your comments. You may use “_” and - “.” - - - - - Password - - Must be at least 8 characters - - - - - Confirm Password - - - -
- - - Already have an account? - - -
-
+
+ {({ handleSubmit, submitting }) => ( + + + + + Sign up to join the conversation + + + + {({ input, meta }) => ( + + Email Address + + + )} + + + + Username + + A unique identifier displayed on your comments. You may use + “_” and “.” + + + + + Password + + Must be at least 8 characters + + + + + Confirm Password + + + +
+ + + Already have an account? + + +
+
+
+ )} + ); }; diff --git a/src/core/client/auth/containers/SignUpContainer.tsx b/src/core/client/auth/containers/SignUpContainer.tsx index 9db82383a..eac0f8d14 100644 --- a/src/core/client/auth/containers/SignUpContainer.tsx +++ b/src/core/client/auth/containers/SignUpContainer.tsx @@ -1,10 +1,31 @@ -import * as React from "react"; -import { StatelessComponent } from "react"; +import { BadUserInputError } from "talk-framework/lib/errors"; +import SignUp, { SignUpForm } from "../components/SignUp"; -import SignUp from "../components/SignUp"; +import React, { Component } from "react"; +import { SignUpMutation, withSignUpMutation } from "../mutations"; -const SignUpContainer: StatelessComponent = () => { - return ; -}; +interface SignUpContainerProps { + signUp: SignUpMutation; +} -export default SignUpContainer; +class SignUpContainer extends Component { + private onSubmit: SignUpForm["onSubmit"] = async (input, form) => { + try { + await this.props.signUp(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 = withSignUpMutation(SignUpContainer); +export default enhanced; diff --git a/src/core/client/ui/components/TextField/TextField.tsx b/src/core/client/ui/components/TextField/TextField.tsx index 391b3759a..756242ec3 100644 --- a/src/core/client/ui/components/TextField/TextField.tsx +++ b/src/core/client/ui/components/TextField/TextField.tsx @@ -37,6 +37,14 @@ export interface TextFieldProps { * Mark as readonly */ readOnly?: boolean; + /** + * Name + */ + name?: string; + /** + * onChange + */ + onChange?: (event: any) => void; } const TextField: StatelessComponent = props => {