Add import error postfix and extract more labels
This commit is contained in:
+11
-2
@@ -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'
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
Reference in New Issue
Block a user