Skip to content

Commit

Permalink
Merge branch 'VanshKing30:main' into FloatBtnFeat
Browse files Browse the repository at this point in the history
  • Loading branch information
Asymtode712 authored Jun 11, 2024
2 parents d961ce4 + c029236 commit 864a943
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 48 deletions.
2 changes: 1 addition & 1 deletion src/components/Footer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const Footer = () => {
window.scrollTo(0, 0);
};
return (
<div className='bg-blue-950 text-white p-10'>
<div className="text-white p-3 font-semibold shadow-lg bg-gradient-to-t from-blue-950 via-blue-950 to-gray-900 w-full z-40 dark:bg-cadetblue dark:bg-none">
<div className='md:flex'>
<div className='md:w-1/2 flex mb-8 md:mb-0 items-top'>
<img src="https://foodies-web-app.vercel.app/static/media/logo2.db6bd5028bb56c6572c7.png" alt="" className='h-16 w-48'/>
Expand Down
58 changes: 13 additions & 45 deletions src/pages/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,57 +33,27 @@ function Login() {
: `${process.env.REACT_APP_BASE_URL}/canteenLogin`;


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


// Assuming the response contains a token
const token = response.data.token;
try {
const response = await axios.post(apiUrl, formData);
const { token, cantId } = response.data;


localStorage.setItem("token", token);
localStorage.setItem("canteenId", cantId);

if (formData.accountType === "User") {
toast.success("User logged in successfully!");
navigate("/home");
} else {
toast.success("User Logged in ");
toast.success("User Logged in");
navigate(`/section/${cantId}`);
}
}

else{
const apiUrl = `${process.env.REACT_APP_BASE_URL}/canteenLogin`;
// const apiUrl = `http://localhost:4000/api/v1/canteenLogin`;
setLoading(true);

axios
.post(apiUrl, formData)
.then((response) => {
setLoading(false);
localStorage.setItem("canteenId", response.data.cantId);
localStorage.setItem("token", response.data.token);
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");
});

} catch (error) {
toast.error("Failed To Login. Please try again.");
console.error(error);
const errorMessage = error.response?.data?.message || "Failed to login. Please try again.";
toast.error(errorMessage);
} finally {
setLoading(false);

}
}

Expand Down Expand Up @@ -148,7 +118,7 @@ function Login() {

<div className="relative mb-4">
<input
required
required
className="w-full py-2 px-3 border border-gray-300 rounded-2xl"
type={showPassword ? "text" : "password"}
placeholder="Password"
Expand All @@ -167,13 +137,11 @@ function Login() {
)}
</span>
</div>
<div className="mb-4 flex justify-end text-red-400">
<Link to="/forgotPassword">
<h1 classname="font-medium">
Forogt Password ?
</h1>
</Link>
</div>
<div className="mb-4 flex justify-end text-red-400">
<Link to="/forgotPassword">
<h1 className="font-medium">Forgot Password ?</h1>
</Link>
</div>

<button
type="submit"
Expand All @@ -184,7 +152,7 @@ function Login() {
</button>

<Link to="/signup">
<span className="text-sm hover:text-blue-500 cursor-pointer">
<span className="text-sm hover:text-blue-500 cursor-pointer">
Don't have an account? Sign Up
</span>
</Link>
Expand All @@ -196,4 +164,4 @@ function Login() {
);
}

export default Login;
export default Login;
6 changes: 4 additions & 2 deletions src/pages/Signup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ function Signup() {

// const apiUrl = `${process.env.REACT_APP_BASE_URL}/studentSignup`;
const apiUrl = `${process.env.REACT_APP_BASE_URL}/studentSignup`;
// const apiUrl = `http://localhost:8000/api/v1/studentSignUp`;
try {

setLoading(true);
Expand All @@ -97,8 +98,9 @@ function Signup() {
toast.success("Account Created Successfully!");
navigate("/home");
} catch (error) {
toast.error("Failed To Create Account. Please try again.");
console.error(error);
const errorMessage = error.response?.data?.message || "Failed to login. Please try again.";
toast.error(errorMessage);
console.log("This is our error ", error);
} finally {
setLoading(false);
}
Expand Down

0 comments on commit 864a943

Please sign in to comment.