Lift state to top level component
[MAILPOET-1809]
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import React from 'react';
|
import React, { useState } from 'react';
|
||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
import { HashRouter, Switch, Route, Redirect } from 'react-router-dom';
|
import { HashRouter, Switch, Route, Redirect } from 'react-router-dom';
|
||||||
|
|
||||||
@@ -6,13 +6,18 @@ import StepMethodSelection from './import/step_method_selection.jsx';
|
|||||||
|
|
||||||
const container = document.getElementById('import_container');
|
const container = document.getElementById('import_container');
|
||||||
|
|
||||||
if (container) {
|
const ImportSubscribers = () => {
|
||||||
ReactDOM.render((
|
const [stepMethodSelection, setStepMethodSelection] = useState(undefined);
|
||||||
|
return (
|
||||||
<HashRouter>
|
<HashRouter>
|
||||||
<Switch>
|
<Switch>
|
||||||
<Route path="/step_method_selection" component={StepMethodSelection} />
|
<Route path="/step_method_selection" render={props => <StepMethodSelection {...props} setStepMethodSelection={setStepMethodSelection} />} />
|
||||||
<Route path="*" render={() => <Redirect to="/step_method_selection" />} />
|
<Route path="*" render={() => <Redirect to="/step_method_selection" />} />
|
||||||
</Switch>
|
</Switch>
|
||||||
</HashRouter>
|
</HashRouter>
|
||||||
), container);
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (container) {
|
||||||
|
ReactDOM.render(<ImportSubscribers />, container);
|
||||||
}
|
}
|
||||||
|
@@ -25,13 +25,13 @@ const getNextStepLink = (importData) => {
|
|||||||
|
|
||||||
function StepMethodSelection({
|
function StepMethodSelection({
|
||||||
history,
|
history,
|
||||||
|
setStepMethodSelection,
|
||||||
}) {
|
}) {
|
||||||
const [method, setMethod] = useState(undefined);
|
const [method, setMethod] = useState(undefined);
|
||||||
const [pastedCsvData, setPastedCsvData] = useState('');
|
const [pastedCsvData, setPastedCsvData] = useState('');
|
||||||
const [file, setFile] = useState(undefined);
|
const [file, setFile] = useState(undefined);
|
||||||
|
|
||||||
const finish = (parsedData) => {
|
const finish = (parsedData) => {
|
||||||
window.importData.step_method_selection = parsedData;
|
|
||||||
setStepMethodSelection(parsedData);
|
setStepMethodSelection(parsedData);
|
||||||
history.push(getNextStepLink(parsedData));
|
history.push(getNextStepLink(parsedData));
|
||||||
};
|
};
|
||||||
@@ -94,6 +94,7 @@ StepMethodSelection.propTypes = {
|
|||||||
history: PropTypes.shape({
|
history: PropTypes.shape({
|
||||||
push: PropTypes.func.isRequired,
|
push: PropTypes.func.isRequired,
|
||||||
}).isRequired,
|
}).isRequired,
|
||||||
|
setStepMethodSelection: PropTypes.func.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default withRouter(StepMethodSelection);
|
export default withRouter(StepMethodSelection);
|
||||||
|
@@ -14,12 +14,12 @@ function papaParserConfig(done) {
|
|||||||
if (sanitizedData) {
|
if (sanitizedData) {
|
||||||
done(sanitizedData);
|
done(sanitizedData);
|
||||||
} else {
|
} else {
|
||||||
MailPoet.Modal.loading(false);
|
|
||||||
let errorNotice = MailPoet.I18n.t('noValidRecords');
|
let errorNotice = MailPoet.I18n.t('noValidRecords');
|
||||||
errorNotice = errorNotice.replace('[link]', MailPoet.I18n.t('csvKBLink'));
|
errorNotice = errorNotice.replace('[link]', MailPoet.I18n.t('csvKBLink'));
|
||||||
errorNotice = errorNotice.replace('[/link]', '</a>');
|
errorNotice = errorNotice.replace('[/link]', '</a>');
|
||||||
MailPoet.Notice.error(errorNotice);
|
MailPoet.Notice.error(errorNotice);
|
||||||
}
|
}
|
||||||
|
MailPoet.Modal.loading(false);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user