import React, { Fragment } from 'react'; import { withTranslation } from 'react-i18next'; import PropTypes from 'prop-types'; import AppContainer from '../../services/AppContainer'; import { createSubscribedElement } from '../UnstatedUtils'; import { toastSuccess, toastError } from '../../util/apiNotification'; class Importer extends React.Component { constructor(props) { super(props); this.state = { esaTeamName: '', esaAccessToken: '', }; this.esaHandleSubmit = this.esaHandleSubmit.bind(this); this.esaHandleSubmitTest = this.esaHandleSubmitTest.bind(this); this.esaHandleSubmitUpdate = this.esaHandleSubmitUpdate.bind(this); this.handleInputValue = this.handleInputValue.bind(this); } handleInputValue(event) { this.setState({ [event.target.name]: event.target.value, }); } esaHandleSubmit() { try { const params = { esaTeamName: this.state.esaTeamName, esaAccessToken: this.state.esaAccessToken, }; this.props.appContainer.apiPost('/admin/import/esa', params); toastSuccess('Import posts from esa success.'); } catch (error) { toastError(error, 'Error occurred in importing pages from esa.io'); } } esaHandleSubmitTest() { try { const params = { esaTeamName: this.state.esaTeamName, esaAccessToken: this.state.esaAccessToken, }; this.props.appContainer.apiPost('/admin/import/testEsaAPI', params); toastSuccess('Test connection to esa success.'); } catch (error) { toastError(error, 'Test connection to esa failed.'); } } esaHandleSubmitUpdate() { try { const params = { esaTeamName: this.state.esaTeamName, esaAccessToken: this.state.esaAccessToken, }; this.props.appContainer.apiPost('/admin/settings/importerEsa', params); toastSuccess('Update'); } catch (error) { toastError(error); } } render() { const { esaTeamName, esaAccessToken } = this.state; const { t } = this.props; return (
{ t('importer_management.import_from_esa') }
esa.io GROWI
{ t('Article') } { t('Page') }
{ t('Category') } { t('Page Path') }
{ t('User') } (TBD)
  • { t('importer_management.page_skip') }
); } } /** * Wrapper component for using unstated */ const ImporterWrapper = (props) => { return createSubscribedElement(Importer, props, [AppContainer]); }; Importer.propTypes = { appContainer: PropTypes.instanceOf(AppContainer).isRequired, t: PropTypes.func.isRequired, // i18next csrf: PropTypes.string, }; export default withTranslation()(ImporterWrapper);