Skip to content

Commit

Permalink
Merge branch 'main' into bugfix/259-vertical-center-show-password-icon
Browse files Browse the repository at this point in the history
  • Loading branch information
hustlerZzZ authored Jun 9, 2024
2 parents 980d7f0 + 54e49d0 commit 998b5e9
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 21 deletions.
58 changes: 41 additions & 17 deletions src/pages/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@ function Login() {

async function submitHandler(event) {
event.preventDefault();
setLoading(true);

try {
const apiUrl =
formData.accountType === "User"
? `http://localhost:8000/api/v1/studentLogin`
: `http://localhost:8000/api/v1/canteenLogin`;
if (formData.accountType === "User") {
//Loader will show till the api fetching is done as show as promise is resolved the loader will be not shown
setLoading(true);

// const apiUrl = `${process.env.REACT_APP_BASE_URL}/studentLogin`;
const apiUrl = `http://localhost:3000/api/v1/studentLogin`;

const response = await axios.post(apiUrl, formData);

// Assuming the response contains a token
const token = response.data.token;
Expand All @@ -43,16 +42,34 @@ function Login() {
localStorage.setItem("canteenId", response.data.cantId);
if (formData.accountType === "User") {
toast.success("User logged in successfully!");

navigate("/home");
} else {
toast.success("Canteen logged in successfully!");
navigate(`/section/${response.data.cantId}`);
} catch (error) {
toast.error("Failed To Login. Please try again.");
console.error(error);
} finally {
setLoading(false);
}
} catch (error) {
toast.error("Failed to login. Please try again.");
console.error(error);
} finally {
setLoading(false);
}

else{
const apiUrl = `${process.env.REACT_APP_BASE_URL}/canteenLogin`;
setLoading(true);

axios
.post(apiUrl, formData)
.then((response) => {
setLoading(false);
toast.success("User Logged in ");
navigate(
`/section/${response.data.cantId}`
);
})
.catch((error) => {
//Loader will show till the api fetching is done as show as promise is resolved the loader will be not shown
setLoading(false);
toast.error("Failed to login");
});
}
}

Expand All @@ -64,9 +81,14 @@ function Login() {
<div className="h-screen md:flex">
<div className="relative overflow-hidden md:flex w-1/2 bg-gradient-to-t from-blue-950 via-blue-950 to-gray-900 bg-no-repeat justify-around items-center hidden">
<div>
<img src={logo} alt="logo" className="w-48 h-12 mb-2" />
<img
src={logo}
alt="logo"
className="w-48 h-12 mb-2"
/>
<p className="text-white mt-1 ml-3">
Connecting You to Your College Canteens
Connecting You to Your College
Canteens
</p>
</div>
<div className="absolute -bottom-32 -left-40 w-80 h-80 border-4 rounded-full border-opacity-30 border-t-8"></div>
Expand All @@ -78,8 +100,10 @@ function Login() {
<div className="flex md:w-1/2 justify-center py-10 items-center bg-white">
<form
className="bg-white p-8 rounded shadow-lg w-80"

onSubmit={submitHandler}
>

<h1 className="text-gray-800 font-bold text-2xl mb-1">
Hello Again!
</h1>
Expand Down
10 changes: 6 additions & 4 deletions src/pages/News.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ function News() {
Trending Food and Health News
</h1>
<main className="mt-24 p-4">
<div className="container grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4">
{articles.map((article, index) => (
<NewsCard key={index} article={article} />
))}
<div style={{display:"flex",justifyContent:"center"}}>
<div className="container grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-5 ">
{articles.map((article, index) => (
<NewsCard key={index} article={article} />
))}
</div>
</div>
</main>
<Footer />
Expand Down
2 changes: 2 additions & 0 deletions src/pages/Signup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ function Signup() {
lengthValidated
) {
if (formData.accountType === "User") {

// const apiUrl = `http://localhost:8000/api/v1/studentSignup`;
const apiUrl = `http://localhost:8000/api/v1/studentSignup`;
try {
Expand Down Expand Up @@ -122,6 +123,7 @@ function Signup() {
}
} else {
toast.error("Password must pass all the criteria");

}
}

Expand Down

0 comments on commit 998b5e9

Please sign in to comment.