LoginModal.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. 'use client'
  2. import { useState } from 'react'
  3. import { useAuth } from '@/hooks/useAuth'
  4. export default function LoginModal({ onClose }: { onClose: () => void }) {
  5. const { login } = useAuth()
  6. const [email, setEmail] = useState('')
  7. const [password, setPassword] = useState('')
  8. const [error, setError] = useState('')
  9. const handleSubmit = async (e: React.FormEvent) => {
  10. e.preventDefault()
  11. try {
  12. await login(email, password)
  13. onClose()
  14. } catch (err: any) {
  15. setError(err.message || 'Login failed')
  16. }
  17. }
  18. return (
  19. <div className="fixed inset-0 z-50 flex items-center justify-center bg-black/40" onClick={onClose}>
  20. <form
  21. onSubmit={handleSubmit}
  22. onClick={(e) => e.stopPropagation()}
  23. className="w-full max-w-sm space-y-4 rounded-2xl bg-white/10 p-8 backdrop-blur-md"
  24. >
  25. <h1 className="text-center text-2xl font-bold text-white">Вход</h1>
  26. {error && <p className="text-sm text-red-400">{error}</p>}
  27. <input
  28. type="email"
  29. placeholder="Email"
  30. value={email}
  31. onChange={(e) => setEmail(e.target.value)}
  32. 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"
  33. required
  34. />
  35. <input
  36. type="password"
  37. placeholder="Пароль"
  38. value={password}
  39. onChange={(e) => setPassword(e.target.value)}
  40. 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"
  41. required
  42. />
  43. <button
  44. type="submit"
  45. className="w-full rounded-lg bg-green-600 px-4 py-3 font-medium text-white hover:bg-green-500 transition"
  46. >
  47. Войти
  48. </button>
  49. </form>
  50. </div>
  51. )
  52. }