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

Introduces PasswordPrompt component redesign

parent cbe9f394
No related branches found
No related tags found
No related merge requests found
import React, { Component } from 'react' import React, { Component } from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import { View, TextInput, TouchableOpacity, 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 { saveEncryptionFlag } from '../local-storage'
import AppText from './common/app-text' import AppPage from './common/app-page'
import AppTextInput from './common/app-text-input'
import Button from './common/button'
import Header from './header' import Header from './header'
import styles from '../styles'
import { passwordPrompt as labels, shared, menuTitles } from '../i18n/en/labels' import { saveEncryptionFlag } from '../local-storage'
import { requestHash, deleteDbAndOpenNew, openDb } from '../db' import { requestHash, deleteDbAndOpenNew, openDb } from '../db'
import { passwordPrompt as labels, shared } from '../i18n/en/labels'
import { Containers, Spacing } from '../styles/redesign'
const cancelButton = { text: shared.cancel, style: 'cancel' }
export default class PasswordPrompt extends Component { export default class PasswordPrompt extends Component {
static propTypes = { static propTypes = {
...@@ -16,17 +22,40 @@ export default class PasswordPrompt extends Component { ...@@ -16,17 +22,40 @@ export default class PasswordPrompt extends Component {
constructor(props) { constructor(props) {
super(props) super(props)
this.state = { this.state = { password: null }
password: null
nodejs.channel.addListener('check-pw', this.passHashToDb, this)
}
componentWillUnmount() {
nodejs.channel.removeListener('check-pw', this.passHashToDb)
} }
nodejs.channel.addListener( onConfirmDeletion = async () => {
'check-pw', Alert.alert(
this.passHashToDb, labels.deleteDatabaseTitle,
this labels.deleteDatabaseExplainer,
[cancelButton, { text: labels.deleteData, onPress: this.onDeleteData}]
) )
} }
onDeleteData = () => {
Alert.alert(
labels.areYouSureTitle,
labels.areYouSure,
[cancelButton, {
text: labels.reallyDeleteData,
onPress: this.onDeleteDataConfirmation
}]
)
}
onDeleteDataConfirmation = async () => {
await deleteDbAndOpenNew()
await saveEncryptionFlag(false)
this.props.enableShowApp()
}
passHashToDb = async hash => { passHashToDb = async hash => {
const connected = await openDb(hash) const connected = await openDb(hash)
if (!connected) { if (!connected) {
...@@ -35,7 +64,7 @@ export default class PasswordPrompt extends Component { ...@@ -35,7 +64,7 @@ export default class PasswordPrompt extends Component {
shared.incorrectPasswordMessage, shared.incorrectPasswordMessage,
[{ [{
text: shared.tryAgain, text: shared.tryAgain,
onPress: () => this.setState({ password: null }) onPress: this.setPassword(null)
}] }]
) )
return return
...@@ -43,71 +72,53 @@ export default class PasswordPrompt extends Component { ...@@ -43,71 +72,53 @@ export default class PasswordPrompt extends Component {
this.props.enableShowApp() this.props.enableShowApp()
} }
confirmDeletion = async () => { setPassword = (password) => {
Alert.alert( this.setState({ password })
labels.deleteDatabaseTitle,
labels.deleteDatabaseExplainer,
[{
text: shared.cancel,
style: 'cancel'
}, {
text: labels.deleteData,
onPress: () => {
Alert.alert(
labels.areYouSureTitle,
labels.areYouSure,
[{
text: shared.cancel,
style: 'cancel'
}, {
text: labels.reallyDeleteData,
onPress: async () => {
await deleteDbAndOpenNew()
await saveEncryptionFlag(false)
this.props.enableShowApp()
}
}]
)
}
}]
)
} }
componentWillUnmount() { unlockApp = () => {
nodejs.channel.removeListener('check-pw', this.passHashToDb) requestHash('check-pw', this.state.password)
} }
render() { render() {
const { password } = this.state
const isPasswordEntered = password && password.length > 0
return ( return (
<View flex={1}> <React.Fragment>
<Header title={menuTitles.PasswordPrompt.toLowerCase()} /> <Header isSideMenuEnabled={false} />
<View style={styles.passwordPromptPage}> <AppPage contentContainerStyle={styles.contentContainer}>
<TextInput <AppTextInput
onChangeText={val => this.setState({ password: val })} onChangeText={this.setPassword}
style={styles.passwordPromptField}
secureTextEntry={true} secureTextEntry={true}
placeholder={labels.enterPassword} placeholder={labels.enterPassword}
/> />
<TouchableOpacity <View style={styles.containerButtons}>
style={styles.passwordPromptButton} <Button
onPress={() => { disabled={!isPasswordEntered}
requestHash('check-pw', this.state.password) isCTA={isPasswordEntered}
}} onPress={this.unlockApp}
disabled={!this.state.password}
> >
<AppText style={styles.passwordPromptButtonText}>
{labels.title} {labels.title}
</AppText> </Button>
</TouchableOpacity> <Button onPress={this.onConfirmDeletion}>
<TouchableOpacity
onPress={this.confirmDeletion}
>
<AppText style={styles.passwordPromptForgotPasswordText}>
{labels.forgotPassword} {labels.forgotPassword}
</AppText> </Button>
</TouchableOpacity>
</View>
</View> </View>
</AppPage>
</React.Fragment>
) )
} }
} }
const styles = StyleSheet.create({
contentContainer: {
flex: 1,
justifyContent: 'center',
marginHorizontal: Spacing.base
},
containerButtons: {
...Containers.rowContainer,
justifyContent: 'space-around'
}
})
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment