|
| 1 | +import React, { useState, } from "react"; |
| 2 | +import { Eye, EyeOff, Lock } from "lucide-react"; |
| 3 | +import BackButton from "./BackButton"; |
| 4 | +import { SignInStep } from "@/lib/types"; |
| 5 | + |
| 6 | + |
| 7 | +interface EmailSignInStepProps { |
| 8 | + onBack: () => void; |
| 9 | + onStepChange: (step: SignInStep) => void; |
| 10 | +} |
| 11 | + |
| 12 | +const emailRegex = /^[\w-.]+@([\w-]+\.)+[\w-]{2,}$/i; |
| 13 | + |
| 14 | +export default function EmailSignInStep({ |
| 15 | + onBack, |
| 16 | + onStepChange, |
| 17 | +}: EmailSignInStepProps) { |
| 18 | + const [showPassword, setShowPassword] = useState(false); |
| 19 | + const [email, setEmail] = useState(""); |
| 20 | + const [password, setPassword] = useState(""); |
| 21 | + const [emailError, setEmailError] = useState(""); |
| 22 | + |
| 23 | + const handleEmailChange = (e: React.ChangeEvent<HTMLInputElement>) => { |
| 24 | + const value = e.target.value; |
| 25 | + setEmail(value); |
| 26 | + if (value.length === 0 || emailRegex.test(value)) { |
| 27 | + setEmailError(""); |
| 28 | + } else { |
| 29 | + setEmailError("Please enter a valid email address"); |
| 30 | + } |
| 31 | + }; |
| 32 | + |
| 33 | + const handleSubmit = (e: React.FormEvent) => { |
| 34 | + e.preventDefault(); |
| 35 | + if (!emailRegex.test(email)) { |
| 36 | + setEmailError("Please enter a valid email address"); |
| 37 | + return; |
| 38 | + } else { |
| 39 | + setEmailError(""); |
| 40 | + onStepChange("success"); |
| 41 | + } |
| 42 | + }; |
| 43 | + |
| 44 | + return ( |
| 45 | + <div className="min-h-screen flex items-center justify-center bg-gray-100 font-inter"> |
| 46 | + <div className="bg-white rounded-xl shadow-md p-6 w-full max-w-xl"> |
| 47 | + <BackButton onBack={onBack} /> |
| 48 | + |
| 49 | + <h2 className="text-2xl font-inter font-semibold text-[#5D5D5D] mb-1"> |
| 50 | + Welcome Back |
| 51 | + </h2> |
| 52 | + <p className="text-[#5D5D5D] text-base font-inter mb-8"> |
| 53 | + Enter your registered email address and password |
| 54 | + </p> |
| 55 | + |
| 56 | + <form className="flex flex-col gap-6" onSubmit={handleSubmit}> |
| 57 | + <div> |
| 58 | + <label |
| 59 | + className="block text-[#5D5D5D] text-base font-inter mb-2" |
| 60 | + htmlFor="email" |
| 61 | + > |
| 62 | + Email Address |
| 63 | + </label> |
| 64 | + <input |
| 65 | + id="email" |
| 66 | + type="email" |
| 67 | + className="rounded-md border border-gray-300 py-2 w-full px-5 focus:outline-none focus:ring-2 focus:ring-blue-100 placeholder:text-[#B0B0B0] font-normal text-base h-[50px]" |
| 68 | + placeholder="Enter Email address" |
| 69 | + value={email} |
| 70 | + onChange={handleEmailChange} |
| 71 | + autoComplete="email" |
| 72 | + /> |
| 73 | + {emailError && ( |
| 74 | + <p className="text-base text-red-500 mt-1">{emailError}</p> |
| 75 | + )} |
| 76 | + </div> |
| 77 | + |
| 78 | + <div> |
| 79 | + <div className="flex items-center justify-between mb-1"> |
| 80 | + <label |
| 81 | + className="block text-[#5D5D5D] text-base font-inter" |
| 82 | + htmlFor="password" |
| 83 | + > |
| 84 | + Password |
| 85 | + </label> |
| 86 | + <a |
| 87 | + href="#" |
| 88 | + className="text-[#096CFF] text-base font-inter hover:underline" |
| 89 | + > |
| 90 | + Forgot Password? |
| 91 | + </a> |
| 92 | + </div> |
| 93 | + <div className="relative"> |
| 94 | + <span className="absolute left-3 top-1/2 -translate-y-1/2"> |
| 95 | + <Lock className="w-4 h-4 text-gray-400" /> |
| 96 | + </span> |
| 97 | + <input |
| 98 | + id="password" |
| 99 | + type={showPassword ? "text" : "password"} |
| 100 | + className="rounded-md border border-gray-300 px-3 py-2 w-full pl-10 pr-10 focus:outline-none focus:ring-2 focus:ring-blue-100 placeholder:text-[#B0B0B0] font-normal text-base h-[50px]" |
| 101 | + placeholder="Enter Password" |
| 102 | + value={password} |
| 103 | + onChange={(e) => setPassword(e.target.value)} |
| 104 | + autoComplete="current-password" |
| 105 | + /> |
| 106 | + <button |
| 107 | + type="button" |
| 108 | + onClick={() => setShowPassword(!showPassword)} |
| 109 | + className="absolute right-3 top-1/2 -translate-y-1/2" |
| 110 | + > |
| 111 | + {showPassword ? ( |
| 112 | + <EyeOff className="w-4 h-4 text-gray-400" /> |
| 113 | + ) : ( |
| 114 | + <Eye className="w-4 h-4 text-gray-400" /> |
| 115 | + )} |
| 116 | + </button> |
| 117 | + </div> |
| 118 | + </div> |
| 119 | + |
| 120 | + <button |
| 121 | + type="submit" |
| 122 | + className="w-full bg-[#096CFF] text-white py-3 px-4 rounded-md font-inter font-medium text-base hover:bg-blue-700 transition-colors h-[50px]" |
| 123 | + > |
| 124 | + Sign In |
| 125 | + </button> |
| 126 | + </form> |
| 127 | + </div> |
| 128 | + </div> |
| 129 | + ); |
| 130 | +} |
0 commit comments