Skip to content
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
merged 25 commits into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
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 Apr 3, 2024
fc9065e
feat: Added zod for validation
0xmohitsen Apr 3, 2024
f65842a
feat: Installed react-hook-form + zod + @hookform/resolver
0xmohitsen Apr 3, 2024
7c855b2
feat: Added /user-auth route
0xmohitsen Apr 3, 2024
3d65cb5
feat: Added colors
0xmohitsen Apr 3, 2024
3fdc8f6
feat: Added signin-page
0xmohitsen Apr 3, 2024
4bf0483
feat: Correction in imported signin page name
0xmohitsen Apr 3, 2024
88e0863
feat: Added signin-page
0xmohitsen Apr 3, 2024
84720e3
feat: Added signin-page
0xmohitsen Apr 3, 2024
5b6f6bb
feat-#38: Added email validation check + reduced the width + made cha…
0xmohitsen Apr 4, 2024
a3d5010
feat-#38: Added email validation check + reduced the width + made cha…
0xmohitsen Apr 4, 2024
561825a
Merge branch 'krishnaacharyaa:main' into enhance/wanderLust
0xmohitsen Apr 5, 2024
6471e06
feat-#38: Removed hardcode css + removed unnecessary breakpoint prefi…
0xmohitsen Apr 5, 2024
31211c0
feat-#38: Configured for color
0xmohitsen Apr 5, 2024
007b3bd
feat-#38: Added signUp schema
0xmohitsen Apr 6, 2024
fee59e3
feat-#38: Removed hardcode values
0xmohitsen Apr 6, 2024
7efd726
feat-#38: Modified UI for mobile screen
0xmohitsen Apr 6, 2024
611e341
feat-#38: Modified UI for mobile screen
0xmohitsen Apr 6, 2024
4f75bbb
feat-#38: Executed npm run format
0xmohitsen Apr 6, 2024
f734270
feat-#38: Leveraged tailwind classes for colors + removed custom colors
0xmohitsen Apr 6, 2024
dc5ce21
feat-#38: Removed custom corner case
0xmohitsen Apr 6, 2024
b5b590a
feat-#38: Added signup page
0xmohitsen Apr 6, 2024
7312064
feat-#38: Refactored the auth-form layout code from auth pages + crea…
0xmohitsen Apr 7, 2024
7c67e72
Revert "feat-#38: Refactored the auth-form layout code from auth page…
0xmohitsen Apr 7, 2024
1d88d5b
feat-#38: Changed /user-auth route name to /signin route
0xmohitsen Apr 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@
"test": "jest"
},
"dependencies": {
"@hookform/resolvers": "^3.3.4",
"axios": "^1.6.1",
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
"lucide-react": "^0.292.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-hook-form": "^7.51.2",
"react-router-dom": "^6.18.0",
"react-tag-input": "^6.8.1",
"react-toastify": "^9.1.3",
"tailwind-merge": "^2.0.0",
"tailwindcss-animate": "^1.0.7"
"tailwindcss-animate": "^1.0.7",
"zod": "^3.22.4"
},
"devDependencies": {
"@babel/preset-env": "^7.23.6",
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import AddBlog from '@/pages/add-blog';
import DetailsPage from '@/pages/details-page';
import ScrollToTop from '@/components/scroll-to-top';
import Footer from '@/layouts/footer-layout';
import SignIn from '@/pages/signin-page';
import SignUp from '@/pages/signup-page';

function App() {
return (
Expand All @@ -15,6 +17,8 @@ function App() {
<Route index element={<HomePage />} />
<Route path="add-blog" element={<AddBlog />} />
<Route path="details-page/:title/:postId" element={<DetailsPage />} />
<Route path="user-auth" element={<SignIn />} />
Copy link
Owner

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay.

<Route path="signup" element={<SignUp />} />
</Route>
</Routes>
<Footer />
Expand Down
1 change: 1 addition & 0 deletions frontend/src/assets/svg/github-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions frontend/src/assets/svg/google-color-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion frontend/src/layouts/footer-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ function footer() {
const year = newDate.getFullYear();

return (
<footer className="flex min-h-[6vh] flex-col items-center bg-footer-background py-2 text-center text-white sm:flex-row sm:justify-between sm:py-3">
<footer className="flex min-h-[6vh] flex-col items-center bg-zinc-900 py-2 text-center text-white sm:flex-row sm:justify-between sm:py-3">
<section className="text-base sm:pl-4 md:pl-8 lg:pl-16">WanderLust</section>
<section className="text-base sm:pr-4 md:pr-16 lg:pr-24">
<span className="mr-2">&copy;</span>
Expand Down
37 changes: 37 additions & 0 deletions frontend/src/lib/types.ts
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>;
109 changes: 109 additions & 0 deletions frontend/src/pages/signin-page.tsx
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">
Copy link
Owner

Choose a reason for hiding this comment

The 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;
Loading