622 Use translation library for delete settings
This commit is contained in:
@@ -2,12 +2,8 @@ import React, { useState } from 'react'
|
|||||||
|
|
||||||
import AppLoadingView from '../../common/app-loading'
|
import AppLoadingView from '../../common/app-loading'
|
||||||
import AppPage from '../../common/app-page'
|
import AppPage from '../../common/app-page'
|
||||||
import AppText from '../../common/app-text'
|
|
||||||
import Segment from '../../common/segment'
|
|
||||||
|
|
||||||
import DeleteData from './delete-data'
|
import DeleteData from './delete-data'
|
||||||
|
|
||||||
import labels from '../../../i18n/en/settings'
|
|
||||||
import ImportData from './ImportData'
|
import ImportData from './ImportData'
|
||||||
import ExportData from './ExportData'
|
import ExportData from './ExportData'
|
||||||
|
|
||||||
@@ -27,13 +23,10 @@ const DataManagement = () => {
|
|||||||
resetIsDeletingData={() => setIsDeletingData(false)}
|
resetIsDeletingData={() => setIsDeletingData(false)}
|
||||||
setIsLoading={setIsLoading}
|
setIsLoading={setIsLoading}
|
||||||
/>
|
/>
|
||||||
<Segment title={labels.deleteSegment.title} last>
|
|
||||||
<AppText>{labels.deleteSegment.explainer}</AppText>
|
|
||||||
<DeleteData
|
<DeleteData
|
||||||
isDeletingData={isDeletingData}
|
isDeletingData={isDeletingData}
|
||||||
onStartDeletion={() => setIsDeletingData(true)}
|
onStartDeletion={() => setIsDeletingData(true)}
|
||||||
/>
|
/>
|
||||||
</Segment>
|
|
||||||
</AppPage>
|
</AppPage>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,9 +11,10 @@ import alertError from '../common/alert-error'
|
|||||||
import { clearDb, isDbEmpty } from '../../../db'
|
import { clearDb, isDbEmpty } from '../../../db'
|
||||||
import { showToast } from '../../helpers/general'
|
import { showToast } from '../../helpers/general'
|
||||||
import { hasEncryptionObservable } from '../../../local-storage'
|
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 { 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}`
|
const exportedFilePath = `${RNFS.DocumentDirectoryPath}/${EXPORT_FILE_NAME}`
|
||||||
|
|
||||||
@@ -22,6 +23,10 @@ const DeleteData = ({ onStartDeletion, isDeletingData }) => {
|
|||||||
const [isConfirmingWithPassword, setIsConfirmingWithPassword] =
|
const [isConfirmingWithPassword, setIsConfirmingWithPassword] =
|
||||||
useState(false)
|
useState(false)
|
||||||
|
|
||||||
|
const { t } = useTranslation(null, {
|
||||||
|
keyPrefix: 'hamburgerMenu.settings.data.delete',
|
||||||
|
})
|
||||||
|
|
||||||
const onAlertConfirmation = () => {
|
const onAlertConfirmation = () => {
|
||||||
onStartDeletion()
|
onStartDeletion()
|
||||||
if (isPasswordSet) {
|
if (isPasswordSet) {
|
||||||
@@ -32,17 +37,16 @@ const DeleteData = ({ onStartDeletion, isDeletingData }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const alertBeforeDeletion = async () => {
|
const alertBeforeDeletion = async () => {
|
||||||
const { question, message, confirmation, errors } = settings.deleteSegment
|
|
||||||
if (isDbEmpty() && !(await RNFS.exists(exportedFilePath))) {
|
if (isDbEmpty() && !(await RNFS.exists(exportedFilePath))) {
|
||||||
alertError(errors.noData)
|
alertError(t('error.noData'))
|
||||||
} else {
|
} else {
|
||||||
Alert.alert(question, message, [
|
Alert.alert(t('dialog.title'), t('dialog.message'), [
|
||||||
{
|
{
|
||||||
text: confirmation,
|
text: t('dialog.delete'),
|
||||||
onPress: onAlertConfirmation,
|
onPress: onAlertConfirmation,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
text: sharedLabels.cancel,
|
text: t('dialog.cancel'),
|
||||||
style: 'cancel',
|
style: 'cancel',
|
||||||
onPress: cancelConfirmationWithPassword,
|
onPress: cancelConfirmationWithPassword,
|
||||||
},
|
},
|
||||||
@@ -57,16 +61,14 @@ const DeleteData = ({ onStartDeletion, isDeletingData }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const deleteAppData = async () => {
|
const deleteAppData = async () => {
|
||||||
const { errors, success } = settings.deleteSegment
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!isDbEmpty()) {
|
if (!isDbEmpty()) {
|
||||||
clearDb()
|
clearDb()
|
||||||
}
|
}
|
||||||
await deleteExportedFile()
|
await deleteExportedFile()
|
||||||
showToast(success.message)
|
showToast(t('success.message'))
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
alertError(errors.couldNotDeleteFile)
|
alertError(t('error.delete'))
|
||||||
}
|
}
|
||||||
cancelConfirmationWithPassword()
|
cancelConfirmationWithPassword()
|
||||||
}
|
}
|
||||||
@@ -85,9 +87,12 @@ const DeleteData = ({ onStartDeletion, isDeletingData }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<Segment title={t('title')} last>
|
||||||
|
<AppText>{t('subTitle')}</AppText>
|
||||||
<Button isCTA onPress={alertBeforeDeletion}>
|
<Button isCTA onPress={alertBeforeDeletion}>
|
||||||
{settings.deleteSegment.title}
|
{t('title')}
|
||||||
</Button>
|
</Button>
|
||||||
|
</Segment>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -81,6 +81,23 @@
|
|||||||
},
|
},
|
||||||
"settings": {
|
"settings": {
|
||||||
"data": {
|
"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": {
|
"export": {
|
||||||
"button": "Export data",
|
"button": "Export data",
|
||||||
"error": {
|
"error": {
|
||||||
|
|||||||
@@ -19,22 +19,6 @@ export default {
|
|||||||
text: '',
|
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: {
|
tempScale: {
|
||||||
segmentTitle: 'Temperature scale',
|
segmentTitle: 'Temperature scale',
|
||||||
segmentExplainer:
|
segmentExplainer:
|
||||||
|
|||||||
Reference in New Issue
Block a user