Spaces:
Sleeping
Sleeping
File size: 14,402 Bytes
5463318 | 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 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | import React, { useState } from "react";
import { Link, useNavigate } from "react-router-dom";
import { motion, AnimatePresence } from "framer-motion";
import { User, Mail, Building, Lock, Eye, EyeOff, ArrowRight, ArrowLeft, School, GraduationCap, Users } from "lucide-react";
import { Button } from "../../components/ui/Button";
import { Input } from "../../components/ui/Input";
import { useToast } from "../../components/ui/Toast";
import { supabase } from "../../utils/supabaseClient";
export default function Register() {
const [step, setStep] = useState(1);
const [isLoading, setIsLoading] = useState(false);
const [showPassword, setShowPassword] = useState(false);
const [formData, setFormData] = useState({
full_name: "",
work_email: "",
institution_name: "",
password: "",
confirm_password: "",
role: ""
});
const navigate = useNavigate();
const { addToast } = useToast();
const handleChange = (e) => {
setFormData({ ...formData, [e.target.name]: e.target.value });
};
const handleSelectRole = (role) => {
setFormData({ ...formData, role });
};
const handleContinue = () => {
if (step === 1 && (!formData.full_name || !formData.work_email)) {
addToast({ title: "Incomplete", description: "Please fill all fields to continue.", variant: "destructive" });
return;
}
if (step === 2) {
if (!formData.institution_name || !formData.password || !formData.confirm_password) {
addToast({ title: "Incomplete", description: "Please fill all fields to continue.", variant: "destructive" });
return;
}
if (formData.password !== formData.confirm_password) {
addToast({ title: "Mismatch", description: "Passwords do not match.", variant: "destructive" });
return;
}
if (formData.password.length < 8) {
addToast({ title: "Weak Password", description: "Password must be at least 8 characters.", variant: "destructive" });
return;
}
}
setStep(prev => prev + 1);
};
const handleBack = () => setStep(prev => prev - 1);
const handleRegister = async () => {
if (!formData.role) {
addToast({ title: "Select a Role", description: "Please select how you identify.", variant: "destructive" });
return;
}
setIsLoading(true);
try {
const { data, error } = await supabase.auth.signUp({
email: formData.work_email,
password: formData.password,
options: {
data: {
full_name: formData.full_name,
work_email: formData.work_email,
institution_name: formData.institution_name,
role: formData.role,
avatar_url: `https://ui-avatars.com/api/?name=${encodeURIComponent(formData.full_name)}&background=random`
}
}
});
if (error) throw error;
addToast({
title: "Account Created!",
description: "Welcome to ExamCraft.AI! Check your email to verify if required.",
variant: "success",
});
navigate("/app");
} catch (error) {
addToast({
title: "Registration Failed",
description: error.message || "Something went wrong.",
variant: "destructive",
});
} finally {
setIsLoading(false);
}
};
return (
<div className="min-h-screen flex items-center justify-center bg-[#0B1121] p-6 text-slate-200">
<div className="w-full max-w-md bg-[#131B2F] border border-slate-800 p-8 rounded-3xl shadow-2xl relative overflow-hidden">
<div className="mb-8">
<h1 className="text-3xl font-black text-white mb-2">Join ExamCraft.AI</h1>
<p className="text-sm text-slate-400">Start generating intelligent question papers today.</p>
</div>
{/* Progress Indicators */}
<div className="flex gap-2 mb-8">
{[1, 2, 3].map((item) => (
<div key={item} className={`h-1.5 flex-1 rounded-full bg-slate-800 relative overflow-hidden`}>
<motion.div
className="absolute inset-0 bg-gradient-to-r from-indigo-500 to-purple-500 rounded-full"
initial={{ width: "0%" }}
animate={{ width: step >= item ? "100%" : "0%" }}
transition={{ duration: 0.3 }}
/>
</div>
))}
</div>
<AnimatePresence mode="wait">
{/* STEP 1 */}
{step === 1 && (
<motion.div key="step1" initial={{ opacity: 0, x: 20 }} animate={{ opacity: 1, x: 0 }} exit={{ opacity: 0, x: -20 }} className="space-y-5">
<div className="relative">
<label className="absolute -top-2 left-4 px-1 bg-[#131B2F] text-xs font-semibold text-indigo-400">Full Name</label>
<div className="relative">
<User className="absolute left-4 top-1/2 -translate-y-1/2 w-5 h-5 text-emerald-500" />
<input type="text" name="full_name" value={formData.full_name} onChange={handleChange} className="w-full bg-[#0B1121] border border-indigo-500/50 rounded-xl pl-12 pr-4 py-4 text-white focus:outline-none focus:ring-2 focus:ring-indigo-500 transition-all font-medium" />
</div>
</div>
<div className="relative">
<label className="absolute -top-2 left-4 px-1 bg-[#131B2F] text-xs font-semibold text-emerald-400">Work Email</label>
<div className="relative">
<Mail className="absolute left-4 top-1/2 -translate-y-1/2 w-5 h-5 text-emerald-500" />
<input type="email" name="work_email" value={formData.work_email} onChange={handleChange} className="w-full bg-[#0B1121] border border-emerald-500/30 rounded-xl pl-12 pr-4 py-4 text-white focus:outline-none focus:border-emerald-500 focus:ring-1 focus:ring-emerald-500 transition-all font-medium" />
</div>
</div>
<button onClick={handleContinue} className="w-full mt-4 bg-white text-black font-bold py-4 rounded-xl flex items-center justify-center gap-2 hover:bg-slate-200 transition-colors">
Continue <ArrowRight size={18} />
</button>
</motion.div>
)}
{/* STEP 2 */}
{step === 2 && (
<motion.div key="step2" initial={{ opacity: 0, x: 20 }} animate={{ opacity: 1, x: 0 }} exit={{ opacity: 0, x: -20 }} className="space-y-5">
<div className="relative">
<label className="absolute -top-2 left-4 px-1 bg-[#131B2F] text-xs font-semibold text-blue-400">Institution Name</label>
<div className="relative">
<Building className="absolute left-4 top-1/2 -translate-y-1/2 w-5 h-5 text-emerald-500" />
<input type="text" name="institution_name" value={formData.institution_name} onChange={handleChange} className="w-full bg-[#0B1121] border border-blue-500/50 rounded-xl pl-12 pr-4 py-4 text-white focus:outline-none focus:ring-2 focus:ring-blue-500 transition-all font-medium" />
</div>
</div>
<div className="relative pt-2">
<label className="absolute top-0 left-4 px-1 bg-[#131B2F] text-xs font-semibold text-emerald-400">Create Password</label>
<div className="relative">
<Lock className="absolute left-4 top-1/2 -translate-y-1/2 w-5 h-5 text-emerald-500" />
<input type={showPassword ? "text" : "password"} name="password" value={formData.password} onChange={handleChange} className="w-full bg-[#0B1121] border border-slate-700/50 rounded-xl pl-12 pr-12 py-4 text-white focus:outline-none focus:border-emerald-500 transition-all tracking-widest" />
<button type="button" onClick={() => setShowPassword(!showPassword)} className="absolute right-4 top-1/2 -translate-y-1/2 text-slate-500 hover:text-white">
{showPassword ? <EyeOff size={18} /> : <Eye size={18} />}
</button>
</div>
</div>
<div className="relative pt-2">
<label className="absolute top-0 left-4 px-1 bg-[#131B2F] text-xs font-semibold text-emerald-400">Confirm Password</label>
<div className="relative">
<Lock className="absolute left-4 top-1/2 -translate-y-1/2 w-5 h-5 text-emerald-500" />
<input type={showPassword ? "text" : "password"} name="confirm_password" value={formData.confirm_password} onChange={handleChange} className="w-full bg-[#0B1121] border border-slate-700/50 rounded-xl pl-12 pr-12 py-4 text-white focus:outline-none focus:border-emerald-500 transition-all tracking-widest" />
</div>
</div>
<div className="flex gap-4 pt-2">
<button onClick={handleBack} className="w-16 h-14 border border-slate-700 rounded-xl flex items-center justify-center hover:bg-slate-800 transition-colors shrink-0 text-slate-300">
<ArrowLeft size={20} />
</button>
<button onClick={handleContinue} className="flex-1 bg-white text-black font-bold h-14 rounded-xl flex items-center justify-center gap-2 hover:bg-slate-200 transition-colors">
Continue <ArrowRight size={18} />
</button>
</div>
</motion.div>
)}
{/* STEP 3 */}
{step === 3 && (
<motion.div key="step3" initial={{ opacity: 0, x: 20 }} animate={{ opacity: 1, x: 0 }} exit={{ opacity: 0, x: -20 }} className="space-y-4">
<p className="text-sm font-semibold mb-4 text-slate-300">I identify mostly as a...</p>
<button onClick={() => handleSelectRole("School Teacher")} className={`w-full flex items-center gap-4 p-4 rounded-xl border ${formData.role === "School Teacher" ? "border-indigo-500 bg-indigo-500/10" : "border-slate-800 bg-[#0B1121]"} transition-all hover:bg-slate-800`}>
<div className="w-10 h-10 rounded-xl bg-blue-500 flex items-center justify-center shrink-0 text-white"><School size={20} /></div>
<span className="font-semibold text-white">School Teacher</span>
</button>
<button onClick={() => handleSelectRole("College Professor")} className={`w-full flex items-center gap-4 p-4 rounded-xl border ${formData.role === "College Professor" ? "border-purple-500 bg-purple-500/10" : "border-slate-800 bg-[#0B1121]"} transition-all hover:bg-slate-800`}>
<div className="w-10 h-10 rounded-xl bg-purple-500 flex items-center justify-center shrink-0 text-white"><GraduationCap size={20} /></div>
<span className="font-semibold text-white">College Professor</span>
</button>
<button onClick={() => handleSelectRole("Coaching Instructor")} className={`w-full flex items-center gap-4 p-4 rounded-xl border ${formData.role === "Coaching Instructor" ? "border-emerald-500 bg-emerald-500/10" : "border-slate-800 bg-[#0B1121]"} transition-all hover:bg-slate-800`}>
<div className="w-10 h-10 rounded-xl bg-emerald-500 flex items-center justify-center shrink-0 text-white"><Users size={20} /></div>
<span className="font-semibold text-white">Coaching Instructor</span>
</button>
<div className="flex gap-4 pt-4">
<button onClick={handleBack} disabled={isLoading} className="w-16 h-14 border border-slate-700 rounded-xl flex items-center justify-center hover:bg-slate-800 transition-colors shrink-0 text-slate-300">
<ArrowLeft size={20} />
</button>
<button onClick={handleRegister} disabled={isLoading || !formData.role} className="flex-1 bg-gradient-to-r from-indigo-500 to-purple-500 text-white font-bold h-14 rounded-xl flex items-center justify-center gap-2 hover:opacity-90 transition-opacity disabled:opacity-50">
{isLoading ? "Creating..." : "Create Account"}
</button>
</div>
</motion.div>
)}
</AnimatePresence>
<p className="text-center text-sm text-slate-500 mt-8">
Already have an account? <Link to="/login" className="text-indigo-400 hover:text-indigo-300 font-semibold transition-colors">Sign in</Link>
</p>
</div>
</div>
);
}
|