generated from ReCoded-Org/capstone-react-redux-template
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* login component completed * login page design completed * sign up page design completed * added form validation to sign up page * deleted node modules Co-authored-by: allan <[email protected]>
- Loading branch information
1 parent
fea30d1
commit a4ae624
Showing
5 changed files
with
250 additions
and
113 deletions.
There are no files selected for viewing
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 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,86 @@ | ||
import React from "react"; | ||
import { useForm } from "react-hook-form"; | ||
|
||
function SignUp() { | ||
const { | ||
register, | ||
formState: { errors }, | ||
handleSubmit, | ||
} = useForm(); | ||
const onSubmit = (data) => console.log(data); | ||
return ( | ||
<div className=" my-52"> | ||
<h1 className="font-inter font-black text-2xl mb-6">Sign Up</h1> | ||
<div className="w-full max-w-sm mx-auto"> | ||
<form onSubmit={handleSubmit(onSubmit)}> | ||
<div className="mb-4"> | ||
<input | ||
className="shadow border-2 border-black rounded-md w-full py-2 px-3 text-dark-gray leading-tight focus:outline-1 focus:shadow-outline" | ||
id="username" | ||
type="text" | ||
placeholder="Username " | ||
{...register("name", { required: true })} | ||
/> | ||
<error className="text-primary font-inter"> | ||
{errors.name?.type === "required" && "Please Enter your Name"} | ||
</error> | ||
</div> | ||
<div className="mb-4"> | ||
<input | ||
className="shadow border-2 border-black rounded-md w-full py-2 px-3 text-dark-gray leading-tight focus:outline-1 focus:shadow-outline" | ||
id="email" | ||
type="email" | ||
placeholder="[email protected] " | ||
{...register("email", { | ||
required: true, | ||
pattern: /^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$/i, | ||
})} | ||
/> | ||
<error className="text-primary font-inter"> | ||
{errors.email?.type === "required" && "Please Enter an Email"} | ||
{errors.email?.type === "pattern" && | ||
"Entered email is in wrong format"} | ||
</error> | ||
</div> | ||
<div className="mb-4 font-inter"> | ||
<input | ||
className="shadow border-2 border-black rounded-md w-full py-2 px-3 text-dark-gray leading-tight focus:outline-1 focus:shadow-outline" | ||
id="password" | ||
type="password" | ||
placeholder="Password " | ||
{...register("password", { | ||
required: true, | ||
minLength: 8, | ||
maxLength: 20, | ||
})} | ||
/> | ||
<error className="text-primary font-inter"> | ||
{errors.password?.type === "required" && | ||
"Please Enter a Password"} | ||
{errors.password?.type === "minLength" && | ||
"Entered password is less than 8 characters"} | ||
{errors.password?.type === "maxLength" && | ||
"Entered password is more than 20 characters"} | ||
</error> | ||
</div> | ||
<div className="mb-4"> | ||
<button | ||
type="submit" | ||
className="w-full bg-accent font-inter text-white rounded-md py-1 hover:bg-red-500" | ||
> | ||
Sign Up | ||
</button> | ||
</div> | ||
<div className="mb-4"> | ||
<p className="text-dark-gray"> | ||
Already Have an Account?{" "} | ||
<span className="font-semibold">Log in</span> | ||
</p> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default SignUp; |
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,8 @@ | ||
import renderer from "react-test-renderer"; | ||
|
||
import SignUp from "../SignUp"; | ||
|
||
it("renders correctly when the component matches the snapshot", () => { | ||
const tree = renderer.create(<SignUp />).toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); |
94 changes: 94 additions & 0 deletions
94
src/components/signup/__test__/__snapshots__/SignUp.test.js.snap
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,94 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`renders correctly when the component matches the snapshot 1`] = ` | ||
<div | ||
className=" my-52" | ||
> | ||
<h1 | ||
className="font-inter font-black text-2xl mb-6" | ||
> | ||
Sign Up | ||
</h1> | ||
<div | ||
className="w-full max-w-sm mx-auto" | ||
> | ||
<form | ||
onSubmit={[Function]} | ||
> | ||
<div | ||
className="mb-4" | ||
> | ||
<input | ||
className="shadow border-2 border-black rounded-md w-full py-2 px-3 text-dark-gray leading-tight focus:outline-1 focus:shadow-outline" | ||
id="username" | ||
name="name" | ||
onBlur={[Function]} | ||
onChange={[Function]} | ||
placeholder="Username " | ||
type="text" | ||
/> | ||
<error | ||
className="text-primary font-inter" | ||
/> | ||
</div> | ||
<div | ||
className="mb-4" | ||
> | ||
<input | ||
className="shadow border-2 border-black rounded-md w-full py-2 px-3 text-dark-gray leading-tight focus:outline-1 focus:shadow-outline" | ||
id="email" | ||
name="email" | ||
onBlur={[Function]} | ||
onChange={[Function]} | ||
placeholder="[email protected] " | ||
type="email" | ||
/> | ||
<error | ||
className="text-primary font-inter" | ||
/> | ||
</div> | ||
<div | ||
className="mb-4 font-inter" | ||
> | ||
<input | ||
className="shadow border-2 border-black rounded-md w-full py-2 px-3 text-dark-gray leading-tight focus:outline-1 focus:shadow-outline" | ||
id="password" | ||
name="password" | ||
onBlur={[Function]} | ||
onChange={[Function]} | ||
placeholder="Password " | ||
type="password" | ||
/> | ||
<error | ||
className="text-primary font-inter" | ||
/> | ||
</div> | ||
<div | ||
className="mb-4" | ||
> | ||
<button | ||
className="w-full bg-accent font-inter text-white rounded-md py-1 hover:bg-red-500" | ||
type="submit" | ||
> | ||
Sign Up | ||
</button> | ||
</div> | ||
<div | ||
className="mb-4" | ||
> | ||
<p | ||
className="text-dark-gray" | ||
> | ||
Already Have an Account? | ||
<span | ||
className="font-semibold" | ||
> | ||
Log in | ||
</span> | ||
</p> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
`; |
Oops, something went wrong.