File size: 5,788 Bytes
643fcf4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | import React, { useState } from "react";
// import { useNavigate } from "react-router-dom"; // Removed unused import
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
interface AuthFormProps {
view: "login" | "signup";
setView: React.Dispatch<React.SetStateAction<"login" | "signup">>;
}
const AuthForm: React.FC<AuthFormProps> = ({ view, setView }) => {
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [loading, setLoading] = useState(false);
const [err, setErr] = useState<string | null>(null);
const handleAuth = async (e: React.FormEvent) => {
e.preventDefault();
setLoading(true);
setErr(null);
if (!email || !password) {
setErr("Please enter email and password");
setLoading(false);
return;
}
// Removed Supabase authentication logic for UI review
// if (view === "login") {
// const { error } = await supabase.auth.signInWithPassword({ email, password });
// if (error) {
// setErr(
// error.message === "Invalid login credentials"
// ? "Invalid email or password."
// : error.message
// );
// } else {
// navigate("/");
// }
// } else {
// const { error } = await supabase.auth.signUp({
// email,
// password,
// options: { emailRedirectTo: window.location.origin + "/" },
// });
// if (error) {
// setErr(error.message);
// } else {
// setErr("Check your email for a confirmation link!");
// }
// }
setLoading(false);
};
return (
<>
<form onSubmit={handleAuth} className="space-y-4 mt-2">
<Input
autoFocus
type="email"
placeholder="Email"
value={email}
autoComplete="username"
onChange={(e: React.ChangeEvent<HTMLInputElement>) => setEmail(e.target.value)}
disabled={loading}
className="focus:ring-2 focus:ring-[#7f7fd5] focus:border-[#38f9d7]
bg-gradient-to-tr from-[#fff] via-[#38f9d7]/20 to-[#ffd200]/20
border-2 border-[#38f9d7]/50
text-[#19142a] dark:text-white
placeholder:text-muted-foreground font-semibold
transition-all shadow-lg shadow-[#38f9d7]/10
"
/>
<Input
type="password"
placeholder="Password"
value={password}
autoComplete={view === "login" ? "current-password" : "new-password"}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => setPassword(e.target.value)}
disabled={loading}
className="focus:ring-2 focus:ring-[#ffd200] focus:border-[#f7971e]
bg-gradient-to-br from-[#fff] via-[#38f9d7]/10 to-[#f7971e]/20
border-2 border-[#ffd200]/60
text-[#19142a] dark:text-white
placeholder:text-muted-foreground font-semibold
transition-all shadow-lg shadow-[#ffd200]/10
"
/>
{err && (
<p className="text-destructive text-base text-center font-semibold px-2" aria-live="polite">
{err}
</p>
)}
<Button
className="w-full mt-1 bg-gradient-to-r from-[#7f7fd5] via-[#38f9d7] to-[#f7971e] text-white font-bold shadow-md
hover:bg-gradient-to-br hover:from-[#f7971e] hover:via-[#38f9d7] hover:to-[#7f7fd5] transition-all duration-150"
variant="default"
type="submit"
disabled={loading}
>
{loading ? "Please wait..." : view === "login" ? "Sign In" : "Sign Up"}
</Button>
</form>
<div className="text-center text-base mt-2">
{view === "login" ? (
<>
<span className="text-slate-300 dark:text-slate-200">New here? </span>
<span
className="font-bold underline underline-offset-4 text-[#43e97b] bg-gradient-to-r from-[#ffd200] via-[#38f9d7] to-[#f7971e] bg-clip-text text-transparent
shadow-sm
hover:text-[#ffd200] hover:bg-none
focus:outline focus:outline-2 focus:outline-[#38f9d7]
cursor-pointer transition-all duration-150
px-1
"
onClick={() => { setView("signup"); setErr(null); }}
tabIndex={0}
role="button"
aria-label="Create an account"
onKeyDown={e => { if (e.key === "Enter" || e.key === " ") { setView("signup"); setErr(null); } }}
>
Create an account
</span>
</>
) : (
<>
<span className="text-slate-300 dark:text-slate-200">Already have an account? </span>
<span
className="font-bold underline underline-offset-4 text-[#38f9d7] bg-gradient-to-r from-[#f7971e] via-[#38f9d7] to-[#7f7fd5] bg-clip-text text-transparent
shadow-sm
hover:text-[#7f7fd5] hover:bg-none
focus:outline focus:outline-2 focus:outline-[#38f9d7]
cursor-pointer transition-all duration-150
px-1
"
onClick={() => { setView("login"); setErr(null); }}
tabIndex={0}
role="button"
aria-label="Sign in"
onKeyDown={e => { if (e.key === "Enter" || e.key === " ") { setView("login"); setErr(null); } }}
>
Sign in
</span>
</>
)}
</div>
</>
);
};
export default AuthForm; |