Skip to content
Snippets Groups Projects
Commit d3d72a39 authored by Julia Friesel's avatar Julia Friesel
Browse files

Extract labels

parent 77bda6bf
No related branches found
No related tags found
No related merge requests found
export const settings = { export const settings = {
errors: { shared: {
noData: 'There is no data to export', cancel: 'Cancel'
couldNotConvert: 'Could not convert data to CSV',
problemSharing: 'There was a problem sharing the data export file'
}, },
exportTitle: 'My Drip data export', export: {
exportSubject: 'My Drip data export', errors: {
exportLabel: 'Export data', noData: 'There is no data to export',
importLabel: 'Import data' couldNotConvert: 'Could not convert data to CSV',
problemSharing: 'There was a problem sharing the data export file'
},
title: 'My Drip data export',
subject: 'My Drip data export',
button: 'Export data',
},
import: {
button: 'Import data',
title: 'Keep existing data?',
message: `There are two options for the import:
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'
}
} }
\ No newline at end of file
...@@ -22,13 +22,27 @@ export default class Settings extends Component { ...@@ -22,13 +22,27 @@ export default class Settings extends Component {
<View style={styles.homeButton}> <View style={styles.homeButton}>
<Button <Button
onPress={ openShareDialogAndExport } onPress={ openShareDialogAndExport }
title={labels.exportLabel}> title={labels.export.button}>
</Button> </Button>
</View> </View>
<View style={styles.homeButton}> <View style={styles.homeButton}>
<Button <Button
onPress={ getFileContentAndImport } title={labels.import.button}
title={labels.importLabel}> onPress={() => {
Alert.alert(
labels.import.title,
labels.import.message,
[{
text: labels.import.replaceOption,
onPress: () => getFileContentAndImport({deleteExisting: false})
}, {
text: labels.import.deleteOption,
onPress: () => getFileContentAndImport({deleteExisting: true})
}, {
text: labels.shared.cancel, style: 'cancel', onPress: () => { }
}]
)
}}>
</Button> </Button>
</View> </View>
</View> </View>
...@@ -51,19 +65,19 @@ async function openShareDialogAndExport() { ...@@ -51,19 +65,19 @@ async function openShareDialogAndExport() {
try { try {
await Share.open({ await Share.open({
title: labels.exportTitle, title: labels.export.title,
url: data, url: data,
subject: labels.exportSubject, subject: labels.export.subject,
type: 'text/csv', type: 'text/csv',
showAppsToView: true showAppsToView: true
}) })
} catch (err) { } catch (err) {
console.error(err) console.error(err)
return alertError(labels.errors.problemSharing) return alertError(labels.export.errors.problemSharing)
} }
} }
async function getFileContentAndImport() { async function getFileContentAndImport({ deleteExisting }) {
let fileInfo let fileInfo
try { try {
fileInfo = await new Promise((resolve, reject) => { fileInfo = await new Promise((resolve, reject) => {
...@@ -87,7 +101,7 @@ async function getFileContentAndImport() { ...@@ -87,7 +101,7 @@ async function getFileContentAndImport() {
} }
try { try {
await importCsv(fileContent, false) await importCsv(fileContent, deleteExisting)
Alert.alert('Success', 'Data successfully imported') Alert.alert('Success', 'Data successfully imported')
} catch(err) { } catch(err) {
alertError(err.message) alertError(err.message)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment