158 lines
6.2 KiB
TypeScript
158 lines
6.2 KiB
TypeScript
import React, { useState } from 'react';
|
|
import { useNavigate, Link } from 'react-router';
|
|
import { BrandLogo } from '../components/common/BrandLogo';
|
|
import { FiMail, FiLock, FiUser, FiArrowRight, FiCheckCircle } from 'react-icons/fi';
|
|
import { FaGraduationCap, FaChalkboardTeacher } from 'react-icons/fa';
|
|
import type { User } from '../types/course';
|
|
|
|
interface RegisterViewProps {
|
|
onShowToast: (msg: string) => void;
|
|
onLogin: (user: User) => void;
|
|
}
|
|
|
|
export const RegisterView: React.FC<RegisterViewProps> = ({ onShowToast, onLogin }) => {
|
|
const navigate = useNavigate();
|
|
const [name, setName] = useState('');
|
|
const [email, setEmail] = useState('');
|
|
const [password, setPassword] = useState('');
|
|
const [accountType, setAccountType] = useState<'buyer' | 'seller'>('buyer');
|
|
|
|
const handleSubmit = (e: React.FormEvent) => {
|
|
e.preventDefault();
|
|
if (name && email && password) {
|
|
const newUser: User = {
|
|
id: Math.random().toString(36).substr(2, 9),
|
|
name,
|
|
email,
|
|
role: accountType,
|
|
};
|
|
onLogin(newUser);
|
|
onShowToast(`¡Cuenta de ${accountType === 'buyer' ? 'Estudiante' : 'Instructor'} creada con éxito!`);
|
|
navigate(accountType === 'seller' ? '/seller' : '/courses');
|
|
}
|
|
};
|
|
|
|
return (
|
|
<div className="min-h-[85vh] flex items-center justify-center py-12 px-4 sm:px-6 lg:px-8 relative bg-slate-950">
|
|
<div className="max-w-md w-full space-y-8 bg-slate-900/90 border border-slate-800 p-8 sm:p-10 rounded-3xl shadow-2xl backdrop-blur-md relative z-10">
|
|
|
|
{/* Header */}
|
|
<div className="text-center space-y-3">
|
|
<div className="flex justify-center">
|
|
<BrandLogo size="lg" showSubtitle={false} />
|
|
</div>
|
|
<h1 className="text-2xl font-bold text-white tracking-tight">
|
|
Crear Cuenta
|
|
</h1>
|
|
<p className="text-xs text-slate-400">
|
|
Únete a la comunidad de RyCourses y empieza hoy mismo
|
|
</p>
|
|
</div>
|
|
|
|
{/* Account type selector */}
|
|
<div className="grid grid-cols-2 gap-2 p-1 bg-slate-950 rounded-2xl border border-slate-800">
|
|
<button
|
|
type="button"
|
|
onClick={() => setAccountType('buyer')}
|
|
className={`flex items-center justify-center gap-2 py-2.5 rounded-xl text-xs font-semibold transition-all ${
|
|
accountType === 'buyer'
|
|
? 'bg-blue-600 text-white shadow-md'
|
|
: 'text-slate-400 hover:text-white'
|
|
}`}
|
|
>
|
|
<FaGraduationCap /> Estudiante
|
|
</button>
|
|
|
|
<button
|
|
type="button"
|
|
onClick={() => setAccountType('seller')}
|
|
className={`flex items-center justify-center gap-2 py-2.5 rounded-xl text-xs font-semibold transition-all ${
|
|
accountType === 'seller'
|
|
? 'bg-violet-600 text-white shadow-md'
|
|
: 'text-slate-400 hover:text-white'
|
|
}`}
|
|
>
|
|
<FaChalkboardTeacher /> Instructor
|
|
</button>
|
|
</div>
|
|
|
|
{/* Form */}
|
|
<form onSubmit={handleSubmit} className="space-y-4">
|
|
<div>
|
|
<label className="block text-xs font-semibold text-slate-300 mb-1.5">
|
|
Nombre Completo
|
|
</label>
|
|
<div className="relative">
|
|
<FiUser className="absolute left-3.5 top-3.5 text-slate-500" />
|
|
<input
|
|
type="text"
|
|
required
|
|
value={name}
|
|
onChange={(e) => setName(e.target.value)}
|
|
placeholder="Carlos Mendoza"
|
|
className="w-full pl-10 pr-4 py-3 bg-slate-950 border border-slate-700/80 rounded-xl text-xs text-white placeholder-slate-500 focus:outline-none focus:ring-2 focus:ring-cyan-500"
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<div>
|
|
<label className="block text-xs font-semibold text-slate-300 mb-1.5">
|
|
Correo Electrónico
|
|
</label>
|
|
<div className="relative">
|
|
<FiMail className="absolute left-3.5 top-3.5 text-slate-500" />
|
|
<input
|
|
type="email"
|
|
required
|
|
value={email}
|
|
onChange={(e) => setEmail(e.target.value)}
|
|
placeholder="[email protected]"
|
|
className="w-full pl-10 pr-4 py-3 bg-slate-950 border border-slate-700/80 rounded-xl text-xs text-white placeholder-slate-500 focus:outline-none focus:ring-2 focus:ring-cyan-500"
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<div>
|
|
<label className="block text-xs font-semibold text-slate-300 mb-1.5">
|
|
Contraseña
|
|
</label>
|
|
<div className="relative">
|
|
<FiLock className="absolute left-3.5 top-3.5 text-slate-500" />
|
|
<input
|
|
type="password"
|
|
required
|
|
value={password}
|
|
onChange={(e) => setPassword(e.target.value)}
|
|
placeholder="Mínimo 8 caracteres"
|
|
className="w-full pl-10 pr-4 py-3 bg-slate-950 border border-slate-700/80 rounded-xl text-xs text-white placeholder-slate-500 focus:outline-none focus:ring-2 focus:ring-cyan-500"
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="flex items-center gap-2 pt-1 text-xs text-slate-400">
|
|
<FiCheckCircle className="text-emerald-400 shrink-0" />
|
|
<span>Acepto los términos de servicio y políticas de privacidad.</span>
|
|
</div>
|
|
|
|
<button
|
|
type="submit"
|
|
className="w-full py-3.5 px-4 bg-gradient-to-r from-blue-600 to-cyan-500 hover:from-blue-500 hover:to-cyan-400 text-white font-bold rounded-xl text-sm shadow-lg shadow-cyan-500/25 transition-all flex items-center justify-center gap-2"
|
|
>
|
|
<span>Crear Cuenta Gratis</span>
|
|
<FiArrowRight />
|
|
</button>
|
|
</form>
|
|
|
|
{/* Footer link */}
|
|
<p className="text-center text-xs text-slate-400 pt-2">
|
|
¿Ya tienes una cuenta?{' '}
|
|
<Link to="/login" className="text-cyan-400 font-bold hover:underline">
|
|
Inicia sesión
|
|
</Link>
|
|
</p>
|
|
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|