From a94e56d45fb2766a7f22f8927b302c0feaa94623 Mon Sep 17 00:00:00 2001 From: Belen Curcio Date: Mon, 13 Aug 2018 13:37:18 -0300 Subject: [PATCH] Adding form validations for Forgot Password, ResetPassword, and more --- .../client/auth/components/ForgotPassword.tsx | 82 ++++++++---- .../client/auth/components/ResetPassword.tsx | 118 ++++++++++++++---- .../containers/ForgotPasswordContainer.tsx | 13 +- .../containers/ResetPasswordContainer.tsx | 13 +- 4 files changed, 171 insertions(+), 55 deletions(-) diff --git a/src/core/client/auth/components/ForgotPassword.tsx b/src/core/client/auth/components/ForgotPassword.tsx index 4c06dcbc4..e99230c9e 100644 --- a/src/core/client/auth/components/ForgotPassword.tsx +++ b/src/core/client/auth/components/ForgotPassword.tsx @@ -1,7 +1,14 @@ -import * as React from "react"; -import { StatelessComponent } from "react"; +import React, { StatelessComponent } from "react"; +import { Field, Form } from "react-final-form"; +import { OnSubmit } from "talk-framework/lib/form"; import * as styles from "./SignIn.css"; +import { + composeValidators, + required, + validateEmail, +} from "talk-framework/lib/validation"; + import { Button, Flex, @@ -9,28 +16,61 @@ import { InputLabel, TextField, Typography, + ValidationMessage, } from "talk-ui/components"; -const ForgotPassword: StatelessComponent = props => { +interface FormProps { + email: string; +} + +export interface ForgotPasswordForm { + onSubmit: OnSubmit; +} + +const ForgotPassword: StatelessComponent = props => { return ( - - - Forgot Password - - - Enter your email address below and we will send you a link to reset your - password. - - - Email Address - - -
- -
-
+
+ {({ handleSubmit }) => ( + + + + Forgot Password + + + Enter your email address below and we will send you a link to + reset your password. + + + {({ input, meta }) => ( + + Email Address + + {meta.touched && + (meta.error || meta.submitError) && ( + + {meta.error || meta.submitError} + + )} + + )} + +
+ +
+
+
+ )} + ); }; diff --git a/src/core/client/auth/components/ResetPassword.tsx b/src/core/client/auth/components/ResetPassword.tsx index 5f000d091..3ca37cf80 100644 --- a/src/core/client/auth/components/ResetPassword.tsx +++ b/src/core/client/auth/components/ResetPassword.tsx @@ -1,37 +1,111 @@ -import * as React from "react"; -import { StatelessComponent } from "react"; +import React, { StatelessComponent } from "react"; +import { Field, Form } from "react-final-form"; +import { OnSubmit } from "talk-framework/lib/form"; import * as styles from "./SignIn.css"; +import { + composeValidators, + required, + validateEqualPasswords, + validatePassword, +} from "talk-framework/lib/validation"; + import { Button, Flex, FormField, + InputDescription, InputLabel, TextField, Typography, + ValidationMessage, } from "talk-ui/components"; -const ResetPassword: StatelessComponent = props => { +interface FormProps { + password: string; + confirmPassword: string; +} + +export interface ResetPasswordForm { + onSubmit: OnSubmit; +} + +const ResetPassword: StatelessComponent = props => { return ( - - - Reset Password - - - Password - Must be at least 8 characters - - - - Confirm Password - - -
- -
-
+
+ {({ handleSubmit }) => ( + + + + Reset Password + + + {({ input, meta }) => ( + + Password + + Must be at least 8 characters + + + {meta.touched && + (meta.error || meta.submitError) && ( + + {meta.error || meta.submitError} + + )} + + )} + + + + {({ input, meta }) => ( + + Confirm Password + + Must be at least 8 characters + + + {meta.touched && + (meta.error || meta.submitError) && ( + + {meta.error || meta.submitError} + + )} + + )} + + +
+ +
+
+
+ )} + ); }; diff --git a/src/core/client/auth/containers/ForgotPasswordContainer.tsx b/src/core/client/auth/containers/ForgotPasswordContainer.tsx index b364e7e9e..37b842160 100644 --- a/src/core/client/auth/containers/ForgotPasswordContainer.tsx +++ b/src/core/client/auth/containers/ForgotPasswordContainer.tsx @@ -1,10 +1,11 @@ -import * as React from "react"; -import { StatelessComponent } from "react"; - +import React, { Component } from "react"; import ForgotPassword from "../components/ForgotPassword"; -const ForgotPasswordContainer: StatelessComponent = () => { - return ; -}; +class ForgotPasswordContainer extends Component { + public render() { + // tslint:disable-next-line:no-empty + return {}} />; + } +} export default ForgotPasswordContainer; diff --git a/src/core/client/auth/containers/ResetPasswordContainer.tsx b/src/core/client/auth/containers/ResetPasswordContainer.tsx index 6dab0eef1..cfca96d9d 100644 --- a/src/core/client/auth/containers/ResetPasswordContainer.tsx +++ b/src/core/client/auth/containers/ResetPasswordContainer.tsx @@ -1,10 +1,11 @@ -import * as React from "react"; -import { StatelessComponent } from "react"; - +import React, { Component } from "react"; import ResetPassword from "../components/ResetPassword"; -const ResetPasswordContainer: StatelessComponent = () => { - return ; -}; +class ResetPasswordContainer extends Component { + public render() { + // tslint:disable-next-line:no-empty + return {}} />; + } +} export default ResetPasswordContainer;