Skip to content

Commit e7005ed

Browse files
author
Aishwarya Nair
committed
add error handling for user login and sign up and css animations
1 parent 3cad0c5 commit e7005ed

File tree

4 files changed

+123
-50
lines changed

4 files changed

+123
-50
lines changed

Frontend/src/Components/LoginSignUp/Login.jsx

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,32 @@ import user_icon from "../Assets/user.png";
99
import {loginUser} from "../../User/UserServiceAPI";
1010
import {resetUserPasswordUsingFirebase} from "../../Authentication/UserAuthenticationController";
1111

12-
export const Login = ({setAction}) => {
12+
const MISSING_FIELD_ERROR_MESSAGE = "Please fill all fields!";
13+
14+
export const Login = ({setAction, setError}) => {
1315
const navigate = useNavigate();
1416

1517
const [userEmail, setUserEmail] = useState("");
1618
const [userPassword, setUserPassword] = useState("");
1719

20+
const isEmpty = (str) => {
21+
return str === "";
22+
};
23+
24+
const handleSubmit = async () => {
25+
if (isEmpty(userEmail) || isEmpty(userPassword)) {
26+
setError(MISSING_FIELD_ERROR_MESSAGE);
27+
} else {
28+
const result = await loginUser(userEmail, userPassword);
29+
if (result) {
30+
navigate("/landing");
31+
setError("");
32+
} else {
33+
setError("Invalid credentials. Please try again.");
34+
}
35+
}
36+
};
37+
1838
return (
1939
<div className="login-container">
2040
<div className="inputs">
@@ -46,30 +66,32 @@ export const Login = ({setAction}) => {
4666
</div>
4767
</div>
4868
<div className="forgot-password">
49-
{" "}
50-
Forgot Password?{" "}
69+
Forgot Password?
5170
<span onClick={() => resetUserPasswordUsingFirebase(userEmail)}>
52-
{" "}
5371
Click Here.
5472
</span>
5573
</div>
5674
<div className="submit-container">
5775
<div
5876
className="submit"
59-
onClick={async () => {
60-
const result = await loginUser(userEmail, userPassword);
61-
if (result) {
62-
navigate("/landing");
63-
}
77+
onClick={(e) => {
78+
handleSubmit();
6479
}}
6580
>
6681
Log In
6782
</div>
6883
</div>
6984
<div className="signup-nav">
70-
{" "}
71-
Don't have an account?{" "}
72-
<span onClick={() => setAction("Sign Up")}> Sign Up.</span>
85+
Don't have an account?
86+
<span
87+
onClick={() => {
88+
setError("");
89+
setAction("Sign Up");
90+
}}
91+
>
92+
{" "}
93+
Sign Up.
94+
</span>
7395
</div>
7496
</div>
7597
);

Frontend/src/Components/LoginSignUp/LoginSignUp.css

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
}
3737

3838
.inputs {
39-
margin-top: 55px;
39+
/* margin-top: 55px; */
4040
display: flex;
4141
flex-direction: column;
4242
gap: 25px;
@@ -74,13 +74,19 @@
7474
/* margin-top: 27px; */
7575
color: #797979;
7676
font-size: 18px;
77+
display: flex;
78+
gap: 5px;
7779
}
7880

7981
.forgot-password span {
8082
color: #52cc65;
8183
cursor: pointer;
8284
}
8385

86+
.forgot-password span:hover {
87+
color: #4cbd5d;
88+
}
89+
8490
.submit-container {
8591
display: flex;
8692
gap: 30px;
@@ -101,6 +107,11 @@
101107
cursor: pointer;
102108
}
103109

110+
.submit:hover {
111+
box-shadow: rgba(100, 100, 111, 0.2) 0px 7px 29px 0px;
112+
background: #4cbd5d;
113+
}
114+
104115
.gray {
105116
background: #e9e9e9;
106117
color: #676767;
@@ -121,9 +132,23 @@
121132
cursor: pointer;
122133
}
123134

135+
.signup-nav span:hover,
136+
.login-nav span:hover {
137+
color: #0d489b;
138+
cursor: pointer;
139+
}
140+
124141
.login-container,
125142
.signup-container {
143+
margin-top: 30px;
126144
display: flex;
127145
flex-direction: column;
128146
gap: 20px;
129147
}
148+
149+
.login-signup-error {
150+
margin-top: 30px;
151+
color: red;
152+
padding-left: 95px;
153+
font-size: 18px;
154+
}
Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
1-
import React from 'react'
2-
import './LoginSignUp.css'
3-
import {useState} from 'react'
4-
import { useNavigate } from "react-router-dom";
1+
import React from "react";
2+
import "./LoginSignUp.css";
3+
import {useState} from "react";
4+
import {useNavigate} from "react-router-dom";
55

6-
import { Login } from './Login';
7-
import { SignUp } from './SignUp';
6+
import {Login} from "./Login";
7+
import {SignUp} from "./SignUp";
88

99
export const LoginSignUp = () => {
10-
11-
const [action, setAction] = useState("Log In");
12-
13-
return (
14-
<div className="container-loginsignup">
15-
<div className="header">
16-
<div className="text"> {action} </div>
17-
<div className="underline"></div>
18-
</div>
19-
{action === "Log In"? <Login setAction={setAction}/>: <SignUp setAction={setAction}/>}
20-
21-
</div>
22-
)
23-
}
24-
10+
const [action, setAction] = useState("Log In");
11+
const [error, setError] = useState("");
2512

13+
return (
14+
<div className="container-loginsignup">
15+
<div className="header">
16+
<div className="text"> {action} </div>
17+
<div className="underline"></div>
18+
</div>
19+
<div className="login-signup-error">{error}</div>
20+
{action === "Log In" ? (
21+
<Login setAction={setAction} setError={setError} />
22+
) : (
23+
<SignUp setAction={setAction} setError={setError} />
24+
)}
25+
</div>
26+
);
27+
};

Frontend/src/Components/LoginSignUp/SignUp.jsx

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,41 @@ import user_icon from "../Assets/user.png";
88

99
import {registerUser} from "../../User/UserServiceAPI";
1010

11-
export const SignUp = ({setAction}) => {
11+
const MISSING_FIELD_ERROR_MESSAGE = "Please fill all fields!";
12+
13+
export const SignUp = ({setAction, setError}) => {
1214
const navigate = useNavigate();
1315

1416
const [userEmail, setUserEmail] = useState("");
1517
const [userPassword, setUserPassword] = useState("");
1618
const [userName, setUserName] = useState("");
1719
const [preferredLang, setPreferredLang] = useState("");
1820

21+
const isEmpty = (str) => {
22+
return str === "";
23+
};
24+
25+
const handleSubmit = async () => {
26+
if (isEmpty(userEmail) || isEmpty(userPassword) || isEmpty(userName)) {
27+
setError(MISSING_FIELD_ERROR_MESSAGE);
28+
} else {
29+
const result = await registerUser(
30+
userName,
31+
userEmail,
32+
userPassword,
33+
"GitHub ID Placeholder",
34+
preferredLang
35+
);
36+
37+
if (result.success) {
38+
navigate("/landing");
39+
} else {
40+
console.log(result);
41+
setError(result.message);
42+
}
43+
}
44+
};
45+
1946
return (
2047
<div className="signup-container">
2148
<div className="inputs">
@@ -70,27 +97,24 @@ export const SignUp = ({setAction}) => {
7097
<div className="submit-container">
7198
<div
7299
className="submit"
73-
onClick={async () => {
74-
const result = await registerUser(
75-
userName,
76-
userEmail,
77-
userPassword,
78-
"GitHub ID Placeholder",
79-
preferredLang
80-
);
81-
82-
if (result) {
83-
navigate("/landing");
84-
}
100+
onClick={(e) => {
101+
handleSubmit();
85102
}}
86103
>
87104
Sign Up
88105
</div>
89106
</div>
90107
<div className="login-nav">
91-
{" "}
92-
Already have an account?{" "}
93-
<span onClick={() => setAction("Log In")}> Log In.</span>
108+
Already have an account?
109+
<span
110+
onClick={() => {
111+
setError("");
112+
setAction("Log In");
113+
}}
114+
>
115+
{" "}
116+
Log In.
117+
</span>
94118
</div>
95119
</div>
96120
);

0 commit comments

Comments
 (0)