-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat-#38: Implemented User Authentication UI #126
Merged
krishnaacharyaa
merged 25 commits into
krishnaacharyaa:main
from
0xmohitsen:enhance/wanderLust
Apr 7, 2024
Merged
Changes from 22 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
e93bb9f
feat: Added required svg icons
0xmohitsen fc9065e
feat: Added zod for validation
0xmohitsen f65842a
feat: Installed react-hook-form + zod + @hookform/resolver
0xmohitsen 7c855b2
feat: Added /user-auth route
0xmohitsen 3d65cb5
feat: Added colors
0xmohitsen 3fdc8f6
feat: Added signin-page
0xmohitsen 4bf0483
feat: Correction in imported signin page name
0xmohitsen 88e0863
feat: Added signin-page
0xmohitsen 84720e3
feat: Added signin-page
0xmohitsen 5b6f6bb
feat-#38: Added email validation check + reduced the width + made cha…
0xmohitsen a3d5010
feat-#38: Added email validation check + reduced the width + made cha…
0xmohitsen 561825a
Merge branch 'krishnaacharyaa:main' into enhance/wanderLust
0xmohitsen 6471e06
feat-#38: Removed hardcode css + removed unnecessary breakpoint prefi…
0xmohitsen 31211c0
feat-#38: Configured for color
0xmohitsen 007b3bd
feat-#38: Added signUp schema
0xmohitsen fee59e3
feat-#38: Removed hardcode values
0xmohitsen 7efd726
feat-#38: Modified UI for mobile screen
0xmohitsen 611e341
feat-#38: Modified UI for mobile screen
0xmohitsen 4f75bbb
feat-#38: Executed npm run format
0xmohitsen f734270
feat-#38: Leveraged tailwind classes for colors + removed custom colors
0xmohitsen dc5ce21
feat-#38: Removed custom corner case
0xmohitsen b5b590a
feat-#38: Added signup page
0xmohitsen 7312064
feat-#38: Refactored the auth-form layout code from auth pages + crea…
0xmohitsen 7c67e72
Revert "feat-#38: Refactored the auth-form layout code from auth page…
0xmohitsen 1d88d5b
feat-#38: Changed /user-auth route name to /signin route
0xmohitsen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,37 @@ | ||
import { z } from 'zod'; | ||
|
||
const emailRegex = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i; | ||
|
||
export const signInSchema = z.object({ | ||
email: z | ||
.string() | ||
.min(1, { message: 'Email is required' }) | ||
.regex(emailRegex, 'Invalid email address'), | ||
password: z.string().min(1, { message: 'Password is required' }), | ||
}); | ||
|
||
export const signUpSchema = z | ||
.object({ | ||
username: z.string().min(1, { message: 'Username is required' }), | ||
email: z | ||
.string() | ||
.min(1, { message: 'Email is required' }) | ||
.regex(emailRegex, 'Invalid email address'), | ||
password: z.string().min(1, { message: 'Password is required' }), | ||
confirmPassword: z.string().min(1, { message: 'Confirm Password is required' }), | ||
}) | ||
.refine((data) => data.username.trim().length >= 5, { | ||
message: 'Username must be at least 5 characters long', | ||
path: ['username'], | ||
}) | ||
.refine((data) => data.password === data.confirmPassword, { | ||
message: 'Passwords do not match', | ||
path: ['confirmPassword'], | ||
}) | ||
.refine((data) => data.password.trim().length >= 8, { | ||
message: 'Password must be at least 8 characters long', | ||
path: ['password'], | ||
}); | ||
|
||
export type TSignInSchema = z.infer<typeof signInSchema>; | ||
export type TSignUpSchema = z.infer<typeof signUpSchema>; |
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,109 @@ | ||
import { Link, useNavigate } from 'react-router-dom'; | ||
import AddGoogleIcon from '@/assets/svg/google-color-icon.svg'; | ||
import AddGithubIcon from '@/assets/svg/github-icon.svg'; | ||
import { useForm } from 'react-hook-form'; | ||
import type { FieldValues } from 'react-hook-form'; | ||
import { TSignInSchema, signInSchema } from '@/lib/types'; | ||
import 'react-toastify/dist/ReactToastify.css'; | ||
import { zodResolver } from '@hookform/resolvers/zod'; | ||
import { toast } from 'react-toastify'; | ||
|
||
function signin() { | ||
const navigate = useNavigate(); | ||
|
||
const { | ||
register, | ||
handleSubmit, | ||
formState: { errors, isSubmitting }, | ||
reset, | ||
} = useForm<TSignInSchema>({ resolver: zodResolver(signInSchema) }); | ||
|
||
const onSubmit = async (data: FieldValues) => { | ||
if (data.email === '[email protected]') { | ||
toast.error('Submitting form is failed'); | ||
return; | ||
} | ||
|
||
// TODO: Server-side validation | ||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
|
||
reset(); | ||
navigate('/'); | ||
}; | ||
|
||
return ( | ||
<div className="m-4 flex-grow cursor-default bg-white py-4"> | ||
<div className="mb-4 flex justify-center"> | ||
<div className="flex w-full items-center justify-center"> | ||
<h2 className="w-3/4 text-center text-lg font-bold text-black sm:text-xl"> | ||
Sign in to WanderLust | ||
krishnaacharyaa marked this conversation as resolved.
Show resolved
Hide resolved
krishnaacharyaa marked this conversation as resolved.
Show resolved
Hide resolved
0xmohitsen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</h2> | ||
</div> | ||
</div> | ||
<div className="m-2 mt-8 flex flex-col items-center justify-center gap-2"> | ||
<form onSubmit={handleSubmit(onSubmit)} className="w-full md:w-3/4 lg:w-2/5"> | ||
<div className="mb-2"> | ||
<input | ||
{...register('email')} | ||
type="email" | ||
placeholder="Email" | ||
className="w-full rounded-lg bg-zinc-100 p-3 font-normal placeholder:text-sm placeholder:text-neutral-500" | ||
/> | ||
{errors.email && ( | ||
<p className="p-3 text-xs text-red-500">{`${errors.email.message}`}</p> | ||
)} | ||
</div> | ||
|
||
<div className="mb-4"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This has a same pattern of classnames for both signin and signup pages. Can we extract a component out and reuse in both the pages? |
||
<input | ||
{...register('password')} | ||
type="password" | ||
placeholder="Password" | ||
className="w-full rounded-lg bg-zinc-100 p-3 font-normal placeholder:text-sm placeholder:text-neutral-500" | ||
/> | ||
{errors.password && ( | ||
<p className="p-3 text-xs text-red-500">{`${errors.password.message}`}</p> | ||
)} | ||
</div> | ||
|
||
<button | ||
disabled={isSubmitting} | ||
type="submit" | ||
className="flex w-full items-center justify-center rounded-lg bg-neutral-800 p-3 text-base font-medium text-light disabled:bg-neutral-600 sm:text-lg sm:font-semibold" | ||
> | ||
krishnaacharyaa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Log In | ||
</button> | ||
</form> | ||
<div className="mt-2 flex w-5/6 flex-col items-center justify-center gap-4 text-center text-sm font-normal sm:text-base"> | ||
<p> | ||
Don't have an account? | ||
<Link to={'/signup'} className="text-blue-600 hover:text-blue-500"> | ||
{' '} | ||
Sign up now | ||
</Link> | ||
</p> | ||
|
||
<span>OR</span> | ||
</div> | ||
|
||
<Link | ||
to={'/google-auth'} | ||
className="flex w-full items-center justify-center space-x-2 rounded-lg border-2 border-b-4 border-gray-300 p-3 text-center hover:bg-gray-50 md:w-3/4 lg:w-2/5" | ||
> | ||
<img className="h-4 w-6 pl-1 sm:h-5 sm:w-10" src={AddGoogleIcon} /> | ||
<span className="text-sm sm:text-base">Continue with Google</span> | ||
</Link> | ||
|
||
<Link | ||
to={'/github-auth'} | ||
className="flex w-full items-center justify-center space-x-2 rounded-lg border-2 border-b-4 border-gray-300 p-3 text-center hover:bg-gray-50 md:w-3/4 lg:w-2/5" | ||
> | ||
<img className="h-4 w-6 sm:h-5 sm:w-10" src={AddGithubIcon} /> | ||
<span className="text-sm sm:text-base">Continue with Github</span> | ||
</Link> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default signin; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets make it signin, so that we are consistent to signup
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay.