Introduces password management section redesign

This commit is contained in:
mashazyu
2020-03-25 16:26:57 +01:00
committed by Sofiya Tepikin
parent 842e8a2a24
commit a68ec248b0
6 changed files with 108 additions and 125 deletions
+10 -13
View File
@@ -1,16 +1,17 @@
import React, { Component } from 'react' import React, { Component } from 'react'
import { View } from 'react-native'
import settings from '../../../i18n/en/settings' import Button from '../../common/button'
import EnterNewPassword from './enter-new-password' import EnterNewPassword from './enter-new-password'
import SettingsButton from '../shared/settings-button'
import showBackUpReminder from './show-backup-reminder' import showBackUpReminder from './show-backup-reminder'
import settings from '../../../i18n/en/settings'
export default class CreatePassword extends Component { export default class CreatePassword extends Component {
constructor() { constructor() {
super() super()
this.state = {
isSettingPassword: false this.state = { isSettingPassword: false }
}
} }
toggleSettingPassword = () => { toggleSettingPassword = () => {
@@ -23,18 +24,14 @@ export default class CreatePassword extends Component {
} }
render () { render () {
const { const { isSettingPassword } = this.state
isSettingPassword
} = this.state
const labels = settings.passwordSettings const labels = settings.passwordSettings
if (!isSettingPassword) { if (!isSettingPassword) {
return ( return (
<View> <Button isCTA onPress={this.startSettingPassword}>
<SettingsButton onPress={this.startSettingPassword}>
{labels.setPassword} {labels.setPassword}
</SettingsButton> </Button>
</View>
) )
} else { } else {
return <EnterNewPassword /> return <EnterNewPassword />
+13 -14
View File
@@ -1,17 +1,22 @@
import React, { Component } from 'react' import React, { Component } from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import labels from '../../../i18n/en/settings' import Button from '../../common/button'
import { changeEncryptionAndRestartApp } from '../../../db'
import ConfirmWithPassword from '../shared/confirm-with-password' import ConfirmWithPassword from '../shared/confirm-with-password'
import SettingsButton from '../shared/settings-button'
import { changeEncryptionAndRestartApp } from '../../../db'
import labels from '../../../i18n/en/settings'
export default class DeletePassword extends Component { export default class DeletePassword extends Component {
static propTypes = {
onStartDelete: PropTypes.func,
onCancelDelete: PropTypes.func
}
constructor() { constructor() {
super() super()
this.state = {
enteringCurrentPassword: false this.state = { enteringCurrentPassword: false }
}
} }
startConfirmWithPassword = () => { startConfirmWithPassword = () => {
@@ -29,7 +34,6 @@ export default class DeletePassword extends Component {
} }
render() { render() {
const { enteringCurrentPassword } = this.state const { enteringCurrentPassword } = this.state
if (enteringCurrentPassword) { if (enteringCurrentPassword) {
@@ -42,14 +46,9 @@ export default class DeletePassword extends Component {
} }
return ( return (
<SettingsButton onPress={this.startConfirmWithPassword} > <Button isCTA onPress={this.startConfirmWithPassword}>
{labels.passwordSettings.deletePassword} {labels.passwordSettings.deletePassword}
</SettingsButton> </Button>
) )
} }
} }
DeletePassword.propTypes = {
onStartDelete: PropTypes.func,
onCancelDelete: PropTypes.func
}
@@ -1,13 +1,13 @@
import React, { Component } from 'react' import React, { Component } from 'react'
import { View } from 'react-native' import { StyleSheet } from 'react-native'
import nodejs from 'nodejs-mobile-react-native' import nodejs from 'nodejs-mobile-react-native'
import { requestHash, changeEncryptionAndRestartApp } from '../../../db'
import AppText from '../../common/app-text' import AppText from '../../common/app-text'
import PasswordField from '../shared/password-field' import AppTextInput from '../../common/app-text-input'
import SettingsButton from '../shared/settings-button' import Button from '../../common/button'
import styles from '../../../styles' import { requestHash, changeEncryptionAndRestartApp } from '../../../db'
import { Colors, Spacing } from '../../../styles/redesign'
import settings from '../../../i18n/en/settings' import settings from '../../../i18n/en/settings'
const LISTENER_TYPE = 'create-or-change-pw' const LISTENER_TYPE = 'create-or-change-pw'
@@ -36,9 +36,7 @@ export default class EnterNewPassword extends Component {
if (this.comparePasswords()) { if (this.comparePasswords()) {
requestHash(LISTENER_TYPE, this.state.password) requestHash(LISTENER_TYPE, this.state.password)
} else { } else {
this.setState({ this.setState({ shouldShowErrorMessage: true })
shouldShowErrorMessage: true
})
} }
} }
@@ -58,40 +56,40 @@ export default class EnterNewPassword extends Component {
const { const {
password, password,
passwordConfirmation, passwordConfirmation,
shouldShowErrorMessage, shouldShowErrorMessage
} = this.state } = this.state
const labels = settings.passwordSettings const labels = settings.passwordSettings
const isButtonActive =
const isSaveButtonDisabled = Boolean(password.length && passwordConfirmation.length)
!password.length ||
!passwordConfirmation.length
return ( return (
<View> <React.Fragment>
<PasswordField <AppTextInput
placeholder={labels.enterNew}
value={password}
onChangeText={this.handlePasswordInput} onChangeText={this.handlePasswordInput}
placeholder={labels.enterNew}
textContentType="password"
value={password}
/> />
<PasswordField <AppTextInput
autoFocus={false}
placeholder={labels.confirmPassword}
value={passwordConfirmation}
onChangeText={this.handleConfirmationInput} onChangeText={this.handleConfirmationInput}
placeholder={labels.confirmPassword}
textContentType="password"
value={passwordConfirmation}
/> />
{ {shouldShowErrorMessage &&
shouldShowErrorMessage && <AppText style={styles.error}>{labels.passwordsDontMatch}</AppText>
<AppText style={styles.errorMessage}>
{labels.passwordsDontMatch}
</AppText>
} }
<SettingsButton <Button isCTA={isButtonActive} isSmall onPress={this.savePassword}>
onPress={this.savePassword}
disabled={isSaveButtonDisabled}
>
{labels.savePassword} {labels.savePassword}
</SettingsButton> </Button>
</View> </React.Fragment>
) )
} }
} }
const styles = StyleSheet.create({
error: {
color: Colors.orange,
marginTop: Spacing.base
}
})
+11 -9
View File
@@ -1,18 +1,20 @@
import React, { Component } from 'react' import React, { Component } from 'react'
import { ScrollView } from 'react-native'
import AppPage from '../../common/app-page'
import AppText from '../../common/app-text'
import Segment from '../../common/segment'
import CreatePassword from './create' import CreatePassword from './create'
import ChangePassword from './update' import ChangePassword from './update'
import DeletePassword from './delete' import DeletePassword from './delete'
import Segment from '../../common/segment'
import AppText from '../../common/app-text' import { hasEncryptionObservable } from '../../../local-storage'
import {
hasEncryptionObservable
} from '../../../local-storage'
import labels from '../../../i18n/en/settings' import labels from '../../../i18n/en/settings'
export default class PasswordSetting extends Component { export default class PasswordSetting extends Component {
constructor(props) { constructor(props) {
super(props) super(props)
this.state = { this.state = {
isPasswordSet: hasEncryptionObservable.value, isPasswordSet: hasEncryptionObservable.value,
isChangingPassword: false, isChangingPassword: false,
@@ -51,8 +53,8 @@ export default class PasswordSetting extends Component {
} = labels.passwordSettings } = labels.passwordSettings
return ( return (
<ScrollView> <AppPage>
<Segment title={title}> <Segment title={title} last>
<AppText> <AppText>
{isPasswordSet ? explainerEnabled : explainerDisabled} {isPasswordSet ? explainerEnabled : explainerDisabled}
</AppText> </AppText>
@@ -73,7 +75,7 @@ export default class PasswordSetting extends Component {
/> />
)} )}
</Segment> </Segment>
</ScrollView> </AppPage>
) )
} }
} }
+12 -14
View File
@@ -1,16 +1,23 @@
import React, { Component } from 'react' import React, { Component } from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import settings from '../../../i18n/en/settings' import Button from '../../common/button'
import EnterNewPassword from './enter-new-password' import EnterNewPassword from './enter-new-password'
import SettingsButton from '../shared/settings-button'
import showBackUpReminder from './show-backup-reminder' import showBackUpReminder from './show-backup-reminder'
import ConfirmWithPassword from '../shared/confirm-with-password' import ConfirmWithPassword from '../shared/confirm-with-password'
import settings from '../../../i18n/en/settings'
export default class ChangePassword extends Component { export default class ChangePassword extends Component {
static propTypes = {
onStartChange: PropTypes.func,
onCancelChange: PropTypes.func
}
constructor() { constructor() {
super() super()
this.state = { this.state = {
currentPassword: null, currentPassword: null,
enteringCurrentPassword: false, enteringCurrentPassword: false,
@@ -48,14 +55,13 @@ export default class ChangePassword extends Component {
} }
render() { render() {
const { const {
enteringCurrentPassword, enteringCurrentPassword,
enteringNewPassword, enteringNewPassword,
currentPassword currentPassword
} = this.state } = this.state
const labels = settings.passwordSettings const labels = settings.passwordSettings
const isDisabled = currentPassword !== null
if (enteringCurrentPassword) { if (enteringCurrentPassword) {
return ( return (
@@ -71,17 +77,9 @@ export default class ChangePassword extends Component {
} }
return ( return (
<SettingsButton <Button disabled={isDisabled} isCTA onPress={this.startChangingPassword}>
onPress={this.startChangingPassword}
disabled={currentPassword}
>
{labels.changePassword} {labels.changePassword}
</SettingsButton> </Button>
) )
} }
} }
ChangePassword.propTypes = {
onStartChange: PropTypes.func,
onCancelChange: PropTypes.func
}
@@ -1,27 +1,22 @@
import React, { Component } from 'react' import React, { Component } from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import { View, Alert } from 'react-native' import { Alert, StyleSheet, View } from 'react-native'
import nodejs from 'nodejs-mobile-react-native' import nodejs from 'nodejs-mobile-react-native'
import AppTextInput from '../../common/app-text-input'
import Button from '../../common/button'
import { requestHash, openDb } from '../../../db' import { requestHash, openDb } from '../../../db'
import { Containers } from '../../../styles/redesign'
import PasswordField from './password-field'
import SettingsButton from '../shared/settings-button'
import settings from '../../../i18n/en/settings' import settings from '../../../i18n/en/settings'
import { shared } from '../../../i18n/en/labels' import { shared } from '../../../i18n/en/labels'
export default class ConfirmWithPassword extends Component { export default class ConfirmWithPassword extends Component {
constructor() { constructor() {
super() super()
this.state = {
password: null this.state = { password: null }
} nodejs.channel.addListener('password-check', this.checkPassword, this)
nodejs.channel.addListener(
'password-check',
this.checkPassword,
this
)
} }
componentWillUnmount() { componentWillUnmount() {
@@ -67,36 +62,24 @@ export default class ConfirmWithPassword extends Component {
render() { render() {
const { password } = this.state const { password } = this.state
const labels = settings.passwordSettings const labels = settings.passwordSettings
const isCTA = password !== null
return ( return (
<View> <React.Fragment>
<PasswordField <AppTextInput
onChangeText={this.handlePasswordInput}
placeholder={labels.enterCurrent} placeholder={labels.enterCurrent}
value={password} value={password}
onChangeText={this.handlePasswordInput}
/> />
<View style={{ <View style={styles.container}>
flex: 1, <Button isSmall onPress={this.props.onCancel}>
flexDirection: 'row',
justifyContent: 'space-between'
}}>
<SettingsButton
onPress={this.props.onCancel}
secondary
>
{shared.cancel} {shared.cancel}
</SettingsButton> </Button>
<SettingsButton <Button isCTA={isCTA} isSmall onPress={this.initPasswordCheck}>
onPress={this.initPasswordCheck}
disabled={!password}
style={{
flex: 1,
}}
>
{shared.confirmToProceed} {shared.confirmToProceed}
</SettingsButton> </Button>
</View>
</View> </View>
</React.Fragment>
) )
} }
@@ -106,3 +89,9 @@ ConfirmWithPassword.propTypes = {
onSuccess: PropTypes.func, onSuccess: PropTypes.func,
onCancel: PropTypes.func onCancel: PropTypes.func
} }
const styles = StyleSheet.create({
container: {
...Containers.rowContainer
}
})