Move buttons to component
[MAILPOET-1808]
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import MailPoet from 'mailpoet';
|
import MailPoet from 'mailpoet';
|
||||||
import PreviousNextStepButtons from './previous_next_step_buttons.jsx';
|
|
||||||
import SelectMethod from './step_method_selection/select_import_method.jsx';
|
import SelectMethod from './step_method_selection/select_import_method.jsx';
|
||||||
import MethodPaste from './step_method_selection/method_paste.jsx';
|
import MethodPaste from './step_method_selection/method_paste.jsx';
|
||||||
import MethodUpload from './step_method_selection/method_upload.jsx';
|
import MethodUpload from './step_method_selection/method_upload.jsx';
|
||||||
@@ -26,57 +25,44 @@ const getNextStepLink = (importData) => {
|
|||||||
function StepMethodSelection({
|
function StepMethodSelection({
|
||||||
navigate,
|
navigate,
|
||||||
}) {
|
}) {
|
||||||
const [canGoNext, setCanGoNext] = useState(false);
|
|
||||||
const [method, setMethod] = useState(undefined);
|
const [method, setMethod] = useState(undefined);
|
||||||
const [csvData, setCsvData] = useState('');
|
const [csvData, setCsvData] = useState('');
|
||||||
|
|
||||||
const setInputValid = () => {
|
const methodChanged = (newMethod) => {
|
||||||
setCanGoNext(true);
|
setMethod(newMethod);
|
||||||
|
setCsvData('');
|
||||||
};
|
};
|
||||||
|
|
||||||
const setInputInValid = () => {
|
const navigateToNextStep = () => {
|
||||||
setCanGoNext(false);
|
navigate(
|
||||||
|
getNextStepLink(window.importData.step_method_selection),
|
||||||
|
{ trigger: true }
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const process = () => {
|
const processLocal = () => {
|
||||||
processCsv(csvData, (sanitizedData) => {
|
processCsv(csvData, (sanitizedData) => {
|
||||||
window.importData.step_method_selection = sanitizedData;
|
window.importData.step_method_selection = sanitizedData;
|
||||||
MailPoet.trackEvent('Subscribers import started', {
|
MailPoet.trackEvent('Subscribers import started', {
|
||||||
source: method === 'file-method' ? 'file upload' : 'pasted data',
|
source: method === 'file-method' ? 'file upload' : 'pasted data',
|
||||||
'MailPoet Free version': window.mailpoet_version,
|
'MailPoet Free version': window.mailpoet_version,
|
||||||
});
|
});
|
||||||
navigate(
|
navigateToNextStep();
|
||||||
getNextStepLink(window.importData.step_method_selection),
|
|
||||||
{ trigger: true }
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const showNextButton = () => {
|
|
||||||
if (method) {
|
|
||||||
return (
|
|
||||||
<PreviousNextStepButtons
|
|
||||||
canGoNext={canGoNext}
|
|
||||||
hidePrevious
|
|
||||||
onNextAction={process}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<SelectMethod
|
<SelectMethod
|
||||||
activeMethod={method}
|
activeMethod={method}
|
||||||
onMethodChange={setMethod}
|
onMethodChange={methodChanged}
|
||||||
/>
|
/>
|
||||||
{ method === 'paste-method'
|
{ method === 'paste-method'
|
||||||
? (
|
? (
|
||||||
<MethodPaste
|
<MethodPaste
|
||||||
onValueChange={setCsvData}
|
onValueChange={setCsvData}
|
||||||
setInputValid={setInputValid}
|
onFinish={processLocal}
|
||||||
setInputInvalid={setInputInValid}
|
canFinish={!!csvData.trim()}
|
||||||
/>
|
/>
|
||||||
) : null
|
) : null
|
||||||
}
|
}
|
||||||
@@ -84,19 +70,18 @@ function StepMethodSelection({
|
|||||||
? (
|
? (
|
||||||
<MethodUpload
|
<MethodUpload
|
||||||
onValueChange={setCsvData}
|
onValueChange={setCsvData}
|
||||||
setInputValid={setInputValid}
|
onFinish={processLocal}
|
||||||
setInputInvalid={setInputInValid}
|
canFinish={!!csvData}
|
||||||
/>
|
/>
|
||||||
) : null
|
) : null
|
||||||
}
|
}
|
||||||
{ method === 'mailchimp-method'
|
{ method === 'mailchimp-method'
|
||||||
? (
|
? (
|
||||||
<MethodMailChimp
|
<MethodMailChimp
|
||||||
setInputValid={setInputValid}
|
onFinish={navigateToNextStep}
|
||||||
/>
|
/>
|
||||||
) : null
|
) : null
|
||||||
}
|
}
|
||||||
{showNextButton()}
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -2,18 +2,15 @@ import React from 'react';
|
|||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import MailPoet from 'mailpoet';
|
import MailPoet from 'mailpoet';
|
||||||
import ReactStringReplace from 'react-string-replace';
|
import ReactStringReplace from 'react-string-replace';
|
||||||
|
import PreviousNextStepButtons from '../previous_next_step_buttons.jsx';
|
||||||
|
|
||||||
const kbLink = 'http://docs.mailpoet.com/article/126-importing-subscribers-with-csv-files'
|
const kbLink = 'http://docs.mailpoet.com/article/126-importing-subscribers-with-csv-files'
|
||||||
|
|
||||||
const placeholder = 'Email, First Name, Last Name\njohn@doe.com, John, Doe\nmary@smith.com, Mary, Smith\njohnny@walker.com, Johnny, Walker';
|
const placeholder = 'Email, First Name, Last Name\njohn@doe.com, John, Doe\nmary@smith.com, Mary, Smith\njohnny@walker.com, Johnny, Walker';
|
||||||
|
|
||||||
const MethodPaste = ({ setInputValid, setInputInvalid, onValueChange }) => {
|
const MethodPaste = ({ onValueChange, canFinish, onFinish }) => {
|
||||||
|
|
||||||
const onChange = (e) => {
|
const onChange = (e) => {
|
||||||
if (e.target.value) {
|
|
||||||
setInputValid();
|
|
||||||
} else {
|
|
||||||
setInputInvalid();
|
|
||||||
}
|
|
||||||
onValueChange(e.target.value);
|
onValueChange(e.target.value);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -47,19 +44,23 @@ const MethodPaste = ({ setInputValid, setInputInvalid, onValueChange }) => {
|
|||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
|
<PreviousNextStepButtons
|
||||||
|
canGoNext={canFinish}
|
||||||
|
hidePrevious
|
||||||
|
onNextAction={onFinish}
|
||||||
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
MethodPaste.propTypes = {
|
MethodPaste.propTypes = {
|
||||||
setInputValid: PropTypes.func,
|
onFinish: PropTypes.func,
|
||||||
setInputInvalid: PropTypes.func,
|
canFinish: PropTypes.bool.isRequired,
|
||||||
onValueChange: PropTypes.func.isRequired,
|
onValueChange: PropTypes.func.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
MethodPaste.defaultProps = {
|
MethodPaste.defaultProps = {
|
||||||
setInputValid: () => {},
|
onFinish: () => {},
|
||||||
setInputInvalid: () => {},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default MethodPaste;
|
export default MethodPaste;
|
||||||
|
@@ -2,26 +2,25 @@ import React from 'react';
|
|||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import MailPoet from 'mailpoet';
|
import MailPoet from 'mailpoet';
|
||||||
import ReactStringReplace from 'react-string-replace';
|
import ReactStringReplace from 'react-string-replace';
|
||||||
|
import PreviousNextStepButtons from '../previous_next_step_buttons.jsx';
|
||||||
|
|
||||||
const kbLink = 'http://docs.mailpoet.com/article/126-importing-subscribers-with-csv-files'
|
const kbLink = 'http://docs.mailpoet.com/article/126-importing-subscribers-with-csv-files'
|
||||||
|
|
||||||
const MethodUpload = ({ setInputValid, setInputInvalid, onValueChange }) => {
|
const MethodUpload = ({ onValueChange, canFinish, onFinish }) => {
|
||||||
const onChange = (e) => {
|
const onChange = (e) => {
|
||||||
const ext = e.target.value.match(/[^.]+$/);
|
const ext = e.target.value.match(/[^.]+$/);
|
||||||
MailPoet.Notice.hide();
|
MailPoet.Notice.hide();
|
||||||
if (ext === null || ext[0].toLowerCase() !== 'csv') {
|
if (ext === null || ext[0].toLowerCase() !== 'csv') {
|
||||||
setInputInvalid();
|
|
||||||
MailPoet.Notice.error(MailPoet.I18n.t('wrongFileFormat'));
|
MailPoet.Notice.error(MailPoet.I18n.t('wrongFileFormat'));
|
||||||
onValueChange('');
|
onValueChange('');
|
||||||
} else {
|
} else {
|
||||||
onValueChange(e.target.files[0]);
|
onValueChange(e.target.files[0]);
|
||||||
setInputValid();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
|
||||||
<>
|
<>
|
||||||
|
<div>
|
||||||
<label htmlFor="paste_input" className="import_method_paste">
|
<label htmlFor="paste_input" className="import_method_paste">
|
||||||
<div className="import_paste_texts">
|
<div className="import_paste_texts">
|
||||||
<span className="import_heading">{MailPoet.I18n.t('methodUpload')}</span>
|
<span className="import_heading">{MailPoet.I18n.t('methodUpload')}</span>
|
||||||
@@ -50,20 +49,24 @@ const MethodUpload = ({ setInputValid, setInputInvalid, onValueChange }) => {
|
|||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
</>
|
|
||||||
</div>
|
</div>
|
||||||
|
<PreviousNextStepButtons
|
||||||
|
canGoNext={canFinish}
|
||||||
|
hidePrevious
|
||||||
|
onNextAction={onFinish}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
MethodUpload.propTypes = {
|
MethodUpload.propTypes = {
|
||||||
setInputValid: PropTypes.func,
|
canFinish: PropTypes.bool.isRequired,
|
||||||
setInputInvalid: PropTypes.func,
|
onFinish: PropTypes.func,
|
||||||
onValueChange: PropTypes.func.isRequired,
|
onValueChange: PropTypes.func.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
MethodUpload.defaultProps = {
|
MethodUpload.defaultProps = {
|
||||||
setInputValid: () => {},
|
onFinish: () => {},
|
||||||
setInputInvalid: () => {},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default MethodUpload;
|
export default MethodUpload;
|
||||||
|
Reference in New Issue
Block a user