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