Skip to content
22 changes: 16 additions & 6 deletions src/pages/signin/PasswordForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class PasswordForm extends React.Component {
constructor(props) {
super(props);
this.validateAndSubmitForm = this.validateAndSubmitForm.bind(this);
this.resetPassword = this.resetPassword.bind(this);

this.state = {
formError: false,
Expand All @@ -56,15 +57,15 @@ class PasswordForm extends React.Component {
}

componentDidMount() {
if (!canFocusInputOnScreenFocus() || !this.input || !this.props.isVisible) {
if (!canFocusInputOnScreenFocus() || !this.inputPassword || !this.props.isVisible) {
return;
}
this.input.focus();
this.inputPassword.focus();
}

componentDidUpdate(prevProps) {
if (!prevProps.isVisible && this.props.isVisible) {
this.input.focus();
this.inputPassword.focus();
}
if (prevProps.isVisible && !this.props.isVisible && this.state.password) {
this.clearPassword();
Expand All @@ -75,7 +76,15 @@ class PasswordForm extends React.Component {
* Clear Password from the state
*/
clearPassword() {
this.setState({password: ''}, this.input.clear);
this.setState({password: ''}, this.inputPassword.clear);
}

/**
* Trigger the reset password flow and ensure the 2FA input field is reset to avoid it being permanently hidden
*/
resetPassword() {
this.setState({twoFactorAuthCode: ''}, this.input2FA.clear);
Session.resetPassword();
}

/**
Expand Down Expand Up @@ -109,7 +118,7 @@ class PasswordForm extends React.Component {
<>
<View style={[styles.mv3]}>
<TextInput
ref={el => this.input = el}
ref={el => this.inputPassword = el}
label={this.props.translate('common.password')}
secureTextEntry
autoCompleteType={ComponentUtils.PASSWORD_AUTOCOMPLETE_TYPE}
Expand All @@ -124,7 +133,7 @@ class PasswordForm extends React.Component {
<View style={[styles.changeExpensifyLoginLinkContainer]}>
<TouchableOpacity
style={[styles.mt2]}
onPress={Session.resetPassword}
onPress={this.resetPassword}
underlayColor={themeColors.componentBG}
>
<Text style={[styles.link]}>
Expand All @@ -137,6 +146,7 @@ class PasswordForm extends React.Component {
{this.props.account.requiresTwoFactorAuth && (
<View style={[styles.mv3]}>
<TextInput
ref={el => this.input2FA = el}
label={this.props.translate('passwordForm.twoFactorCode')}
value={this.state.twoFactorAuthCode}
placeholder={this.props.translate('passwordForm.requiredWhen2FAEnabled')}
Expand Down