# Code coverage report for pages/ResetPassword.jsx

# All files / pages ResetPassword.jsx

96.29% Statements 26/27
92.85% Branches 13/14
80% Functions 4/5
100% Lines 26/26

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
    140
    141

    18x
    18x
    18x
    18x
    18x
    18x
    18x

    18x

    18x
    4x
    4x
    1x
    1x

    3x
    3x

    3x
    3x
    2x
    2x

    1x

    3x

    18x
    2x

    16x

    4x

    1x

     import { useState } from 'react'
    import { useSearchParams, Link, useNavigate } from 'react-router-dom'
    import { motion } from 'framer-motion'
    import { Eye, EyeOff, Zap, CheckCircle } from 'lucide-react'
    import api from '../api/client'

    export default function ResetPassword() {
      const [searchParams] = useSearchParams()
      const [password, setPassword] = useState('')
      const [showPassword, setShowPassword] = useState(false)
      const [loading, setLoading] = useState(false)
      const [error, setError] = useState('')
      const [success, setSuccess] = useState(false)
      const navigate = useNavigate()

      const token = searchParams.get('token')

      const handleSubmit = async (e) => {
        e.preventDefault()
        if (!token) {
          setError('Токен не найден')
          return
        }

        setError('')
        setLoading(true)

        try {
          await api.post('/auth/reset-password', { token, new_password: password })
          setSuccess(true)
          setTimeout(() => navigate('/login'), 2000)
        } catch (err) {
          setError(err.response?.data?.error || 'Ошибка сброса пароля')
        } finally {
          setLoading(false)
        }
      }

      if (success) {
        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="card p-10 text-center max-w-md w-full"
            >
              <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">Перенаправляем на страницу входа...</p>
            </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"
              >
                <Zap 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">Придумай новый надёжный пароль</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">
                    Новый пароль
                  </label>
                  <div className="relative">
                    <input
                      type={showPassword ? 'text' : 'password'}
                      value={password}
                      onChange={(e) => setPassword(e.target.value)}
                      className="input pr-12"
                      placeholder="Минимум 8 символов"
                      minLength={8}
                      required
                    />
                    <button
                      type="button"
                      onClick={() => setShowPassword(!showPassword)}
                      className="absolute right-4 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600 transition-colors"
                    >
                      {showPassword ? <EyeOff size={20} /> : <Eye size={20} />}
                    </button>
                  </div>
                </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="text-primary-600 hover:text-primary-700 font-medium text-sm">
                  Вернуться ко входу
                </Link>
              </div>
            </div>
          </motion.div>
        </div>
      )
    }