Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 5 additions & 13 deletions client/package-lock.json

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

30 changes: 22 additions & 8 deletions client/src/components/Login.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState } from "react";
import { useNavigate } from "react-router-dom";
import { useAuth } from "../middleware/AuthContext";
import { FaUserCircle } from "react-icons/fa";
import { FaUserCircle, FaEye, FaEyeSlash } from "react-icons/fa";
import { FaSpinner } from "react-icons/fa";

const InputField = ({ label, type, name, value, onChange, error, placeholder }) => (
Expand All @@ -26,7 +26,7 @@ const InputField = ({ label, type, name, value, onChange, error, placeholder })
const Login = () => {
const navigate = useNavigate();
const { login } = useAuth();

const [formData, setFormData] = useState({
email: "",
password: "",
Expand All @@ -39,7 +39,12 @@ const Login = () => {
general: "",
});

const [showPassword, setShowPassword] = useState(false);

const [isLoading, setIsLoading] = useState(false);
const handlePassword = () => {
setShowPassword(!showPassword);
};

const handleInputChange = (e) => {
const { name, value, type, checked } = e.target;
Expand Down Expand Up @@ -83,7 +88,7 @@ const Login = () => {
});

const data = await response.json();

if (response.ok) {
login(data.user, data.token);
setFormData({ email: "", password: "", rememberMe: false });
Expand Down Expand Up @@ -113,7 +118,7 @@ const Login = () => {
<FaUserCircle className="text-[80px] text-gray-500 mb-[10px] mx-auto" />
<h2 className="text-[1.8rem] font-bold text-[#333]">MCA Alumni</h2>
</div>

{error.general && <div className="text-red-500 text-center">{error.general}</div>}

<form onSubmit={handleLogin}>
Expand All @@ -128,13 +133,23 @@ const Login = () => {
/>
<InputField
label="PASSWORD"
type="password"
type={showPassword ? "text" : "password"}
name="password"
value={formData.password}
onChange={handleInputChange}
error={error.password}
placeholder="Enter Your Password"
/>
<div
className="relative top-[-52px] left-[265px] cursor-pointer"
onClick={handlePassword}
>
{showPassword ? (
<FaEyeSlash className="text-gray-500" />
) : (
<FaEye className="text-gray-500" />
)}
</div>

<div className="flex items-center mb-[20px] text-left">
<input
Expand All @@ -152,9 +167,8 @@ const Login = () => {

<button
type="submit"
className={`w-full p-[12px] border-none rounded-[30px] bg-[#e0e5ec] shadow-[8px_8px_16px_#b3b9c5,-8px_-8px_16px_#ffffff] text-[#333] text-[1rem] font-bold cursor-pointer transition-all duration-300 ease-in-out hover:bg-[#d1d9e6] ${
isLoading ? "opacity-70 cursor-not-allowed" : ""
}`}
className={`w-full p-[12px] border-none rounded-[30px] bg-[#e0e5ec] shadow-[8px_8px_16px_#b3b9c5,-8px_-8px_16px_#ffffff] text-[#333] text-[1rem] font-bold cursor-pointer transition-all duration-300 ease-in-out hover:bg-[#d1d9e6] ${isLoading ? "opacity-70 cursor-not-allowed" : ""
}`}
disabled={isLoading}
>
{isLoading ? <FaSpinner className="animate-spin mx-auto" /> : "LOGIN"}
Expand Down