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

Login/Register Page UI updated #331

Merged
merged 1 commit into from
Jan 18, 2025
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
286 changes: 80 additions & 206 deletions src/Pages/Register.js
Original file line number Diff line number Diff line change
@@ -1,211 +1,85 @@
import React, { useState } from "react";
import styled from "styled-components";
import { motion } from "framer-motion";
import { Link, useNavigate } from "react-router-dom";
import { useDispatch } from "react-redux";
import { login } from "../Store/authSlice";

const RegisterBackGround = styled.section`
background-image: url("https://img.freepik.com/free-photo/hot-latte-art-coffee-cup-wood-table-coffee-shop_1150-8937.jpg");
background-size: cover;
background-position: center;
height: 100vh;
`;

const RegisterContainer = styled.div`
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
padding: 0 1rem;
backdrop-filter: blur(8px);
background: rgba(0, 0, 0, 0.6);
`;

const RegisterForm = styled(motion.form)`
background-color: rgba(255, 255, 255, 0.9);
padding: 2.5rem;
border-radius: 12px;
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
width: 350px;
max-width: 90%;
text-align: center;
opacity: 1;
transition: opacity 0.6s ease-in-out;
`;

const Heading = styled.h2`
margin-bottom: 1.5rem;
color: #7c2214;
font-size: 1.8rem;
font-weight: bold;
`;

const Input = styled(motion.input)`
width: 100%;
padding: 0.8rem;
margin-bottom: 1.2rem;
border: 1px solid #ddd;
border-radius: 8px;
font-size: 1rem;
transition: all 0.3s ease;

&:focus {
border-color: #7c2214;
outline: none;
box-shadow: 0 0 5px rgba(124, 34, 20, 0.5);
}
&:hover {
border-color: #aaa;
}
`;

const Button = styled(motion.button)`
width: 100%;
padding: 0.8rem;
background-color: #7c2214;
color: white;
border: none;
border-radius: 8px;
font-size: 1rem;
font-weight: bold;
cursor: pointer;
transition: background-color 0.3s;

&:hover {
background-color: #5b190f;
}
`;

const LoginLink = styled(Link)`
display: block;
margin-top: 1.5rem;
font-size: 0.9rem;
color: #7c2214;
text-decoration: underline;

&:hover {
text-decoration: none;
color: #5b190f;
}
`;

const SuccessMessage = styled.div`
margin-top: 1.5rem;
color: green;
text-align: center;
font-weight: bold;
`;

const ErrorMessage = styled.div`
margin-top: 1.5rem;
color: red;
text-align: center;
font-weight: bold;
`;

const Register = () => {
const [formData, setFormData] = useState({
username: "",
email: "",
password: "",
confirmPassword: "",
});

const [isSubmitted, setIsSubmitted] = useState(false);
const [error, setError] = useState("");
const dispatch = useDispatch();
const navigate = useNavigate();

const handleChange = (e) => {
const { name, value } = e.target;
setFormData({
...formData,
[name]: value,
});
};

const handleSubmit = (e) => {
e.preventDefault();
if(formData.password.length < 9){
setError("Password must have a minimum of 8 characters");
return;
}
else if (formData.password !== formData.confirmPassword) {
setError("Passwords do not match");
return;
}
localStorage.setItem("user", JSON.stringify(formData));
dispatch(login({ username: formData.username, email: formData.email }));
setIsSubmitted(true);
setError("");
setTimeout(() => {
navigate("/");
}, 2000);
};
import React from "react";

function SignupPage() {
return (
<RegisterBackGround>
<RegisterContainer>
<RegisterForm
initial={{ opacity: 0, y: 50 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.6 }}
onSubmit={handleSubmit}
>
<Heading>Register</Heading>
<Input
type="text"
name="username"
placeholder="Username"
value={formData.username}
onChange={handleChange}
required
whileFocus={{ scale: 1.03 }}
/>
<Input
type="email"
name="email"
placeholder="Email"
value={formData.email}
onChange={handleChange}
required
whileFocus={{ scale: 1.03 }}
/>
<Input
type="password"
name="password"
placeholder="Password"
value={formData.password}
onChange={handleChange}
required
whileFocus={{ scale: 1.03 }}
/>
<Input
type="password"
name="confirmPassword"
placeholder="Confirm Password"
value={formData.confirmPassword}
onChange={handleChange}
required
whileFocus={{ scale: 1.03 }}
<div className="flex items-center justify-center h-screen bg-gray-100">
<div className="bg-[#D2B48C] rounded-lg shadow-lg overflow-hidden w-[900px] h-[500px] flex">
{/* Left Side: Image */}
<div className="w-1/2">
<img
src="https://www.shutterstock.com/image-photo/assorted-iced-coffee-on-white-600nw-2480796893.jpg"
alt="Coffee"
className="w-full h-full object-cover"
/>
<Button
type="submit"
whileHover={{ scale: 1.05 }}
whileTap={{ scale: 0.95 }}
>
Register
</Button>
{error && <ErrorMessage>{error}</ErrorMessage>}
{isSubmitted && (
<SuccessMessage>Registration successful!</SuccessMessage>
)}
<LoginLink to="/login">Already have an account? Login</LoginLink>
</RegisterForm>
</RegisterContainer>
</RegisterBackGround>
</div>
{/* Right Side: Signup Form */}
<div className="w-1/2 p-10 flex flex-col justify-center bg-white">
<h2 className="text-3xl font-bold text-[#4E342E] text-center mb-6">
Create an Account
</h2>
<form>
<div className="mb-4">
<label
className="block text-gray-700 font-medium mb-2"
htmlFor="name"
>
Full Name
</label>
<input
type="text"
id="name"
placeholder="Enter your name"
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-[#6D4C41]"
/>
</div>
<div className="mb-4">
<label
className="block text-gray-700 font-medium mb-2"
htmlFor="email"
>
Email Address
</label>
<input
type="email"
id="email"
placeholder="Enter your email"
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-[#6D4C41]"
/>
</div>
<div className="mb-4">
<label
className="block text-gray-700 font-medium mb-2"
htmlFor="password"
>
Password
</label>
<input
type="password"
id="password"
placeholder="Enter your password"
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-[#6D4C41]"
/>
</div>
<button
type="submit"
className="w-full bg-[#4E342E] text-white py-2 px-4 rounded-lg hover:bg-[#3E2723] transition duration-300"
>
Sign Up
</button>
</form>
<p className="text-sm text-gray-600 text-center mt-6">
Already have an account?{" "}
<a
href="/login"
className="text-[#6D4C41] font-medium hover:underline"
>
Log In
</a>
</p>
</div>
</div>
</div>
);
};
}

export default Register;
export default SignupPage;
Loading
Loading