Add import error postfix and extract more labels

This commit is contained in:
Julia Friesel
2018-08-16 08:48:46 +02:00
parent b07a2c8a53
commit 4b227d82d4
3 changed files with 105 additions and 105 deletions
+11 -2
View File
@@ -1,6 +1,8 @@
export const settings = {
shared: {
cancel: 'Cancel'
cancel: 'Cancel',
errorTitle: 'Error',
successTitle: 'Success'
},
export: {
errors: {
@@ -19,6 +21,13 @@ export const settings = {
1. Keep existing cycle days and replace only the ones in the import file.
2. Delete all existing cycle days and import cycle days from file.`,
replaceOption: 'Import and replace',
deleteOption: 'Import and delete existing'
deleteOption: 'Import and delete existing',
errors: {
couldNotOpenFile: 'Could not open file',
postFix: 'No data was imported or changed'
},
success: {
message: 'Data successfully imported'
}
}
}
+9 -4
View File
@@ -99,17 +99,22 @@ async function getFileContentAndImport({ deleteExisting }) {
try {
fileContent = await rnfs.readFile(fileInfo.uri, 'utf8')
} catch (err) {
return alertError('Could not open file')
return importError(labels.import.errors.couldNotOpenFile)
}
try {
await importCsv(fileContent, deleteExisting)
Alert.alert('Success', 'Data successfully imported')
Alert.alert(labels.import.success.title, labels.import.success.message)
} catch(err) {
alertError(err.message)
importError(err.message)
}
}
function alertError(msg) {
Alert.alert('Error', msg)
Alert.alert(labels.shared.errorTitle, msg)
}
function importError(msg) {
const postFixed = `${msg}\n\n${labels.import.errors.postFix}`
alertError(postFixed)
}