From 802b7417c8b16cc8922c0a1526e9b769ca2cc28f Mon Sep 17 00:00:00 2001 From: eug-vs Date: Thu, 25 Jun 2020 15:49:06 +0300 Subject: feat: validate form --- src/pages/AuthPage/AuthPage.tsx | 4 ++-- src/pages/AuthPage/SignUpForm.tsx | 36 ++++++++++++++++++++++++------------ 2 files changed, 26 insertions(+), 14 deletions(-) (limited to 'src/pages/AuthPage') diff --git a/src/pages/AuthPage/AuthPage.tsx b/src/pages/AuthPage/AuthPage.tsx index dc90c01..0938bce 100644 --- a/src/pages/AuthPage/AuthPage.tsx +++ b/src/pages/AuthPage/AuthPage.tsx @@ -29,8 +29,8 @@ const AuthPage: React.FC = ({ logIn }) => { }; const footerInfo = { - signIn: ['Don\'t have an account?', 'Sign in'], - signUp: ['Already have an account?', 'Sign up'] + signIn: ['Don\'t have an account?', 'Sign up'], + signUp: ['Already have an account?', 'Sign in'] }; return ( diff --git a/src/pages/AuthPage/SignUpForm.tsx b/src/pages/AuthPage/SignUpForm.tsx index 0e3d0c7..4a84830 100644 --- a/src/pages/AuthPage/SignUpForm.tsx +++ b/src/pages/AuthPage/SignUpForm.tsx @@ -1,4 +1,4 @@ -import React, { useRef } from 'react'; +import React, { useState, useRef } from 'react'; import { makeStyles } from '@material-ui/core/styles'; import TextField from '@material-ui/core/TextField'; import Button from '@material-ui/core/Button'; @@ -26,31 +26,43 @@ const useStyles = makeStyles(theme => ({ })); const SignUpForm: React.FC = ({ logIn }) => { + const [error, setError] = useState(false); const classes = useStyles(); - const inputRef = useRef(); - const inputRefPassword = useRef(); + const usernameRef = useRef(); + const emailRef = useRef(); + const passwordRef = useRef(); const onClick = () => { - const username = inputRef.current?.value; - const password = inputRefPassword.current?.value; + const username = usernameRef.current?.value; + const password = passwordRef.current?.value; + const email = emailRef.current?.value; if (username && password) { - post('/users', { username, password }).then(() => { - logIn(username, password); + post('/users', { username, password, email }).then(() => { + logIn(username, password).then(success => { + }); }); - } + } else setError(true); }; return ( <>
Sign Up
- - + + -- cgit v1.2.3