Skip to content

Commit

Permalink
password visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
DianaKryzhanivska committed Mar 23, 2024
1 parent 65a13e6 commit c5e1cf7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
15 changes: 12 additions & 3 deletions src/components/Login/LoginForm/LoginForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@ import { loginSchema } from "../../../schemas/yupSchemas";
import { useDispatch, useSelector } from "react-redux";
import { selectIsLoggedIn } from "../../../redux/auth/selectors";
import { signInThunk } from "../../../redux/auth/operations";
import { useState } from "react";

const LoginForm = () => {
const dispatch = useDispatch();
const [showPassword, setShowPassword] = useState(false);
const isLoggedIn = useSelector(selectIsLoggedIn);
if (isLoggedIn) {
return <Navigate to="/dictionary" />;
}
const handleTogglePasswordVisibility = () => {
setShowPassword(!showPassword);
};
const handleSubmit = (values) => {
dispatch(signInThunk(values));
};
Expand Down Expand Up @@ -54,7 +59,7 @@ const LoginForm = () => {
<ErrorMessage name="email" component="div" className="error" />
<InputWithIcon>
<Field
type="password"
type={showPassword ? "text" : "password"}
placeholder="Password"
name="password"
onChange={handleChange}
Expand All @@ -65,8 +70,12 @@ const LoginForm = () => {
component="div"
className="error"
/>
<svg>
<use href={`${sprite}#eye-off`} />
<svg onClick={handleTogglePasswordVisibility}>
{showPassword ? (
<use href={`${sprite}#eye`} />
) : (
<use href={`${sprite}#eye-off`} />
)}
</svg>
</InputWithIcon>
</InputBox>
Expand Down
16 changes: 12 additions & 4 deletions src/components/Register/RegisterForm/RegisterForm.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useState } from "react";
import {
Desc,
Form,
Expand All @@ -19,10 +19,14 @@ import { selectIsLoggedIn } from "../../../redux/auth/selectors";

const RegisterForm = () => {
const dispatch = useDispatch();
const [showPassword, setShowPassword] = useState(false);
const isLoggedIn = useSelector(selectIsLoggedIn);
if (isLoggedIn) {
return <Navigate to="/dictionary" />;
}
const handleTogglePasswordVisibility = () => {
setShowPassword(!showPassword);
};
const handleSubmit = (values) => {
dispatch(signUpThunk(values));
};
Expand Down Expand Up @@ -64,7 +68,7 @@ const RegisterForm = () => {
<ErrorMessage name="email" component="div" className="error" />
<InputWithIcon>
<Field
type="password"
type={showPassword ? "text" : "password"}
placeholder="Password"
name="password"
onChange={handleChange}
Expand All @@ -75,8 +79,12 @@ const RegisterForm = () => {
component="div"
className="error"
/>
<svg>
<use href={`${sprite}#eye-off`} />
<svg onClick={handleTogglePasswordVisibility}>
{showPassword ? (
<use href={`${sprite}#eye`} />
) : (
<use href={`${sprite}#eye-off`} />
)}
</svg>
</InputWithIcon>
</InputBox>
Expand Down

0 comments on commit c5e1cf7

Please sign in to comment.