|
@@ -5,8 +5,10 @@ import { useAuth } from '@/hooks/useAuth'
|
|
|
|
|
|
|
|
export default function RegisterModal({ onClose }: { onClose: () => void }) {
|
|
export default function RegisterModal({ onClose }: { onClose: () => void }) {
|
|
|
const { register } = useAuth()
|
|
const { register } = useAuth()
|
|
|
|
|
+ const [name, setName] = useState('')
|
|
|
const [email, setEmail] = useState('')
|
|
const [email, setEmail] = useState('')
|
|
|
const [password, setPassword] = useState('')
|
|
const [password, setPassword] = useState('')
|
|
|
|
|
+ const [confirmPassword, setConfirmPassword] = useState('')
|
|
|
const [role, setRole] = useState('customer')
|
|
const [role, setRole] = useState('customer')
|
|
|
const [error, setError] = useState('')
|
|
const [error, setError] = useState('')
|
|
|
const [success, setSuccess] = useState(false)
|
|
const [success, setSuccess] = useState(false)
|
|
@@ -19,8 +21,12 @@ export default function RegisterModal({ onClose }: { onClose: () => void }) {
|
|
|
|
|
|
|
|
const handleSubmit = async (e: React.FormEvent) => {
|
|
const handleSubmit = async (e: React.FormEvent) => {
|
|
|
e.preventDefault()
|
|
e.preventDefault()
|
|
|
|
|
+ if (password !== confirmPassword) {
|
|
|
|
|
+ setError('Пароли не совпадают')
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
try {
|
|
try {
|
|
|
- await register(email, password, role)
|
|
|
|
|
|
|
+ await register(email, password, role, name || undefined)
|
|
|
setSuccess(true)
|
|
setSuccess(true)
|
|
|
} catch (err: any) {
|
|
} catch (err: any) {
|
|
|
setError(err.message || 'Registration failed')
|
|
setError(err.message || 'Registration failed')
|
|
@@ -44,6 +50,14 @@ export default function RegisterModal({ onClose }: { onClose: () => void }) {
|
|
|
|
|
|
|
|
{error && <p className="text-sm text-red-400">{error}</p>}
|
|
{error && <p className="text-sm text-red-400">{error}</p>}
|
|
|
|
|
|
|
|
|
|
+ <input
|
|
|
|
|
+ type="text"
|
|
|
|
|
+ placeholder="Имя"
|
|
|
|
|
+ value={name}
|
|
|
|
|
+ onChange={(e) => setName(e.target.value)}
|
|
|
|
|
+ className="w-full rounded-lg border border-white/10 bg-white/5 px-4 py-3 text-white placeholder-white/40 outline-none focus:border-green-500"
|
|
|
|
|
+ />
|
|
|
|
|
+
|
|
|
<input
|
|
<input
|
|
|
type="email"
|
|
type="email"
|
|
|
placeholder="Email"
|
|
placeholder="Email"
|
|
@@ -63,6 +77,16 @@ export default function RegisterModal({ onClose }: { onClose: () => void }) {
|
|
|
minLength={8}
|
|
minLength={8}
|
|
|
/>
|
|
/>
|
|
|
|
|
|
|
|
|
|
+ <input
|
|
|
|
|
+ type="password"
|
|
|
|
|
+ placeholder="Повторите пароль"
|
|
|
|
|
+ value={confirmPassword}
|
|
|
|
|
+ onChange={(e) => setConfirmPassword(e.target.value)}
|
|
|
|
|
+ className="w-full rounded-lg border border-white/10 bg-white/5 px-4 py-3 text-white placeholder-white/40 outline-none focus:border-green-500"
|
|
|
|
|
+ required
|
|
|
|
|
+ minLength={8}
|
|
|
|
|
+ />
|
|
|
|
|
+
|
|
|
<select
|
|
<select
|
|
|
value={role}
|
|
value={role}
|
|
|
onChange={(e) => setRole(e.target.value)}
|
|
onChange={(e) => setRole(e.target.value)}
|