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 11 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
2 changes: 2 additions & 0 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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';

function App() {
return (
Expand All @@ -15,6 +16,7 @@ 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/>} />
</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.
10 changes: 10 additions & 0 deletions frontend/src/lib/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
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 type TSignInSchema = z.infer<typeof signInSchema>;
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="flex-grow cursor-default bg-white px-5 py-9 mt-1">
<div className="mb-4 flex justify-center">
<div className="flex items-center justify-center space-x-4 w-5/6 md:w-5/6 lg:w-2/5">
<h2 className="text-center text-2xl sm:text-3xl md:text-4xl lg:text-2xl xl:text-3xl 2xl:text-4xl font-bold text-black w-3/4">
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="flex flex-col justify-center items-center mt-12 gap-4">
<form onSubmit={handleSubmit(onSubmit)} className="w-3/4 md:w-5/6 lg:w-2/5">

<div className="mb-4">
<input
{...register('email')}
type="email"
placeholder="Email"
className="w-full rounded-lg font-semibold bg-input-background p-3 placeholder:text-sm placeholder:text-light-gray"
// value={formData.title}
// onChange={handleInputChange}
/>
{errors.email && (
<p className="text-red-500 text-xs p-2">
{`${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 font-semibold bg-input-background p-3 placeholder:text-sm placeholder:text-light-gray"
// value={formData.description}
// onChange={handleInputChange}
/>
{errors.password && (
<p className="text-red-500 text-xs p-2">
{`${errors.password.message}`}
</p>
)}
</div>

<button
disabled={isSubmitting}
type="submit"
className="flex disabled:bg-[#3C3C3C] w-full items-center justify-center rounded-lg bg-login-background p-3 text-base font-semibold text-light md:fit"
>
krishnaacharyaa marked this conversation as resolved.
Show resolved Hide resolved
Log In
</button>
</form>
<div className='flex flex-col items-center justify-center gap-4 text-center'>
<p className='w-3/4 sm:w-full'> 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 items-center justify-center p-3 space-x-2 rounded-lg border-2 border-b-4 border-gray-300 w-3/4 md:w-5/6 lg:w-2/5 hover:bg-light-white text-center'>
<img className='h-4 w-6 sm:h-5 sm:w-10' src={AddGoogleIcon}/>
<span className='font-bold'>Continue with Google</span>
</Link>

<Link to={'/github-auth'} className='flex items-center justify-center p-3 space-x-2 rounded-lg border-2 border-b-4 border-gray-300 w-3/4 md:w-5/6 lg:w-2/5 hover:bg-light-white text-center'>
<img className='h-4 w-6 sm:h-5 sm:w-10' src={AddGithubIcon}/>
<span className='font-bold'>Continue with Github</span>
</Link>

</div>
</div>
);
}

export default signin;
4 changes: 4 additions & 0 deletions frontend/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export default {
'dark-theme-background': '#092e40',
'dark-theme-foreground': '#25a5e3',
'footer-background': '#181818',
'login-background': '#232323',
'input-background': '#F8F8F8',
'light-gray': '#686868',
'light-white': '#f9fafb',
},
krishnaacharyaa marked this conversation as resolved.
Show resolved Hide resolved
fontFamily: {
sans: ['Poppins', ...defaultTheme.fontFamily.sans],
Expand Down