Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 56c783020d | |||
| 43106f0081 |
@@ -2,12 +2,7 @@ import React, { useState } from 'react'
|
||||
|
||||
import AppLoadingView from '../../common/app-loading'
|
||||
import AppPage from '../../common/app-page'
|
||||
import AppText from '../../common/app-text'
|
||||
import Segment from '../../common/segment'
|
||||
|
||||
import DeleteData from './delete-data'
|
||||
|
||||
import labels from '../../../i18n/en/settings'
|
||||
import DeleteData from './DeleteData'
|
||||
import ImportData from './ImportData'
|
||||
import ExportData from './ExportData'
|
||||
|
||||
@@ -27,13 +22,10 @@ const DataManagement = () => {
|
||||
resetIsDeletingData={() => setIsDeletingData(false)}
|
||||
setIsLoading={setIsLoading}
|
||||
/>
|
||||
<Segment title={labels.deleteSegment.title} last>
|
||||
<AppText>{labels.deleteSegment.explainer}</AppText>
|
||||
<DeleteData
|
||||
isDeletingData={isDeletingData}
|
||||
onStartDeletion={() => setIsDeletingData(true)}
|
||||
/>
|
||||
</Segment>
|
||||
<DeleteData
|
||||
isDeletingData={isDeletingData}
|
||||
onStartDeletion={() => setIsDeletingData(true)}
|
||||
/>
|
||||
</AppPage>
|
||||
)
|
||||
}
|
||||
|
||||
+19
-14
@@ -11,9 +11,10 @@ import alertError from '../common/alert-error'
|
||||
import { clearDb, isDbEmpty } from '../../../db'
|
||||
import { showToast } from '../../helpers/general'
|
||||
import { hasEncryptionObservable } from '../../../local-storage'
|
||||
import settings from '../../../i18n/en/settings'
|
||||
import { shared as sharedLabels } from '../../../i18n/en/labels'
|
||||
import { EXPORT_FILE_NAME } from './constants'
|
||||
import Segment from '../../common/segment'
|
||||
import AppText from '../../common/app-text'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
const exportedFilePath = `${RNFS.DocumentDirectoryPath}/${EXPORT_FILE_NAME}`
|
||||
|
||||
@@ -22,6 +23,10 @@ const DeleteData = ({ onStartDeletion, isDeletingData }) => {
|
||||
const [isConfirmingWithPassword, setIsConfirmingWithPassword] =
|
||||
useState(false)
|
||||
|
||||
const { t } = useTranslation(null, {
|
||||
keyPrefix: 'hamburgerMenu.settings.data.delete',
|
||||
})
|
||||
|
||||
const onAlertConfirmation = () => {
|
||||
onStartDeletion()
|
||||
if (isPasswordSet) {
|
||||
@@ -32,17 +37,16 @@ const DeleteData = ({ onStartDeletion, isDeletingData }) => {
|
||||
}
|
||||
|
||||
const alertBeforeDeletion = async () => {
|
||||
const { question, message, confirmation, errors } = settings.deleteSegment
|
||||
if (isDbEmpty() && !(await RNFS.exists(exportedFilePath))) {
|
||||
alertError(errors.noData)
|
||||
alertError(t('error.noData'))
|
||||
} else {
|
||||
Alert.alert(question, message, [
|
||||
Alert.alert(t('dialog.title'), t('dialog.message'), [
|
||||
{
|
||||
text: confirmation,
|
||||
text: t('dialog.delete'),
|
||||
onPress: onAlertConfirmation,
|
||||
},
|
||||
{
|
||||
text: sharedLabels.cancel,
|
||||
text: t('dialog.cancel'),
|
||||
style: 'cancel',
|
||||
onPress: cancelConfirmationWithPassword,
|
||||
},
|
||||
@@ -57,16 +61,14 @@ const DeleteData = ({ onStartDeletion, isDeletingData }) => {
|
||||
}
|
||||
|
||||
const deleteAppData = async () => {
|
||||
const { errors, success } = settings.deleteSegment
|
||||
|
||||
try {
|
||||
if (!isDbEmpty()) {
|
||||
clearDb()
|
||||
}
|
||||
await deleteExportedFile()
|
||||
showToast(success.message)
|
||||
showToast(t('success.message'))
|
||||
} catch (err) {
|
||||
alertError(errors.couldNotDeleteFile)
|
||||
alertError(t('error.delete'))
|
||||
}
|
||||
cancelConfirmationWithPassword()
|
||||
}
|
||||
@@ -85,9 +87,12 @@ const DeleteData = ({ onStartDeletion, isDeletingData }) => {
|
||||
}
|
||||
|
||||
return (
|
||||
<Button isCTA onPress={alertBeforeDeletion}>
|
||||
{settings.deleteSegment.title}
|
||||
</Button>
|
||||
<Segment title={t('title')} last>
|
||||
<AppText>{t('subTitle')}</AppText>
|
||||
<Button isCTA onPress={alertBeforeDeletion}>
|
||||
{t('title')}
|
||||
</Button>
|
||||
</Segment>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -81,6 +81,23 @@
|
||||
},
|
||||
"settings": {
|
||||
"data": {
|
||||
"delete": {
|
||||
"dialog": {
|
||||
"cancel": "Cancel",
|
||||
"delete": "Delete app data permanently",
|
||||
"message": "Please note that deletion of the app data is permanent and irreversible. We recommend exporting existing data before deletion.",
|
||||
"title": "Do you want to delete app data from this phone?"
|
||||
},
|
||||
"error": {
|
||||
"delete": "Could not delete data",
|
||||
"noData": "There is no data to delete"
|
||||
},
|
||||
"subTitle": "Delete app data from this phone",
|
||||
"success": {
|
||||
"message": "App data successfully deleted"
|
||||
},
|
||||
"title": "Delete app data"
|
||||
},
|
||||
"export": {
|
||||
"button": "Export data",
|
||||
"error": {
|
||||
|
||||
@@ -19,22 +19,6 @@ export default {
|
||||
text: '',
|
||||
},
|
||||
},
|
||||
deleteSegment: {
|
||||
title: 'Delete app data',
|
||||
explainer: 'Delete app data from this phone',
|
||||
question: 'Do you want to delete app data from this phone?',
|
||||
message:
|
||||
'Please note that deletion of the app data is permanent and irreversible. We recommend exporting existing data before deletion.',
|
||||
confirmation: 'Delete app data permanently',
|
||||
errors: {
|
||||
couldNotDeleteFile: 'Could not delete data',
|
||||
postFix: 'No data was deleted or changed',
|
||||
noData: 'There is no data to delete',
|
||||
},
|
||||
success: {
|
||||
message: 'App data successfully deleted',
|
||||
},
|
||||
},
|
||||
tempScale: {
|
||||
segmentTitle: 'Temperature scale',
|
||||
segmentExplainer:
|
||||
|
||||
Reference in New Issue
Block a user