GrowiZipImportSection.jsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. fileName: '',
  14. fileStats: [],
  15. };
  16. this.state = this.initialState;
  17. this.handleUpload = this.handleUpload.bind(this);
  18. this.discardData = this.discardData.bind(this);
  19. }
  20. handleUpload({ meta, fileName, fileStats }) {
  21. this.setState({
  22. fileName,
  23. fileStats,
  24. });
  25. }
  26. discardData() {
  27. this.setState(this.initialState);
  28. }
  29. render() {
  30. const { t } = this.props;
  31. return (
  32. <Fragment>
  33. <legend>{t('importer_management.import_form_growi')}</legend>
  34. <div className="well well-sm small">
  35. <ul>
  36. <li>{t('importer_management.growi_settings.overwrite_documents')}</li>
  37. </ul>
  38. </div>
  39. {this.state.fileName ? (
  40. <Fragment>
  41. <GrowiZipImportForm
  42. fileName={this.state.fileName}
  43. fileStats={this.state.fileStats}
  44. onDiscard={this.discardData}
  45. />
  46. </Fragment>
  47. ) : (
  48. <GrowiZipUploadForm
  49. onUpload={this.handleUpload}
  50. />
  51. )}
  52. </Fragment>
  53. );
  54. }
  55. }
  56. GrowiZipImportSection.propTypes = {
  57. t: PropTypes.func.isRequired, // i18next
  58. appContainer: PropTypes.instanceOf(AppContainer).isRequired,
  59. };
  60. /**
  61. * Wrapper component for using unstated
  62. */
  63. const GrowiZipImportSectionWrapper = (props) => {
  64. return createSubscribedElement(GrowiZipImportSection, props, [AppContainer]);
  65. };
  66. export default withTranslation()(GrowiZipImportSectionWrapper);