|
1 |
| -import React from 'react'; |
| 1 | +import { React, useState } from 'react'; |
2 | 2 | import { useTranslation } from 'react-i18next';
|
3 | 3 | import { Form, Field } from 'react-final-form';
|
4 | 4 | import { useDispatch } from 'react-redux';
|
| 5 | +import { AiOutlineEye, AiOutlineEyeInvisible } from 'react-icons/ai'; |
5 | 6 | import { validateSignup } from '../../../utils/reduxFormUtils';
|
6 | 7 | import { validateAndSignUpUser } from '../actions';
|
7 | 8 | import Button from '../../../common/Button';
|
@@ -39,6 +40,14 @@ function SignupForm() {
|
39 | 40 | function onSubmit(formProps) {
|
40 | 41 | return dispatch(validateAndSignUpUser(formProps));
|
41 | 42 | }
|
| 43 | + const [showPassword, setShowPassword] = useState(false); |
| 44 | + const [showConfirmPassword, setShowConfirmPassword] = useState(false); |
| 45 | + const handleVisibility = () => { |
| 46 | + setShowPassword(!showPassword); |
| 47 | + }; |
| 48 | + const handleConfirmVisibility = () => { |
| 49 | + setShowConfirmPassword(!showConfirmPassword); |
| 50 | + }; |
42 | 51 |
|
43 | 52 | return (
|
44 | 53 | <Form
|
@@ -95,42 +104,68 @@ function SignupForm() {
|
95 | 104 | </Field>
|
96 | 105 | <Field name="password">
|
97 | 106 | {(field) => (
|
98 |
| - <p className="form__field"> |
99 |
| - <label htmlFor="password" className="form__label"> |
100 |
| - {t('SignupForm.Password')} |
101 |
| - </label> |
102 |
| - <input |
103 |
| - className="form__input" |
104 |
| - aria-label={t('SignupForm.PasswordARIA')} |
105 |
| - type="password" |
106 |
| - id="password" |
107 |
| - autoComplete="new-password" |
108 |
| - {...field.input} |
109 |
| - /> |
110 |
| - {field.meta.touched && field.meta.error && ( |
111 |
| - <span className="form-error">{field.meta.error}</span> |
112 |
| - )} |
113 |
| - </p> |
| 107 | + <div> |
| 108 | + <p className="form__field"> |
| 109 | + <label htmlFor="password" className="form__label"> |
| 110 | + {t('SignupForm.Password')} |
| 111 | + </label> |
| 112 | + <button |
| 113 | + className="form__eye__icon" |
| 114 | + type="button" |
| 115 | + onClick={handleVisibility} |
| 116 | + > |
| 117 | + {showPassword ? ( |
| 118 | + <AiOutlineEyeInvisible /> |
| 119 | + ) : ( |
| 120 | + <AiOutlineEye /> |
| 121 | + )} |
| 122 | + </button> |
| 123 | + <input |
| 124 | + className="form__input" |
| 125 | + aria-label={t('SignupForm.PasswordARIA')} |
| 126 | + type={showPassword ? 'text' : 'password'} |
| 127 | + id="password" |
| 128 | + autoComplete="new-password" |
| 129 | + {...field.input} |
| 130 | + /> |
| 131 | + {field.meta.touched && field.meta.error && ( |
| 132 | + <span className="form-error">{field.meta.error}</span> |
| 133 | + )} |
| 134 | + </p> |
| 135 | + </div> |
114 | 136 | )}
|
115 | 137 | </Field>
|
116 | 138 | <Field name="confirmPassword">
|
117 | 139 | {(field) => (
|
118 |
| - <p className="form__field"> |
119 |
| - <label htmlFor="confirm password" className="form__label"> |
120 |
| - {t('SignupForm.ConfirmPassword')} |
121 |
| - </label> |
122 |
| - <input |
123 |
| - className="form__input" |
124 |
| - type="password" |
125 |
| - aria-label={t('SignupForm.ConfirmPasswordARIA')} |
126 |
| - id="confirm password" |
127 |
| - autoComplete="new-password" |
128 |
| - {...field.input} |
129 |
| - /> |
130 |
| - {field.meta.touched && field.meta.error && ( |
131 |
| - <span className="form-error">{field.meta.error}</span> |
132 |
| - )} |
133 |
| - </p> |
| 140 | + <div> |
| 141 | + <p className="form__field"> |
| 142 | + <label htmlFor="confirmPassword" className="form__label"> |
| 143 | + {t('SignupForm.ConfirmPassword')} |
| 144 | + </label> |
| 145 | + <button |
| 146 | + className="form__eye__icon" |
| 147 | + type="button" |
| 148 | + onClick={handleConfirmVisibility} |
| 149 | + > |
| 150 | + {showConfirmPassword ? ( |
| 151 | + <AiOutlineEyeInvisible /> |
| 152 | + ) : ( |
| 153 | + <AiOutlineEye /> |
| 154 | + )} |
| 155 | + </button> |
| 156 | + <input |
| 157 | + className="form__input" |
| 158 | + type={showConfirmPassword ? 'text' : 'password'} |
| 159 | + aria-label={t('SignupForm.ConfirmPasswordARIA')} |
| 160 | + id="confirmPassword" // Match the id with htmlFor |
| 161 | + autoComplete="new-password" |
| 162 | + {...field.input} |
| 163 | + /> |
| 164 | + {field.meta.touched && field.meta.error && ( |
| 165 | + <span className="form-error">{field.meta.error}</span> |
| 166 | + )} |
| 167 | + </p> |
| 168 | + </div> |
134 | 169 | )}
|
135 | 170 | </Field>
|
136 | 171 | <Button type="submit" disabled={submitting || invalid || pristine}>
|
|
0 commit comments