diff options
author | ilyayudovin <ilyayudovin123@gmail.com> | 2020-08-28 18:40:23 +0300 |
---|---|---|
committer | ilyayudovin <ilyayudovin123@gmail.com> | 2020-08-28 18:40:23 +0300 |
commit | 4bbebc183e75e287e28d5b4369699d1bc40c0cd1 (patch) | |
tree | 9e52e404f57ed0a01545580b053f7b1e8953eed9 | |
parent | fa133c40edb633c63d37619682ba0771d4481ed9 (diff) | |
download | which-ui-4bbebc183e75e287e28d5b4369699d1bc40c0cd1.tar.gz |
feat: submit Form on button click
-rw-r--r-- | src/containers/Registration/Registration.tsx | 10 |
1 files changed, 6 insertions, 4 deletions
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<HTMLFormElement>) => { + 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 ( <> <div className={classes.formHeader}>Sign Up</div> - <form className={classes.root} noValidate autoComplete="off"> + <form className={classes.root} noValidate autoComplete="off" onSubmit={handleSubmit}> <TextField inputRef={usernameRef} label="Username" @@ -152,7 +154,7 @@ const Registration: React.FC = () => { ) }} /> - <Button variant="contained" onClick={handleSubmit}>submit</Button> + <Button variant="contained" type="submit" >submit</Button> </form> <div className={classes.formTransfer}> <div>Already have an account?</div> |