Skip to content
Merged
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
4 changes: 0 additions & 4 deletions src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,8 @@ export default {
currentPassword: 'Current password',
newPassword: 'New password',
newPasswordPrompt: 'New password must be different than your old password, have at least 8 characters,\n1 capital letter, 1 lowercase letter, and 1 number.',
confirmNewPassword: 'Confirm new password',
errors: {
currentPassword: 'Current password is required',
confirmNewPassword: 'Confirm password is required',
newPasswordSameAsOld: 'New password must be different than your old password',
newPassword: 'Your password must have at least 8 characters,\n1 capital letter, 1 lowercase letter, and 1 number.',
},
Expand Down Expand Up @@ -424,9 +422,7 @@ export default {
},
setPasswordPage: {
enterPassword: 'Enter a password',
confirmNewPassword: 'Confirm the password',
setPassword: 'Set password',
passwordsDontMatch: 'Passwords must match',
newPasswordPrompt: 'Your password must have at least 8 characters,\n1 capital letter, 1 lowercase letter, and 1 number.',
passwordFormTitle: 'Welcome back to the New Expensify! Please set your password.',
passwordNotSet: 'We were unable to set your new password correctly.',
Expand Down
4 changes: 0 additions & 4 deletions src/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,8 @@ export default {
currentPassword: 'Contraseña actual',
newPassword: 'Nueva contraseña',
newPasswordPrompt: 'La nueva contraseña debe ser diferente de la antigua, tener al menos 8 caracteres,\n1 letra mayúscula, 1 letra minúscula y 1 número.',
confirmNewPassword: 'Confirma la nueva contraseña',
errors: {
currentPassword: 'Contraseña actual es requerido',
confirmNewPassword: 'Confirma la nueva contraseña es requerido',
newPasswordSameAsOld: 'La nueva contraseña tiene que ser diferente de la antigua',
newPassword: 'Su contraseña debe tener al menos 8 caracteres, \n1 letra mayúscula, 1 letra minúscula y 1 número.',
},
Expand Down Expand Up @@ -424,9 +422,7 @@ export default {
},
setPasswordPage: {
enterPassword: 'Escribe una contraseña',
confirmNewPassword: 'Confirma la contraseña',
setPassword: 'Configura tu contraseña',
passwordsDontMatch: 'Las contraseñas deben coincidir',
newPasswordPrompt: 'La contraseña debe tener al menos 8 caracteres, \n1 letra mayúscula, 1 letra minúscula y 1 número.',
passwordFormTitle: '¡Bienvenido de vuelta al Nuevo Expensify! Por favor, elige una contraseña.',
passwordNotSet: 'No pudimos establecer to contaseña correctamente.',
Expand Down
92 changes: 25 additions & 67 deletions src/pages/settings/NewPasswordForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import withLocalize, {
import CONST from '../../CONST';
import styles from '../../styles/styles';
import ExpensiTextInput from '../../components/ExpensiTextInput';
import InlineErrorText from '../../components/InlineErrorText';

const propTypes = {
/** String to control the first password box in the form */
Expand All @@ -30,16 +29,13 @@ class NewPasswordForm extends React.Component {
super(props);

this.state = {
confirmNewPassword: '',
passwordHintError: false,
shouldShowPasswordConfirmError: false,
};
}

componentDidUpdate(prevProps, prevState) {
const eitherPasswordChanged = (this.props.password !== prevProps.password)
|| this.state.confirmNewPassword !== prevState.confirmNewPassword;
if (eitherPasswordChanged) {
componentDidUpdate(prevProps) {
const passwordChanged = (this.props.password !== prevProps.password);
if (passwordChanged) {
this.props.updateIsFormValid(this.isValidForm());
}
}
Expand All @@ -53,15 +49,6 @@ class NewPasswordForm extends React.Component {
}
}

onBlurConfirmPassword() {
if (this.state.shouldShowPasswordConfirmError) {
return;
}
if (this.state.confirmNewPassword && !this.doPasswordsMatch()) {
this.setState({shouldShowPasswordConfirmError: true});
}
}

isValidPassword() {
return this.props.password.match(CONST.PASSWORD_COMPLEXITY_REGEX_STRING);
}
Expand All @@ -74,63 +61,34 @@ class NewPasswordForm extends React.Component {
return this.state.passwordHintError && this.props.password && !this.isValidPassword();
}

doPasswordsMatch() {
return this.props.password === this.state.confirmNewPassword;
}

isValidForm() {
return this.isValidPassword() && this.doPasswordsMatch();
return this.isValidPassword();
}

showPasswordMatchError() {
return Boolean(
!this.doPasswordsMatch()
&& this.state.shouldShowPasswordConfirmError
&& this.state.confirmNewPassword,
);
}

render() {
return (
<>
<View style={styles.mb6}>
<ExpensiTextInput
label={`${this.props.translate('setPasswordPage.enterPassword')}`}
secureTextEntry
autoCompleteType="password"
textContentType="password"
value={this.props.password}
onChangeText={password => this.props.updatePassword(password)}
onBlur={() => this.onBlurNewPassword()}
/>
<ExpensifyText
style={[
styles.textLabelSupporting,
styles.mt1,
this.isInvalidPassword() && styles.formError,
]}
>
{this.props.translate('setPasswordPage.newPasswordPrompt')}
</ExpensifyText>
</View>
<View style={styles.mb6}>
<ExpensiTextInput
label={`${this.props.translate('setPasswordPage.confirmNewPassword')}*`}
secureTextEntry
autoCompleteType="password"
textContentType="password"
value={this.state.confirmNewPassword}
onChangeText={confirmNewPassword => this.setState({confirmNewPassword})}
onSubmitEditing={() => this.props.onSubmitEditing()}
onBlur={() => this.onBlurConfirmPassword()}
/>
{this.showPasswordMatchError() && (
<InlineErrorText>
{this.props.translate('setPasswordPage.passwordsDontMatch')}
</InlineErrorText>
)}
</View>
</>
<View style={styles.mb6}>
<ExpensiTextInput
label={`${this.props.translate('setPasswordPage.enterPassword')}`}
secureTextEntry
autoCompleteType="password"
textContentType="password"
value={this.props.password}
onChangeText={password => this.props.updatePassword(password)}
onBlur={() => this.onBlurNewPassword()}
onSubmitEditing={() => this.props.onSubmitEditing()}
/>
<ExpensifyText
style={[
styles.textLabelSupporting,
styles.mt1,
this.isInvalidPassword() && styles.formError,
]}
>
{this.props.translate('setPasswordPage.newPasswordPrompt')}
</ExpensifyText>
</View>
);
}
}
Expand Down
29 changes: 2 additions & 27 deletions src/pages/settings/PasswordPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const propTypes = {
/** Success message to display when necessary */
success: PropTypes.string,

/** Whether or not a sign on form is loading (being submitted) */
/** Whether a sign on form is loading (being submitted) */
loading: PropTypes.bool,
}),

Expand All @@ -49,12 +49,9 @@ class PasswordPage extends Component {
this.state = {
currentPassword: '',
newPassword: '',
confirmNewPassword: '',
errors: {
currentPassword: false,
newPassword: false,
confirmNewPassword: false,
confirmPasswordMatch: false,
Comment thread
anthony-hull marked this conversation as resolved.
newPasswordSameAsOld: false,
},
};
Expand All @@ -67,9 +64,7 @@ class PasswordPage extends Component {

this.errorKeysMap = {
currentPassword: 'passwordPage.errors.currentPassword',
confirmNewPassword: 'passwordPage.errors.confirmNewPassword',
newPasswordSameAsOld: 'passwordPage.errors.newPasswordSameAsOld',
confirmPasswordMatch: 'setPasswordPage.passwordsDontMatch',
Comment thread
anthony-hull marked this conversation as resolved.
newPassword: 'passwordPage.errors.newPassword',
};
}
Expand Down Expand Up @@ -125,18 +120,10 @@ class PasswordPage extends Component {
errors.newPassword = true;
}

if (!this.state.confirmNewPassword) {
errors.confirmNewPassword = true;
}

if (this.state.currentPassword && this.state.newPassword && _.isEqual(this.state.currentPassword, this.state.newPassword)) {
errors.newPasswordSameAsOld = true;
}

if (ValidationUtils.isValidPassword(this.state.newPassword) && this.state.confirmNewPassword && !_.isEqual(this.state.newPassword, this.state.confirmNewPassword)) {
errors.confirmPasswordMatch = true;
}

this.setState({errors});
return _.size(errors) === 0;
}
Expand Down Expand Up @@ -199,6 +186,7 @@ class PasswordPage extends Component {
? this.getErrorText('newPasswordSameAsOld')
: this.getErrorText('newPassword')}
onChangeText={text => this.clearErrorAndSetValue('newPassword', text, ['newPasswordSameAsOld'])}
onSubmitEditing={this.submit}
/>
{

Expand All @@ -214,19 +202,6 @@ class PasswordPage extends Component {
)
}
</View>
<View style={styles.mb6}>
<ExpensiTextInput
label={`${this.props.translate('passwordPage.confirmNewPassword')}*`}
secureTextEntry
autoCompleteType="password"
textContentType="password"
value={this.state.confirmNewPassword}
onChangeText={text => this.clearErrorAndSetValue('confirmNewPassword', text, ['confirmPasswordMatch'])}
hasError={this.state.errors.confirmNewPassword || this.state.errors.confirmPasswordMatch}
errorText={this.getErrorText(this.state.errors.confirmNewPassword ? 'confirmNewPassword' : 'confirmPasswordMatch')}
onSubmitEditing={this.validateAndSubmitForm}
/>
</View>
{_.every(this.state.errors, error => !error) && !_.isEmpty(this.props.account.error) && (
<ExpensifyText style={styles.formError}>
{this.props.account.error}
Expand Down