• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

atlp-rwanda / vikings-ec-fe / a2e058da-2c78-40f1-b0d3-0ffea5a6daab

pending completion
a2e058da-2c78-40f1-b0d3-0ffea5a6daab

push

circleci

GitHub
feat: update password (#17)

51 of 104 branches covered (49.04%)

Branch coverage included in aggregate %.

30 of 30 new or added lines in 3 files covered. (100.0%)

407 of 476 relevant lines covered (85.5%)

7.44 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

62.79
/src/components/forms/ResetPasswordForm.js
1
import React, { useEffect, useState } from 'react';
2
import { useDispatch, useSelector } from 'react-redux';
3
import { useForm } from 'react-hook-form';
4
import { yupResolver } from '@hookform/resolvers/yup';
5
import InputField from './InputField';
6
import Button from './Button';
7
import { resetPasswordSchema } from '../../validations/inputValidation';
8
import { showErrorMessage, showSuccessMessage } from '../../utils/toast';
9
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
10
import { faEye, faEyeSlash } from '@fortawesome/free-regular-svg-icons';
11
import { resetPassword } from '../../features/auth/resetPasswordSlice';
12
import { useLocation, useNavigate } from 'react-router-dom';
13

14
const ResetPasswordForm = () => {
21✔
15
  const { isLoading } = useSelector((state) => state.resetPassword);
17✔
16
  const [token, setToken]  = useState(null);
7✔
17
  const dispatch = useDispatch();
7✔
18
  const location = useLocation();
7✔
19
  const navigate = useNavigate();
7✔
20
  useEffect(() => {
7✔
21
    if(location){
4!
22
      const queryParams = new URLSearchParams(location.search);
4✔
23
      const token = queryParams.get("token");
4✔
24
      if(token){
4✔
25
        setToken(token);
3✔
26
      }else {
27
        showErrorMessage("Invalid path, please use a link sent to your email");
1✔
28
        navigate("/");
1✔
29
      }
30
    }
31

32

33
  }, [location]);
34

35
  const {
36
    register,
37
    handleSubmit,
38
    formState: { errors },
39
  } = useForm({
7✔
40
    resolver: yupResolver(resetPasswordSchema),
41
  });
42
  const [showPassword, setShowPassword] = useState(false);
7✔
43
  const handleClickShowPassword = () => {
7✔
44
    setShowPassword(!showPassword);
×
45
  };
46

47
  const onSubmit = async (userData) => {
7✔
48
    try {
×
49
      const {newPassword} = userData;
×
50
      const response = await dispatch(resetPassword({newPassword, token})).unwrap();
×
51
      showSuccessMessage(response.message);
×
52
      navigate("/auth/signin");
×
53
    } catch (error) {
54
      showErrorMessage(error?.data?.message || "Something went wrong");
×
55
    }
56
  };
57

58
  return (
7✔
59
    <form
60
      onSubmit={(event) => {
61
        handleSubmit(onSubmit)(event);
×
62
      }}
63
      className="my-8 px-5"
64
    >
65
      <div className="flex flex-col -space-y-px rounded-md shadow-sm">
66
        <div className=" relative">
67
          <InputField
68
            placeholder="New password"
69
            type={showPassword ? 'text' : 'password'}
7!
70
            className=" w-full rounded-md px-2 py-3 placeholder:text-gray-400 sm:text-[12px] my-2 focus:bg-[#EAF0F7] bg-[#EAF0F7]"
71
            {...register('newPassword')}
72
            error={errors?.newPassword}
73
          />
74
          <div className=" absolute right-4 top-4" onClick={handleClickShowPassword}>
75
            {showPassword ? (
7!
76
              <FontAwesomeIcon icon={faEye} />
77
            ) : (
78
              <FontAwesomeIcon icon={faEyeSlash} />
79
            )}
80
          </div>
81
        </div>
82
        <div className=" relative">
83
          <InputField
84
            placeholder="Confirm password"
85
            type={showPassword ? 'text' : 'password'}
7!
86
            className=" w-full rounded-md px-2 py-3 placeholder:text-gray-400 sm:text-[12px] my-2 focus:bg-[#EAF0F7] bg-[#EAF0F7]"
87
            {...register('confirmPassword')}
88
            error={errors?.confirmPassword}
89
          />
90
          <div className=" absolute right-4 top-4" onClick={handleClickShowPassword}>
91
            {showPassword ? (
7!
92
              <FontAwesomeIcon icon={faEye} />
93
            ) : (
94
              <FontAwesomeIcon icon={faEyeSlash} />
95
            )}
96
          </div>
97
        </div>
98
        <div>
99
          {isLoading ? (
7!
100
            <Button type="submit" label="" className="" disabled>
101
              <svg
102
                role="status"
103
                className="inline mr-3 w-4 h-4 text-white animate-spin"
104
                viewBox="0 0 100 101"
105
                fill="none"
106
                xmlns="http://www.w3.org/2000/svg"
107
              >
108
                <path
109
                  d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
110
                  fill="#E5E7EB"
111
                />
112
                <path
113
                  d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
114
                  fill="currentColor"
115
                />
116
              </svg>
117
            </Button>
118
          ) : (
119
            <Button type="submit" label="Reset" className="my-1" role="submit" />
120
          )}
121
        </div>
122
      </div>
123
    </form>
124
  );
125
};
126

127
export default ResetPasswordForm;
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc