Zuma32

Login Page

Aug 7th, 2025
560
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 4.81 KB | Source Code | 0 0
  1. import { useState } from "react";
  2. import { useAuth } from "./authContext";
  3. import { useNavigate } from "react-router-dom";
  4. import { Link } from "react-router-dom";
  5. import { Ambulance } from "lucide-react";
  6. import { womanWithAmbulane } from "../assets/images/imageIdex";
  7.  
  8. function LoginForm() {
  9.     const {login, loading} = useAuth();
  10.     const navigate = useNavigate();
  11.  
  12.     const [username, setUsername] = useState("");
  13.     const [password, setPassword] = useState("");
  14.    
  15.     const handleSubmit = async (e) => {
  16.         e.preventDefault();
  17.         try {
  18.             await login(username, password);
  19.             navigate("/");
  20.         } catch (err) {
  21.             console.error("Login failed", err);
  22.         }
  23.     };
  24.    
  25.     return (
  26.         <div className="min-h-screen w-full flex items-center justify-end bg-gradient-to-br from-gray-900 via-gray-800 to-gray-700 relative overflow-hidden">
  27.             {/* Background image for the whole page */}
  28.             <img
  29.                 src={womanWithAmbulane}
  30.                 alt="Ambulance background"
  31.                 className="absolute left-0 top-0 h-full w-2/3 object-cover opacity-40 pointer-events-none select-none z-0"
  32.             />
  33.             {/* Animated text on the far left */}
  34.             <div className="absolute left-0 top-0 h-full w-2/3 flex items-center z-10">
  35.                 <div className="pl-16 max-w-xl">
  36.                     <h2 className="text-4xl md:text-5xl font-extrabold text-white drop-shadow-lg animate-fade-in-left" style={{animation: 'fadeInLeft 1.2s ease'}}>Fast. Reliable.<br/>Life-saving Ambulance Service.</h2>
  37.                     <style>{`
  38.                         @keyframes fadeInLeft {
  39.                             0% { opacity: 0; transform: translateX(-40px); }
  40.                             100% { opacity: 1; transform: translateX(0); }
  41.                         }
  42.                         .animate-fade-in-left {
  43.                             animation: fadeInLeft 1.2s ease;
  44.                         }
  45.                     `}</style>
  46.                 </div>
  47.             </div>
  48.             <div className="w-full max-w-md bg-gray-800 bg-opacity-95 rounded-2xl shadow-2xl p-8 m-12 relative z-10 flex flex-col items-center">
  49.                 {/* Ambulance icon on the card */}
  50.                 <Ambulance className="w-16 h-16 text-red-500 drop-shadow-lg mb-2" />
  51.                 <h1 className="text-3xl font-bold text-white mb-6 tracking-wide">AmbuCare</h1>
  52.                 <p className="text-2xl text-red-400 text-center font-semibold mb-6">Login</p>
  53.                 <form onSubmit={handleSubmit} className="space-y-6 w-full">
  54.                     <div>
  55.                         <label htmlFor="email" className="block text-sm font-medium text-gray-300 mb-1">
  56.                             Email
  57.                         </label>
  58.                         <input
  59.                             id="email"
  60.                             value={username}
  61.                             onChange={(e) => setUsername(e.target.value)}
  62.                             type="email"
  63.                             className="w-full px-4 py-2 bg-gray-700 text-white border border-gray-600 rounded-lg focus:outline-none focus:ring-2 focus:ring-red-400 focus:border-red-400 placeholder-gray-400"
  64.                             placeholder="Enter your email"
  65.                         />
  66.                     </div>
  67.                     <div>
  68.                         <label htmlFor="password" className="block text-sm font-medium text-gray-300 mb-1">
  69.                             Password
  70.                         </label>
  71.                         <input
  72.                             id="password"
  73.                             value={password}
  74.                             onChange={(e) => setPassword(e.target.value)}
  75.                             type="password"
  76.                             className="w-full px-4 py-2 bg-gray-700 text-white border border-gray-600 rounded-lg focus:outline-none focus:ring-2 focus:ring-red-400 focus:border-red-400 placeholder-gray-400"
  77.                             placeholder="Enter your password"
  78.                         />
  79.                     </div>
  80.                     <button
  81.                         type="submit"
  82.                         disabled={loading}
  83.                         className="w-full bg-red-500 hover:bg-red-600 text-white py-2 px-4 rounded-lg font-semibold transition-colors disabled:opacity-50 shadow-md"
  84.                     >
  85.                         {loading ? <div className="w-5 h-5 bg-white rounded-full animate-pulse mx-auto"></div> : "Login"}
  86.                     </button>
  87.                 </form>
  88.                 <p className="text-center text-gray-400 mt-6">Don't have an account? <Link to='/signup/' className="text-red-300 hover:underline">Sign up</Link></p>
  89.            </div>
  90.        </div>
  91.    )
  92. }
  93.  
  94. export default LoginForm;
Advertisement
Add Comment
Please, Sign In to add comment