-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: Created the signup react page under the client folder. (#24)
TA-7 * added signup page under client with error checking Co-authored-by: Nandhakishore K.S <[email protected]> Co-authored-by: Andrew Qian <[email protected]>
- Loading branch information
1 parent
78d07bf
commit 4c3e8f3
Showing
14 changed files
with
33,712 additions
and
7,336 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { useState } from "react"; | ||
import axios from 'axios'; | ||
import './signupLogin.css'; | ||
|
||
function Signup() { | ||
|
||
const initialValues = { username: "", mailAddress: "", password: "" }; | ||
const [formValues, setFormValues] = useState(initialValues); | ||
const [formErrors, setFormErrors] = useState([]); | ||
|
||
const handleChange = (e) => { | ||
// console.log(e.target.value); | ||
const { name, value } = e.target; | ||
setFormValues({...formValues, [name]: value }); | ||
} | ||
|
||
const handleSubmit = (e) => { | ||
e.preventDefault(); | ||
setFormErrors(validate(formValues)); | ||
const body = { name: formValues.username, email: formValues.mailAddress, password: formValues.password }; | ||
let axiosConfig = { | ||
headers: { | ||
'Content-Type': 'application/json;charset=UTF-8', | ||
} | ||
}; | ||
axios.post('http://localhost:8000/api/users', body, axiosConfig) | ||
.then(res => { | ||
console.log(res); | ||
}).catch(error => { | ||
console.error(error); | ||
}) | ||
} | ||
|
||
const validate = (values) => { | ||
const errors = {}; | ||
const regex = /^[a-zA-Z0-9_.+-][email protected]$/; | ||
if(!values.username){ | ||
errors.username = "Please enter the username"; | ||
} | ||
if(!values.mailAddress){ | ||
errors.mailAddress = "Please enter your email address"; | ||
} | ||
else if (!regex.test(values.mailAddress)){ | ||
errors.mailAddress = "Please enter the valid mail address"; | ||
} | ||
if(!values.password){ | ||
errors.password = "Please enter your password"; | ||
} | ||
return errors; | ||
} | ||
return ( | ||
<div className="formContainer"> | ||
<form onSubmit={(e) => handleSubmit(e)}> | ||
<h1>Signup Form</h1> | ||
<hr /> | ||
<div className="uiForm"> | ||
<div className="formField"> | ||
<label>Username</label> | ||
<input | ||
type="text" | ||
placeholder="Username" | ||
name="username" | ||
onChange={(e) => handleChange(e)} | ||
/> | ||
</div> | ||
<p className="errorMsg">{formErrors.username}</p> | ||
<div className="formField"> | ||
<label>Mail Address</label> | ||
<input | ||
type="text" | ||
placeholder="Mail Address" | ||
name="mailAddress" | ||
onChange={(e) => handleChange(e)} | ||
/> | ||
</div> | ||
<p className="errorMsg">{formErrors.mailAddress}</p> | ||
<div className="formField"> | ||
<label>Password</label> | ||
<input type="text" | ||
placeholder="Password" | ||
name="password" | ||
onChange={(e) => handleChange(e)} | ||
/> | ||
</div> | ||
<p className="errorMsg">{formErrors.password}</p> | ||
<button className="submitButton">Signup</button> | ||
</div> | ||
</form> | ||
</div> | ||
); | ||
} | ||
|
||
export default Signup; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.errorMsg { | ||
color: red; | ||
margin: 0; | ||
align-self: flex-start; | ||
} |
Oops, something went wrong.