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 = () => {
|
||||
|
||||
Reference in New Issue
Block a user