GrowiZipImportSection.jsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import React, { Fragment } from 'react';
  2. import PropTypes from 'prop-types';
  3. import { withTranslation } from 'react-i18next';
  4. import GrowiZipUploadForm from './GrowiZipUploadForm';
  5. import GrowiZipImportForm from './GrowiZipImportForm';
  6. import { createSubscribedElement } from '../../UnstatedUtils';
  7. import AppContainer from '../../../services/AppContainer';
  8. // import { toastSuccess, toastError } from '../../../util/apiNotification';
  9. class GrowiZipImportSection extends React.Component {
  10. constructor(props) {
  11. super(props);
  12. this.initialState = {
  13. meta: {},
  14. zipFileName: '',
  15. fileStats: [],
  16. };
  17. this.state = this.initialState;
  18. this.inputRef = React.createRef();
  19. this.handleUpload = this.handleUpload.bind(this);
  20. }
  21. handleUpload({ meta, fileName, fileStats }) {
  22. this.setState({ fileName, fileStats });
  23. }
  24. render() {
  25. // eslint-disable-next-line no-unused-vars
  26. const { t } = this.props;
  27. return (
  28. <Fragment>
  29. <legend>Import from GROWI</legend>
  30. <div className="well well-sm small">
  31. <ul>
  32. <li>Imported documents will overwrite existing pages</li>
  33. </ul>
  34. </div>
  35. <GrowiZipUploadForm
  36. onUpload={this.handleUpload}
  37. />
  38. <GrowiZipImportForm
  39. fileName={this.state.fileName}
  40. fileStats={this.state.fileStats}
  41. />
  42. </Fragment>
  43. );
  44. }
  45. }
  46. GrowiZipImportSection.propTypes = {
  47. t: PropTypes.func.isRequired, // i18next
  48. appContainer: PropTypes.instanceOf(AppContainer).isRequired,
  49. };
  50. /**
  51. * Wrapper component for using unstated
  52. */
  53. const GrowiZipImportSectionWrapper = (props) => {
  54. return createSubscribedElement(GrowiZipImportSection, props, [AppContainer]);
  55. };
  56. export default withTranslation()(GrowiZipImportSectionWrapper);