Spaces:
Runtime error
Runtime error
Download Frontend/src/pages/Auth/Register.jsx from jinksQspider/ExamCraftAI: direct link, hf CLI and curl.
- Browser
- Download file 14.4 kB
-
https://huggingface.co/spaces/jinksQspider/ExamCraftAI/resolve/main/Frontend/src/pages/Auth/Register.jsx
- Command line
-
hf download hf://spaces/jinksQspider/ExamCraftAI/Frontend/src/pages/Auth/Register.jsx
-
curl -L -o Register.jsx https://huggingface.co/spaces/jinksQspider/ExamCraftAI/resolve/main/Frontend/src/pages/Auth/Register.jsx
14.4 kB
| 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> | |
| ); | |
| } | |