Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added PasswordTextField component fixed #1702 #1709

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/components/Account/Login/Login.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import './Login.css';
import InputAdornment from '@material-ui/core/InputAdornment';
import IconButton from '@material-ui/core/IconButton';
import { Visibility, VisibilityOff } from '@material-ui/icons';
import PasswordTextField from '../../UI/FormItems/PasswordTextField';

export class Login extends Component {
static propTypes = {
Expand Down Expand Up @@ -101,7 +102,7 @@ export class Login extends Component {
name="email"
onChange={handleChange}
/>
<TextField
<PasswordTextField
error={errors.password}
label={intl.formatMessage(messages.password)}
type={isPasswordVisible ? 'text' : 'password'}
Expand Down
15 changes: 7 additions & 8 deletions src/components/Account/SignUp/SignUp.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import validationSchema from './validationSchema';
import { signUp } from './SignUp.actions';
import messages from './SignUp.messages';
import './SignUp.css';
import PasswordTextField from '../../UI/FormItems/PasswordTextField';

export class SignUp extends Component {
static propTypes = {
Expand Down Expand Up @@ -114,18 +115,16 @@ export class SignUp extends Component {
error={errors.email}
onChange={handleChange}
/>
<TextField
type="password"
name="password"
label={intl.formatMessage(messages.createYourPassword)}
<PasswordTextField
error={errors.password}
label={intl.formatMessage(messages.createYourPassword)}
name="password"
onChange={handleChange}
/>
<TextField
type="password"
name="passwordConfirm"
label={intl.formatMessage(messages.confirmYourPassword)}
<PasswordTextField
error={errors.passwordConfirm}
label={intl.formatMessage(messages.confirmYourPassword)}
name="passwordConfirm"
onChange={handleChange}
/>
<FormControlLabel
Expand Down
33 changes: 33 additions & 0 deletions src/components/UI/FormItems/PasswordTextField.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React, { useState } from 'react';
import { TextField, InputAdornment, IconButton } from '@material-ui/core';
import { Visibility, VisibilityOff } from '@material-ui/icons';

const PasswordTextField = ({ label, error, name, onChange }) => {
const [isPasswordVisible, setPasswordVisible] = useState(false);

const togglePasswordVisibility = () => {
setPasswordVisible(!isPasswordVisible);
};

return (
<TextField
error={!!error}
helperText={error}
label={label}
type={isPasswordVisible ? 'text' : 'password'}
name={name}
onChange={onChange}
InputProps={{
endAdornment: (
<InputAdornment position="end">
<IconButton onClick={togglePasswordVisibility}>
{isPasswordVisible ? <Visibility /> : <VisibilityOff />}
</IconButton>
</InputAdornment>
)
}}
/>
);
};

export default PasswordTextField;