From b0f38916291acdb4b12dcb7ebdfdf2496ebf4069 Mon Sep 17 00:00:00 2001 From: Bowrna Date: Sun, 13 Oct 2024 16:40:36 +0530 Subject: [PATCH] Make import overwrite off by default and add warning (#2078) * Move CSV example rendering to code to get around breaking auto-formatter. * Improve overwrite confirmation logic. --------- Co-authored-by: Kailash Nadh --- docs/swagger/collections.yaml | 2 ++ frontend/src/views/Import.vue | 59 ++++++++++++++++++++--------------- i18n/en.json | 1 + 3 files changed, 37 insertions(+), 25 deletions(-) diff --git a/docs/swagger/collections.yaml b/docs/swagger/collections.yaml index d68df248..48529b49 100644 --- a/docs/swagger/collections.yaml +++ b/docs/swagger/collections.yaml @@ -2487,6 +2487,8 @@ components: type: string import.subscribe: type: string + import.subscribeWarning: + type: string import.title: type: string import.upload: diff --git a/frontend/src/views/Import.vue b/frontend/src/views/Import.vue index c13e12f4..b5e75d4c 100644 --- a/frontend/src/views/Import.vue +++ b/frontend/src/views/Import.vue @@ -6,7 +6,7 @@
-
+
@@ -93,12 +93,8 @@

{{ $t('import.instructionsHelp') }}


-
- - email, - name, - attributes - +
+ email, name, attributes

@@ -106,23 +102,8 @@
{{ $t('import.csvExample') }}
-
- - email, - name, - attributes -
- - user1@mail.com, - "User One", - "{""age"": 42, ""planet"": ""Mars""}" -
- - user2@mail.com, - "User Two", - "{""age"": 24, ""job"": ""Time Traveller""}" - -
+ +
       
@@ -175,8 +156,9 @@ export default Vue.extend({ subStatus: 'unconfirmed', delim: ',', lists: [], - overwrite: true, + overwrite: false, file: null, + example: '', }, // Initial page load still has to wait for the status API to return @@ -295,6 +277,32 @@ export default Vue.extend({ }); }, + renderExample() { + const h = 'email, name, attributes\n' + + 'user1 @mail.com, "User One", "{""age"": 42, ""planet"": ""Mars""}"\n' + + 'user2 @mail.com, "User Two", "{""age"": 24, ""job"": ""Time Traveller""}"'; + + this.example = h; + }, + + resetForm() { + this.form.mode = 'subscribe'; + this.form.overwrite = false; + this.form.file = null; + this.form.lists = []; + this.form.subStatus = 'unconfirmed'; + this.form.delim = ','; + }, + + onUpload() { + if (this.form.mode === 'subscribe' && this.form.overwrite) { + this.$utils.confirm(this.$t('import.subscribeWarning'), this.onSubmit, this.resetForm); + return; + } + + this.onSubmit(); + }, + onSubmit() { this.isProcessing = true; @@ -336,6 +344,7 @@ export default Vue.extend({ }, mounted() { + this.renderExample(); this.pollStatus(); const ids = this.$utils.parseQueryIDs(this.$route.query.list_id); diff --git a/i18n/en.json b/i18n/en.json index 91e4bcb8..19f4eea0 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -259,6 +259,7 @@ "import.recordsCount": "{num} / {total} records", "import.stopImport": "Stop import", "import.subscribe": "Subscribe", + "import.subscribeWarning":"Overwriting will re-subscribe unusbscribed e-mails. Continue?", "import.title": "Import subscribers", "import.upload": "Upload", "lists.confirmDelete": "Are you sure? This does not delete subscribers.",