# Code coverage report for pages/ForgotPassword.jsx

# All files / pages ForgotPassword.jsx

100% Statements 17/17
100% Branches 8/8
100% Functions 3/3
100% Lines 17/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139

    22x
    22x
    22x
    22x

    22x
    5x
    5x
    5x

    5x
    5x
    3x

    2x

    5x

    22x
    3x

    19x

    5x

     import { useState } from 'react'
    import { Link } from 'react-router-dom'
    import { motion } from 'framer-motion'
    import { Mail, ArrowLeft, Zap, CheckCircle } from 'lucide-react'
    import api from '../api/client'

    export default function ForgotPassword() {
      const [email, setEmail] = useState('')
      const [loading, setLoading] = useState(false)
      const [error, setError] = useState('')
      const [sent, setSent] = useState(false)

      const handleSubmit = async (e) => {
        e.preventDefault()
        setError('')
        setLoading(true)

        try {
          await api.post('/auth/forgot-password', { email })
          setSent(true)
        } catch (err) {
          setError(err.response?.data?.error || 'Ошибка отправки')
        } finally {
          setLoading(false)
        }
      }

      if (sent) {
        return (
          <div className="min-h-screen flex items-center justify-center p-4 gradient-mesh bg-surface-50">
            <motion.div
              initial={{ opacity: 0, scale: 0.9 }}
              animate={{ opacity: 1, scale: 1 }}
              className="w-full max-w-md"
            >
              <div className="card p-10 text-center">
                <motion.div
                  initial={{ scale: 0 }}
                  animate={{ scale: 1 }}
                  transition={{ type: 'spring', stiffness: 200 }}
                  className="w-20 h-20 rounded-3xl bg-green-100 flex items-center justify-center mx-auto mb-6"
                >
                  <CheckCircle className="w-10 h-10 text-green-600" />
                </motion.div>
                <h1 className="text-2xl font-display font-bold text-gray-900 mb-2">
                  Письмо отправлено! 📬
                </h1>
                <p className="text-gray-500 mb-6">
                  Если аккаунт с email <strong>{email}</strong> существует, мы отправили ссылку для сброса пароля.
                </p>
                <Link to="/login" className="btn btn-primary">
                  Вернуться ко входу
                </Link>
              </div>
            </motion.div>
          </div>
        )
      }

      return (
        <div className="min-h-screen flex items-center justify-center p-4 gradient-mesh bg-surface-50">
          <motion.div
            initial={{ opacity: 0, y: 20 }}
            animate={{ opacity: 1, y: 0 }}
            className="w-full max-w-md"
          >
            <div className="text-center mb-8">
              <motion.div
                initial={{ scale: 0 }}
                animate={{ scale: 1 }}
                transition={{ type: 'spring', delay: 0.1 }}
                className="inline-flex items-center justify-center w-20 h-20 rounded-3xl bg-gradient-to-br from-primary-500 to-primary-700 mb-6 shadow-xl shadow-primary-500/30"
              >
                <Mail className="w-10 h-10 text-white" />
              </motion.div>
              <h1 className="text-3xl font-display font-bold text-gray-900">
                Забыли пароль?
              </h1>
              <p className="text-gray-500 mt-2">
                Введи email и мы отправим ссылку для сброса
              </p>
            </div>

            <div className="card p-8">
              <form onSubmit={handleSubmit} className="space-y-5">
                {error && (
                  <motion.div
                    initial={{ opacity: 0, height: 0 }}
                    animate={{ opacity: 1, height: 'auto' }}
                    className="p-4 rounded-2xl bg-red-50 text-red-600 text-sm font-medium"
                  >
                    {error}
                  </motion.div>
                )}

                <div>
                  <label className="block text-sm font-semibold text-gray-700 mb-2">
                    Email
                  </label>
                  <input
                    type="email"
                    value={email}
                    onChange={(e) => setEmail(e.target.value)}
                    className="input"
                    placeholder="your@email.com"
                    required
                    autoFocus
                  />
                </div>

                <button
                  type="submit"
                  disabled={loading}
                  className="btn btn-primary w-full text-lg"
                >
                  {loading ? 'Отправляем...' : 'Отправить ссылку'}
                </button>
              </form>

              <div className="mt-6 text-center">
                <Link
                  to="/login"
                  className="inline-flex items-center gap-2 text-primary-600 hover:text-primary-700 font-medium text-sm"
                >
                  <ArrowLeft size={16} />
                  Вернуться ко входу
                </Link>
              </div>
            </div>

            <div className="flex items-center justify-center gap-2 mt-6 text-gray-400">
              <Zap size={16} />
              <span className="text-sm font-medium">Pulse</span>
            </div>
          </motion.div>
        </div>
      )
    }