Bug fix for password field after data is deleted, add notification when there is no data to delete
This commit is contained in:
@@ -2,7 +2,7 @@ import React, { Component } from 'react'
|
||||
import RNFS from 'react-native-fs'
|
||||
import { Alert, ToastAndroid } from 'react-native'
|
||||
|
||||
import { clearDb } from '../../../db'
|
||||
import { clearDb, isDbEmpty } from '../../../db'
|
||||
import { hasEncryptionObservable } from '../../../local-storage'
|
||||
import SettingsButton from '../settings-button'
|
||||
import ConfirmWithPassword from './confirm-with-password'
|
||||
@@ -12,6 +12,8 @@ import settings from '../../../i18n/en/settings'
|
||||
import { shared as sharedLabels } from '../../../i18n/en/labels'
|
||||
import { EXPORT_FILE_NAME } from './constants'
|
||||
|
||||
const exportedFilePath = `${RNFS.DocumentDirectoryPath}/${EXPORT_FILE_NAME}`
|
||||
|
||||
export default class DeleteData extends Component {
|
||||
constructor() {
|
||||
super()
|
||||
@@ -29,41 +31,45 @@ export default class DeleteData extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
alertBeforeDeletion = () => {
|
||||
const { question, message, confirmation } = settings.deleteSegment
|
||||
|
||||
Alert.alert(
|
||||
question,
|
||||
message,
|
||||
[{
|
||||
text: confirmation,
|
||||
onPress: this.onAlertConfirmation
|
||||
}, {
|
||||
text: sharedLabels.cancel,
|
||||
style: 'cancel',
|
||||
onPress: this.cancelConfirmationWithPassword
|
||||
}]
|
||||
)
|
||||
alertBeforeDeletion = async () => {
|
||||
const { question, message, confirmation, errors } = settings.deleteSegment
|
||||
if (isDbEmpty() && !await RNFS.exists(exportedFilePath)) {
|
||||
alertError(errors.noData)
|
||||
} else {
|
||||
Alert.alert(
|
||||
question,
|
||||
message,
|
||||
[{
|
||||
text: confirmation,
|
||||
onPress: this.onAlertConfirmation
|
||||
}, {
|
||||
text: sharedLabels.cancel,
|
||||
style: 'cancel',
|
||||
onPress: this.cancelConfirmationWithPassword
|
||||
}]
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
deleteExportedFile = async () => {
|
||||
const path = `${RNFS.DocumentDirectoryPath}/${EXPORT_FILE_NAME}`
|
||||
const isFileExist = await RNFS.exists(path)
|
||||
if (isFileExist) {
|
||||
await RNFS.unlink(path)
|
||||
if (await RNFS.exists(exportedFilePath)) {
|
||||
await RNFS.unlink(exportedFilePath)
|
||||
}
|
||||
}
|
||||
|
||||
deleteAppData = async () => {
|
||||
const { errors, success } = settings.deleteSegment
|
||||
|
||||
try {
|
||||
clearDb()
|
||||
if (!isDbEmpty()) {
|
||||
clearDb()
|
||||
}
|
||||
await this.deleteExportedFile()
|
||||
ToastAndroid.show(success.message, ToastAndroid.LONG)
|
||||
this.props.onDeleteData()
|
||||
} catch (err) {
|
||||
return alertError(errors.couldNotDeleteFile)
|
||||
alertError(errors.couldNotDeleteFile)
|
||||
}
|
||||
this.cancelConfirmationWithPassword()
|
||||
}
|
||||
|
||||
cancelConfirmationWithPassword = () => {
|
||||
|
||||
@@ -1,51 +1,38 @@
|
||||
import React, { Component } from 'react'
|
||||
import React from 'react'
|
||||
import { ScrollView } from 'react-native'
|
||||
import AppText from '../../app-text'
|
||||
import SettingsSegment from '../settings-segment'
|
||||
import SettingsButton from '../settings-button'
|
||||
import openImportDialogAndImport from './import-dialog'
|
||||
import openShareDialogAndExport from './export-dialog'
|
||||
import { isDbEmpty } from '../../../db'
|
||||
import DeleteData from './delete-data'
|
||||
import labels from '../../../i18n/en/settings'
|
||||
import styles from '../../../styles/index'
|
||||
|
||||
class DataManagement extends Component {
|
||||
constructor() {
|
||||
super()
|
||||
this.state = {
|
||||
isDataEmpty: isDbEmpty()
|
||||
}
|
||||
}
|
||||
onDeleteData = () => {
|
||||
this.setState({
|
||||
isDataEmpty: true
|
||||
})
|
||||
}
|
||||
render() {
|
||||
return (
|
||||
<ScrollView>
|
||||
<SettingsSegment title={labels.export.button}>
|
||||
<AppText>{labels.export.segmentExplainer}</AppText>
|
||||
<SettingsButton onPress={openShareDialogAndExport}>
|
||||
{labels.export.button}
|
||||
</SettingsButton>
|
||||
</SettingsSegment>
|
||||
<SettingsSegment title={labels.import.button}>
|
||||
<AppText>{labels.import.segmentExplainer}</AppText>
|
||||
<SettingsButton onPress={openImportDialogAndImport}>
|
||||
{labels.import.button}
|
||||
</SettingsButton>
|
||||
</SettingsSegment>
|
||||
{!isDbEmpty() && (
|
||||
<SettingsSegment title={labels.deleteSegment.title}>
|
||||
<AppText>{labels.deleteSegment.explainer}</AppText>
|
||||
<DeleteData onDeleteData={this.onDeleteData} />
|
||||
</SettingsSegment>
|
||||
)}
|
||||
</ScrollView>
|
||||
)
|
||||
}
|
||||
const DataManagement = () => {
|
||||
return (
|
||||
<ScrollView>
|
||||
<SettingsSegment title={labels.export.button}>
|
||||
<AppText>{labels.export.segmentExplainer}</AppText>
|
||||
<SettingsButton onPress={openShareDialogAndExport}>
|
||||
{labels.export.button}
|
||||
</SettingsButton>
|
||||
</SettingsSegment>
|
||||
<SettingsSegment title={labels.import.button}>
|
||||
<AppText>{labels.import.segmentExplainer}</AppText>
|
||||
<SettingsButton onPress={openImportDialogAndImport}>
|
||||
{labels.import.button}
|
||||
</SettingsButton>
|
||||
</SettingsSegment>
|
||||
<SettingsSegment
|
||||
title={labels.deleteSegment.title}
|
||||
style={styles.settingsSegmentLast}
|
||||
>
|
||||
<AppText>{labels.deleteSegment.explainer}</AppText>
|
||||
<DeleteData />
|
||||
</SettingsSegment>
|
||||
</ScrollView>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
export default DataManagement
|
||||
export default DataManagement
|
||||
+2
-1
@@ -43,7 +43,8 @@ export default {
|
||||
confirmation: 'Delete app data permanently',
|
||||
errors: {
|
||||
couldNotDeleteFile: 'Could not delete data',
|
||||
postFix: 'No data was deleted or changed'
|
||||
postFix: 'No data was deleted or changed',
|
||||
noData: 'There is no data to delete'
|
||||
},
|
||||
success: {
|
||||
message: 'App data successfully deleted'
|
||||
|
||||
Reference in New Issue
Block a user