Logic for form added

This commit is contained in:
2021-09-25 19:48:23 -03:00
parent 5fb6f228ea
commit 644fe59e77
3 changed files with 98 additions and 14 deletions

View File

@@ -1,10 +1,23 @@
import React from 'react'
const LoginForm = () => {
const LoginForm = (props) => {
return (
<form>
<input type="email" placeholder="Email"></input>
<input type="password" placeholder="Password"></input>
<form onSubmit={props.sendForm}>
<input
type="email"
placeholder="Email"
onChange= {(e) => {
props.setEmail(e.target.value)
}}
/>
<input
type="password"
placeholder="Password"
onChange= { (e) => {
props.setPassword(e.target.value)
}}
/>
<input type="submit" value="Login"></input>
</form>
)

View File

@@ -1,12 +1,37 @@
import React from 'react'
const RegisterForm = () => {
const RegisterForm = (props) => {
return (
<form>
<input type="email" placeholder="Email"></input>
<input type="password" placeholder="Password"></input>
<input type="password" placeholder="Confirm Password"></input>
<input type="submit" value="Register"></input>
<form onSubmit={props.sendForm}>
<input
type="email"
placeholder="Email"
onChange={(e) => {
props.setEmail(e.target.value)
}}
/>
<input
type="password"
placeholder="Password"
onChange={(e) => {
props.setPassword(e.target.value)
}}
/>
<input
type="password"
placeholder="Confirm Password"
onChange={(e) => {
props.setConfirmPassword(e.target.value)
}}
/>
<input
type="submit"
value="Register"
/>
</form>
)
}

View File

@@ -4,7 +4,11 @@ import RegisterForm from './Identify Childrens/RegisterForm'
const Identify = () => {
const [act, setAct] = useState('register')
const [act, setAct] = useState('')
const [email, setEmail] = useState('')
const [password, setPassword] = useState('')
const [confirmPassword, setConfirmPassword] = useState('')
const defineLogin = () => {
if (act !== 'login') {
@@ -17,6 +21,48 @@ const Identify = () => {
setAct('register')
}
}
const sendForm = (e) => {
e.preventDefault()
if (!email.trim()) {
alert('EMAIL EMPTY')
return
}
if (!password.trim()) {
alert('PASSWORD EMPTY')
return
}
if (act === 'register') {
if (!confirmPassword.trim()) {
alert('CONFIRM PASSWORD PLEASE')
return
}
e.target.reset()
setEmail('')
setPassword('')
setConfirmPassword('')
//SEND TO FIREBASE
return
}
if (act === 'login') {
e.target.reset()
setEmail('')
setPassword('')
//SEND TO FIREBASE
return
}
alert('ACTION NOT VALID')
}
React.useEffect( () => {
const urlInfo = new URLSearchParams(window.location.search)
@@ -56,7 +102,7 @@ const Identify = () => {
className={
act === 'register' ? 'option active-option': 'option'
}
onClick={() => {
defineRegister()
}}
@@ -69,10 +115,10 @@ const Identify = () => {
<div className="form-container">
{
act === 'login' ? <LoginForm action={act}/> : null
act === 'login' ? <LoginForm setEmail={setEmail} setPassword={setPassword} sendForm={sendForm}/> : null
}
{
act === 'register' ? <RegisterForm action={act}/> : null
act === 'register' ? <RegisterForm setEmail={setEmail} setPassword={setPassword} setConfirmPassword={setConfirmPassword} sendForm={sendForm}/> : null
}
</div>
</div>