139 lines
5.7 KiB
TypeScript
139 lines
5.7 KiB
TypeScript
import { useState } from 'react'
|
|
import { Link, useNavigate } from 'react-router-dom'
|
|
import { Disc3, Mail, Lock, User, Loader2 } from 'lucide-react'
|
|
import { useAuth } from '../lib/auth'
|
|
import { register as apiRegister } from '../lib/api'
|
|
|
|
export default function Register() {
|
|
const [name, setName] = useState('')
|
|
const [email, setEmail] = useState('')
|
|
const [password, setPassword] = useState('')
|
|
const [error, setError] = useState('')
|
|
const [loading, setLoading] = useState(false)
|
|
const { login } = useAuth()
|
|
const navigate = useNavigate()
|
|
|
|
const handleSubmit = async (e: React.FormEvent) => {
|
|
e.preventDefault()
|
|
setError('')
|
|
setLoading(true)
|
|
|
|
try {
|
|
const response = await apiRegister(email, name, password)
|
|
await login(response.access_token)
|
|
navigate('/dashboard')
|
|
} catch (err: any) {
|
|
setError(err.response?.data?.detail || 'Registration failed. Please try again.')
|
|
} finally {
|
|
setLoading(false)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div className="min-h-screen bg-cream flex flex-col">
|
|
{/* Header */}
|
|
<header className="px-6 py-5">
|
|
<Link to="/" className="flex items-center gap-2 no-underline w-fit">
|
|
<Disc3 className="w-7 h-7 text-purple" strokeWidth={2.5} />
|
|
<span className="text-xl font-bold text-charcoal tracking-tight">Vynl</span>
|
|
</Link>
|
|
</header>
|
|
|
|
{/* Form */}
|
|
<div className="flex-1 flex items-center justify-center px-6 pb-16">
|
|
<div className="w-full max-w-md">
|
|
<div className="bg-white rounded-2xl shadow-lg shadow-purple/5 border border-purple-100 p-8">
|
|
<div className="text-center mb-8">
|
|
<h1 className="text-2xl font-bold text-charcoal">Create your account</h1>
|
|
<p className="text-charcoal-muted mt-1">Start discovering music you'll love</p>
|
|
</div>
|
|
|
|
{error && (
|
|
<div className="mb-6 p-3 bg-red-50 border border-red-200 rounded-lg text-sm text-red-600">
|
|
{error}
|
|
</div>
|
|
)}
|
|
|
|
<form onSubmit={handleSubmit} className="space-y-5">
|
|
<div>
|
|
<label className="block text-sm font-medium text-charcoal mb-1.5">
|
|
Name
|
|
</label>
|
|
<div className="relative">
|
|
<User className="absolute left-3 top-1/2 -translate-y-1/2 w-5 h-5 text-charcoal-muted/50" />
|
|
<input
|
|
type="text"
|
|
value={name}
|
|
onChange={(e) => setName(e.target.value)}
|
|
placeholder="Your name"
|
|
required
|
|
className="w-full pl-11 pr-4 py-3 bg-cream/50 border border-purple-100 rounded-xl text-charcoal placeholder:text-charcoal-muted/40 focus:outline-none focus:ring-2 focus:ring-purple/30 focus:border-purple transition-colors text-sm box-border"
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<div>
|
|
<label className="block text-sm font-medium text-charcoal mb-1.5">
|
|
Email
|
|
</label>
|
|
<div className="relative">
|
|
<Mail className="absolute left-3 top-1/2 -translate-y-1/2 w-5 h-5 text-charcoal-muted/50" />
|
|
<input
|
|
type="email"
|
|
value={email}
|
|
onChange={(e) => setEmail(e.target.value)}
|
|
placeholder="you@example.com"
|
|
required
|
|
className="w-full pl-11 pr-4 py-3 bg-cream/50 border border-purple-100 rounded-xl text-charcoal placeholder:text-charcoal-muted/40 focus:outline-none focus:ring-2 focus:ring-purple/30 focus:border-purple transition-colors text-sm box-border"
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<div>
|
|
<label className="block text-sm font-medium text-charcoal mb-1.5">
|
|
Password
|
|
</label>
|
|
<div className="relative">
|
|
<Lock className="absolute left-3 top-1/2 -translate-y-1/2 w-5 h-5 text-charcoal-muted/50" />
|
|
<input
|
|
type="password"
|
|
value={password}
|
|
onChange={(e) => setPassword(e.target.value)}
|
|
placeholder="Create a password"
|
|
required
|
|
minLength={8}
|
|
className="w-full pl-11 pr-4 py-3 bg-cream/50 border border-purple-100 rounded-xl text-charcoal placeholder:text-charcoal-muted/40 focus:outline-none focus:ring-2 focus:ring-purple/30 focus:border-purple transition-colors text-sm box-border"
|
|
/>
|
|
</div>
|
|
<p className="text-xs text-charcoal-muted mt-1.5">Must be at least 8 characters</p>
|
|
</div>
|
|
|
|
<button
|
|
type="submit"
|
|
disabled={loading}
|
|
className="w-full py-3 bg-purple text-white font-semibold rounded-xl hover:bg-purple-dark transition-colors disabled:opacity-50 cursor-pointer border-none text-sm flex items-center justify-center gap-2"
|
|
>
|
|
{loading ? (
|
|
<>
|
|
<Loader2 className="w-4 h-4 animate-spin" />
|
|
Creating account...
|
|
</>
|
|
) : (
|
|
'Create account'
|
|
)}
|
|
</button>
|
|
</form>
|
|
|
|
<p className="text-center mt-6 text-sm text-charcoal-muted">
|
|
Already have an account?{' '}
|
|
<Link to="/login" className="text-purple font-medium hover:underline">
|
|
Sign in
|
|
</Link>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|