From 4bbebc183e75e287e28d5b4369699d1bc40c0cd1 Mon Sep 17 00:00:00 2001 From: ilyayudovin Date: Fri, 28 Aug 2020 18:40:23 +0300 Subject: feat: submit Form on button click --- src/containers/Registration/Registration.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/containers') diff --git a/src/containers/Registration/Registration.tsx b/src/containers/Registration/Registration.tsx index 7d2a758..20bc283 100644 --- a/src/containers/Registration/Registration.tsx +++ b/src/containers/Registration/Registration.tsx @@ -1,4 +1,4 @@ -import React, { useState, useRef } from 'react'; +import React, {useState, useRef, FormEvent} from 'react'; import { useHistory } from 'react-router-dom'; import { makeStyles } from '@material-ui/core/styles'; import { @@ -64,11 +64,13 @@ const Registration: React.FC = () => { return values.validUsername && values.validEmail && values.validPassword; }; - const handleSubmit = () => { + const handleSubmit = (event: FormEvent) => { + event.preventDefault(); const username = usernameRef.current?.value?.toLowerCase(); const password = passwordRef.current?.value; const email = emailRef.current?.value; if (username && password && checkFromValidation()) { + console.log('yes'); post('/users', { username, password, email }) .then(() => login(username, password)) .then(() => history.push(`/profile/${username}`)); @@ -98,7 +100,7 @@ const Registration: React.FC = () => { return ( <>
Sign Up
-
+ { ) }} /> - +
Already have an account?
-- cgit v1.2.3