Chore/make function components 2

This commit is contained in:
Sofiya Tepikin
2022-09-11 08:47:43 +00:00
parent c6eee43138
commit 4a69cbf4cf
5 changed files with 207 additions and 274 deletions
+27 -34
View File
@@ -1,4 +1,4 @@
import React, { Component } from 'react'
import React, { useState } from 'react'
import PropTypes from 'prop-types'
import Button from '../../common/button'
@@ -8,42 +8,35 @@ import showBackUpReminder from './show-backup-reminder'
import settings from '../../../i18n/en/settings'
export default class CreatePassword extends Component {
static propTypes = {
changeEncryptionAndRestart: PropTypes.func,
const CreatePassword = ({ changeEncryptionAndRestart }) => {
const [isSettingPassword, setIsSettingPassword] = useState(false)
const startSettingPassword = () => {
showBackUpReminder(
() => {
setIsSettingPassword(true)
},
() => {}
)
}
constructor() {
super()
const labels = settings.passwordSettings
this.state = { isSettingPassword: false }
if (!isSettingPassword) {
return (
<Button isCTA onPress={startSettingPassword}>
{labels.setPassword}
</Button>
)
}
toggleSettingPassword = () => {
const { isSettingPassword } = this.state
this.setState({ isSettingPassword: !isSettingPassword })
}
startSettingPassword = () => {
showBackUpReminder(this.toggleSettingPassword, () => {})
}
render() {
const { isSettingPassword } = this.state
const labels = settings.passwordSettings
if (!isSettingPassword) {
return (
<Button isCTA onPress={this.startSettingPassword}>
{labels.setPassword}
</Button>
)
} else {
return (
<EnterNewPassword
changeEncryptionAndRestart={this.props.changeEncryptionAndRestart}
/>
)
}
}
return (
<EnterNewPassword changeEncryptionAndRestart={changeEncryptionAndRestart} />
)
}
CreatePassword.propTypes = {
changeEncryptionAndRestart: PropTypes.func,
}
export default CreatePassword