Spaces:
Running
Running
axeronis commited on
Commit ·
2c7a422
1
Parent(s): 91f59f6
Improve Register UX: Confirm Password, Show Password toggle
Browse files
frontend/app/register/page.tsx
CHANGED
|
@@ -4,7 +4,7 @@ import { useState, useEffect, Suspense } from 'react'
|
|
| 4 |
import { useAuth } from '@/contexts/AuthContext'
|
| 5 |
import { useSearchParams } from 'next/navigation'
|
| 6 |
import Link from 'next/link'
|
| 7 |
-
import { Mail, Lock, Building, Loader2, Users, ArrowRight } from 'lucide-react'
|
| 8 |
import { motion } from 'framer-motion'
|
| 9 |
|
| 10 |
// Компонент для работы с referral code
|
|
@@ -26,10 +26,12 @@ export default function RegisterPage() {
|
|
| 26 |
const { register, isLoading: authLoading } = useAuth()
|
| 27 |
const [email, setEmail] = useState('')
|
| 28 |
const [password, setPassword] = useState('')
|
|
|
|
| 29 |
const [companyName, setCompanyName] = useState('')
|
| 30 |
const [error, setError] = useState('')
|
| 31 |
const [isLoading, setIsLoading] = useState(false)
|
| 32 |
const [referralCode, setReferralCode] = useState<string | null>(null)
|
|
|
|
| 33 |
|
| 34 |
const handleSubmit = async (e: React.FormEvent) => {
|
| 35 |
e.preventDefault()
|
|
@@ -37,7 +39,13 @@ export default function RegisterPage() {
|
|
| 37 |
|
| 38 |
// Validate password length
|
| 39 |
if (password.length < 8) {
|
| 40 |
-
setError('
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
return
|
| 42 |
}
|
| 43 |
|
|
@@ -46,7 +54,7 @@ export default function RegisterPage() {
|
|
| 46 |
try {
|
| 47 |
await register(email, password, companyName, undefined, referralCode)
|
| 48 |
} catch (err: any) {
|
| 49 |
-
setError(err.message || '
|
| 50 |
} finally {
|
| 51 |
setIsLoading(false)
|
| 52 |
}
|
|
@@ -157,14 +165,21 @@ export default function RegisterPage() {
|
|
| 157 |
<Lock className="h-5 w-5 text-slate-500 group-focus-within:text-indigo-400 transition-colors" />
|
| 158 |
</div>
|
| 159 |
<input
|
| 160 |
-
type="password"
|
| 161 |
required
|
| 162 |
value={password}
|
| 163 |
onChange={(e) => setPassword(e.target.value)}
|
| 164 |
disabled={isLoading}
|
| 165 |
-
className="block w-full pl-10 pr-
|
| 166 |
placeholder="••••••••"
|
| 167 |
/>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
</div>
|
| 169 |
<p className="mt-2 text-xs text-slate-500 flex items-center gap-1 ml-1">
|
| 170 |
<span className="w-1 h-1 rounded-full bg-slate-500" />
|
|
@@ -172,6 +187,24 @@ export default function RegisterPage() {
|
|
| 172 |
</p>
|
| 173 |
</div>
|
| 174 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
<button
|
| 176 |
type="submit"
|
| 177 |
disabled={isLoading}
|
|
|
|
| 4 |
import { useAuth } from '@/contexts/AuthContext'
|
| 5 |
import { useSearchParams } from 'next/navigation'
|
| 6 |
import Link from 'next/link'
|
| 7 |
+
import { Mail, Lock, Building, Loader2, Users, ArrowRight, Eye, EyeOff } from 'lucide-react'
|
| 8 |
import { motion } from 'framer-motion'
|
| 9 |
|
| 10 |
// Компонент для работы с referral code
|
|
|
|
| 26 |
const { register, isLoading: authLoading } = useAuth()
|
| 27 |
const [email, setEmail] = useState('')
|
| 28 |
const [password, setPassword] = useState('')
|
| 29 |
+
const [confirmPassword, setConfirmPassword] = useState('')
|
| 30 |
const [companyName, setCompanyName] = useState('')
|
| 31 |
const [error, setError] = useState('')
|
| 32 |
const [isLoading, setIsLoading] = useState(false)
|
| 33 |
const [referralCode, setReferralCode] = useState<string | null>(null)
|
| 34 |
+
const [showPassword, setShowPassword] = useState(false)
|
| 35 |
|
| 36 |
const handleSubmit = async (e: React.FormEvent) => {
|
| 37 |
e.preventDefault()
|
|
|
|
| 39 |
|
| 40 |
// Validate password length
|
| 41 |
if (password.length < 8) {
|
| 42 |
+
setError('Пароль должен содержать минимум 8 символов')
|
| 43 |
+
return
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
// Validate password match
|
| 47 |
+
if (password !== confirmPassword) {
|
| 48 |
+
setError('Пароли не совпадают')
|
| 49 |
return
|
| 50 |
}
|
| 51 |
|
|
|
|
| 54 |
try {
|
| 55 |
await register(email, password, companyName, undefined, referralCode)
|
| 56 |
} catch (err: any) {
|
| 57 |
+
setError(err.message || 'Ошибка регистрации')
|
| 58 |
} finally {
|
| 59 |
setIsLoading(false)
|
| 60 |
}
|
|
|
|
| 165 |
<Lock className="h-5 w-5 text-slate-500 group-focus-within:text-indigo-400 transition-colors" />
|
| 166 |
</div>
|
| 167 |
<input
|
| 168 |
+
type={showPassword ? "text" : "password"}
|
| 169 |
required
|
| 170 |
value={password}
|
| 171 |
onChange={(e) => setPassword(e.target.value)}
|
| 172 |
disabled={isLoading}
|
| 173 |
+
className="block w-full pl-10 pr-10 py-3 border border-white/10 rounded-xl bg-white/5 text-white placeholder-slate-600 focus:outline-none focus:border-indigo-500/50 focus:bg-white/10 focus:ring-1 focus:ring-indigo-500/50 transition-all sm:text-sm"
|
| 174 |
placeholder="••••••••"
|
| 175 |
/>
|
| 176 |
+
<button
|
| 177 |
+
type="button"
|
| 178 |
+
onClick={() => setShowPassword(!showPassword)}
|
| 179 |
+
className="absolute inset-y-0 right-0 pr-3 flex items-center text-slate-500 hover:text-indigo-400 transition-colors"
|
| 180 |
+
>
|
| 181 |
+
{showPassword ? <EyeOff className="h-5 w-5" /> : <Eye className="h-5 w-5" />}
|
| 182 |
+
</button>
|
| 183 |
</div>
|
| 184 |
<p className="mt-2 text-xs text-slate-500 flex items-center gap-1 ml-1">
|
| 185 |
<span className="w-1 h-1 rounded-full bg-slate-500" />
|
|
|
|
| 187 |
</p>
|
| 188 |
</div>
|
| 189 |
|
| 190 |
+
<div>
|
| 191 |
+
<label className="block text-xs font-medium text-slate-400 mb-1.5 ml-1">Подтвердите пароль</label>
|
| 192 |
+
<div className="relative group">
|
| 193 |
+
<div className="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
|
| 194 |
+
<Lock className="h-5 w-5 text-slate-500 group-focus-within:text-indigo-400 transition-colors" />
|
| 195 |
+
</div>
|
| 196 |
+
<input
|
| 197 |
+
type={showPassword ? "text" : "password"}
|
| 198 |
+
required
|
| 199 |
+
value={confirmPassword}
|
| 200 |
+
onChange={(e) => setConfirmPassword(e.target.value)}
|
| 201 |
+
disabled={isLoading}
|
| 202 |
+
className="block w-full pl-10 pr-3 py-3 border border-white/10 rounded-xl bg-white/5 text-white placeholder-slate-600 focus:outline-none focus:border-indigo-500/50 focus:bg-white/10 focus:ring-1 focus:ring-indigo-500/50 transition-all sm:text-sm"
|
| 203 |
+
placeholder="••••••••"
|
| 204 |
+
/>
|
| 205 |
+
</div>
|
| 206 |
+
</div>
|
| 207 |
+
|
| 208 |
<button
|
| 209 |
type="submit"
|
| 210 |
disabled={isLoading}
|