Skip to content
Snippets Groups Projects
Commit 5d29bcdc authored by mashazyu's avatar mashazyu Committed by Sofiya Tepikin
Browse files

Reuse ConfirmWithPassword component in ChangePassword component

parent 95359ce2
No related branches found
No related tags found
No related merge requests found
import React, { Component } from 'react' import React, { Component } from 'react'
import { View } from 'react-native'
import nodejs from 'nodejs-mobile-react-native'
import { shared as sharedLabels } from '../../../i18n/en/labels'
import settings from '../../../i18n/en/settings' import settings from '../../../i18n/en/settings'
import { requestHash } from '../../../db'
import EnterNewPassword from './enter-new-password' import EnterNewPassword from './enter-new-password'
import PasswordField from './password-field'
import SettingsButton from '../settings-button' import SettingsButton from '../settings-button'
import showBackUpReminder from './show-backup-reminder' import showBackUpReminder from './show-backup-reminder'
import checkCurrentPassword from './check-current-password' import ConfirmWithPassword from '../common/confirm-with-password'
export default class ChangePassword extends Component { export default class ChangePassword extends Component {
...@@ -19,35 +14,6 @@ export default class ChangePassword extends Component { ...@@ -19,35 +14,6 @@ export default class ChangePassword extends Component {
enteringCurrentPassword: false, enteringCurrentPassword: false,
enteringNewPassword: false enteringNewPassword: false
} }
nodejs.channel.addListener(
'pre-change-pw-check',
this.openNewPasswordField,
this
)
}
componentWillUnmount() {
nodejs.channel.removeListener('pre-change-pw-check', this.openNewPasswordField)
}
openNewPasswordField = async hash => {
const passwordCorrect = await checkCurrentPassword({
hash,
onTryAgain: () => this.setState({ currentPassword: null }),
onCancel: () => this.setState({
enteringCurrentPassword: false,
currentPassword: null
})
})
if (passwordCorrect) {
this.setState({
currentPassword: null,
enteringNewPassword: true,
enteringCurrentPassword: false
})
}
} }
startChangingPassword = () => { startChangingPassword = () => {
...@@ -56,12 +22,20 @@ export default class ChangePassword extends Component { ...@@ -56,12 +22,20 @@ export default class ChangePassword extends Component {
}) })
} }
handleCurrentPasswordInput = (currentPassword) => { startEnteringNewPassword = () => {
this.setState({ currentPassword }) this.setState({
currentPassword: null,
enteringNewPassword: true,
enteringCurrentPassword: false
})
} }
checkCurrentPassword = () => { cancelConfirmationWithPassword = () => {
requestHash('pre-change-pw-check', this.state.currentPassword) this.setState({
currentPassword: null,
enteringNewPassword: false,
enteringCurrentPassword: false
})
} }
render() { render() {
...@@ -76,19 +50,10 @@ export default class ChangePassword extends Component { ...@@ -76,19 +50,10 @@ export default class ChangePassword extends Component {
if (enteringCurrentPassword) { if (enteringCurrentPassword) {
return ( return (
<View> <ConfirmWithPassword
<PasswordField onSuccess={this.startEnteringNewPassword}
placeholder={labels.enterCurrent} onCancel={this.cancelConfirmationWithPassword}
value={currentPassword} />
onChangeText={this.handleCurrentPasswordInput}
/>
<SettingsButton
onPress={this.checkCurrentPassword}
disabled={!currentPassword}
>
{sharedLabels.unlock}
</SettingsButton>
</View>
) )
} }
...@@ -97,14 +62,12 @@ export default class ChangePassword extends Component { ...@@ -97,14 +62,12 @@ export default class ChangePassword extends Component {
} }
return ( return (
<View> <SettingsButton
<SettingsButton onPress={this.startChangingPassword}
onPress={this.startChangingPassword} disabled={currentPassword}
disabled={currentPassword} >
> {labels.changePassword}
{labels.changePassword} </SettingsButton>
</SettingsButton>
</View>
) )
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment