Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Migrate string refs of reset password modal #7038

Merged
merged 3 commits into from
Nov 20, 2020
Merged
Changes from 1 commit
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
Next Next commit
Migrate string refs of currentPassword and password refs
  • Loading branch information
sridhar02 committed Nov 12, 2020
commit 0a75f3a821201f0b0069c676db3e386ac5d41a72
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ type Props = {
}

export default class ResetPasswordModal extends React.PureComponent<Props, State> {
private currentPasswordRef: React.RefObject<HTMLInputElement>;
private passwordRef: React.RefObject<HTMLInputElement>;
public static defaultProps: Partial<Props> = {
show: false,
};
Expand All @@ -47,6 +49,9 @@ export default class ResetPasswordModal extends React.PureComponent<Props, State
serverErrorNewPass: null,
serverErrorCurrentPass: null,
};

this.currentPasswordRef = React.createRef();
this.passwordRef = React.createRef();
}

public componentWillUnmount(): void {
Expand All @@ -63,8 +68,8 @@ export default class ResetPasswordModal extends React.PureComponent<Props, State
}

let currentPassword = '';
if (this.refs.currentPassword) {
currentPassword = (this.refs.currentPassword as HTMLInputElement).value;
if (this.currentPasswordRef.current) {
currentPassword = (this.currentPasswordRef.current as HTMLInputElement).value;
if (currentPassword === '') {
const errorMsg = (
<FormattedMessage
Expand All @@ -77,7 +82,7 @@ export default class ResetPasswordModal extends React.PureComponent<Props, State
}
}

const password = (this.refs.password as HTMLInputElement).value;
const password = (this.passwordRef.current as HTMLInputElement).value;

const {valid, error} = Utils.isValidPassword(password, this.props.passwordConfig);
if (!valid && error) {
Expand Down Expand Up @@ -159,7 +164,7 @@ export default class ResetPasswordModal extends React.PureComponent<Props, State
</span>
<input
type='password'
ref='currentPassword'
ref={this.currentPasswordRef}
className='form-control'
autoFocus={true}
/>
Expand Down Expand Up @@ -205,7 +210,7 @@ export default class ResetPasswordModal extends React.PureComponent<Props, State
</span>
<input
type='password'
ref='password'
ref={this.passwordRef}
className='form-control'
autoFocus={newPasswordFocus}
/>
Expand Down