diff --git a/assets/js/src/subscribers/importExport/import.jsx b/assets/js/src/subscribers/importExport/import.jsx
index af34a2cd6a..99ac3fff54 100644
--- a/assets/js/src/subscribers/importExport/import.jsx
+++ b/assets/js/src/subscribers/importExport/import.jsx
@@ -87,41 +87,6 @@ jQuery(document).ready(() => {
const mailChimpListsContainerElement = jQuery('#mailchimp_lists');
const mailChimpProcessButtonElement = jQuery('#method_mailchimp > div.mailpoet_method_process')
.find('a.mailpoet_process');
- const uploadElement = jQuery('#file_local');
- const uploadProcessButtonElement = jQuery('#method_file > div.mailpoet_method_process')
- .find('a.mailpoet_process');
-
- function papaParserConfig(isFile) {
- return {
- skipEmptyLines: true,
- error() {
- MailPoet.Notice.hide();
- MailPoet.Notice.error(MailPoet.I18n.t('dataProcessingError'));
- },
- complete(CSV) {
- const sanitizedData = sanitizeCSVData(CSV.data);
- if (sanitizedData) {
- // since we assume that the header line is always present, we need
- // to detect the header by checking if it contains a valid e-mail address
- window.importData.step_method_selection = sanitizedData;
- MailPoet.trackEvent('Subscribers import started', {
- source: isFile ? 'file upload' : 'pasted data',
- 'MailPoet Free version': window.mailpoet_version,
- });
- router.navigate(
- getMethodSelectionNextStepLink(window.importData.step_method_selection),
- { trigger: true }
- );
- } else {
- MailPoet.Modal.loading(false);
- let errorNotice = MailPoet.I18n.t('noValidRecords');
- errorNotice = errorNotice.replace('[link]', MailPoet.I18n.t('csvKBLink'));
- errorNotice = errorNotice.replace('[/link]', '');
- MailPoet.Notice.error(errorNotice);
- }
- },
- };
- }
function displayMailChimpLists(data) {
const listSelectElement = mailChimpListsContainerElement.find('select');
@@ -152,35 +117,6 @@ jQuery(document).ready(() => {
mailChimpListsContainerElement.show();
}
- /*
- * CSV file
- */
- uploadElement.change((event) => {
- const ext = event.currentTarget.value.match(/[^.]+$/);
- MailPoet.Notice.hide();
- if (ext === null || ext[0].toLowerCase() !== 'csv') {
- event.currentTarget.value.val('');
- MailPoet.Notice.error(MailPoet.I18n.t('wrongFileFormat'));
- }
-
- toggleNextStepButton(
- uploadProcessButtonElement,
- (event.currentTarget.value.trim() !== '') ? 'on' : 'off'
- );
- });
-
- uploadProcessButtonElement.click(() => {
- if (uploadElement.val().trim() !== '') {
- // delay loading indicator for 10ms or else it's just too fast :)
- MailPoet.Modal.loading(true);
- setTimeout(() => {
- uploadElement.parse({
- config: papaParserConfig(true),
- });
- }, 10);
- }
- });
-
/*
* MailChimp
*/
diff --git a/assets/js/src/subscribers/importExport/import/step_method_selection.jsx b/assets/js/src/subscribers/importExport/import/step_method_selection.jsx
index 7720bbde7c..edcd0531b8 100644
--- a/assets/js/src/subscribers/importExport/import/step_method_selection.jsx
+++ b/assets/js/src/subscribers/importExport/import/step_method_selection.jsx
@@ -1,13 +1,12 @@
import React, { useState } from 'react';
import PropTypes from 'prop-types';
import MailPoet from 'mailpoet';
-import Papa from 'papaparse';
import PreviousNextStepButtons from './previous_next_step_buttons.jsx';
import SelectMethod from './step_method_selection/select_import_method.jsx';
import MethodPaste from './step_method_selection/method_paste.jsx';
import MethodUpload from './step_method_selection/method_upload.jsx';
import MethodMailChimp from './step_method_selection/method_mailchimp.jsx';
-import sanitizeCSVData from './sanitize_csv_data.jsx';
+import processCsv from './step_method_selection/process_csv.jsx';
const SUBSCRIBERS_LIMIT_FOR_VALIDATION = 500;
@@ -39,49 +38,18 @@ function StepMethodSelection({
setCanGoNext(false);
};
- function papaParserConfig(isFile) {
- return {
- skipEmptyLines: true,
- error() {
- MailPoet.Notice.hide();
- MailPoet.Notice.error(MailPoet.I18n.t('dataProcessingError'));
- },
- complete(CSV) {
- const sanitizedData = sanitizeCSVData(CSV.data);
- if (sanitizedData) {
- // since we assume that the header line is always present, we need
- // to detect the header by checking if it contains a valid e-mail address
- window.importData.step_method_selection = sanitizedData;
- MailPoet.trackEvent('Subscribers import started', {
- source: isFile ? 'file upload' : 'pasted data',
- 'MailPoet Free version': window.mailpoet_version,
- });
- navigate(
- getNextStepLink(window.importData.step_method_selection),
- { trigger: true }
- );
- } else {
- MailPoet.Modal.loading(false);
- let errorNotice = MailPoet.I18n.t('noValidRecords');
- errorNotice = errorNotice.replace('[link]', MailPoet.I18n.t('csvKBLink'));
- errorNotice = errorNotice.replace('[/link]', '');
- MailPoet.Notice.error(errorNotice);
- }
- },
- };
- }
-
const process = () => {
- const pasteSize = encodeURI(csvData).split(/%..|./).length - 1;
- MailPoet.Notice.hide();
- // get an approximate size of textarea paste in bytes
- if (pasteSize > window.maxPostSizeBytes) {
- MailPoet.Notice.error(MailPoet.I18n.t('maxPostSizeNotice'));
- return;
- }
- // delay loading indicator for 10ms or else it's just too fast :)
- MailPoet.Modal.loading(true);
- Papa.parse(csvData, papaParserConfig(false));
+ processCsv(csvData, (sanitizedData) => {
+ window.importData.step_method_selection = sanitizedData;
+ MailPoet.trackEvent('Subscribers import started', {
+ source: method === 'file-method' ? 'file upload' : 'pasted data',
+ 'MailPoet Free version': window.mailpoet_version,
+ });
+ navigate(
+ getNextStepLink(window.importData.step_method_selection),
+ { trigger: true }
+ );
+ });
};
const showNextButton = () => {
@@ -112,10 +80,12 @@ function StepMethodSelection({
/>
) : null
}
- { method === 'csv-method'
+ { method === 'file-method'
? (
- - | -- - | -
---|