import React, { Fragment } from 'react'; import PropTypes from 'prop-types'; import { withTranslation } from 'react-i18next'; import * as toastr from 'toastr'; import AppContainer from '~/client/services/AppContainer'; import { apiv3Delete, apiv3Get } from '~/client/util/apiv3-client'; import { withUnstatedContainers } from '../../UnstatedUtils'; // import { toastSuccess, toastError } from '~/client/util/apiNotification'; import ImportForm from './GrowiArchive/ImportForm'; import UploadForm from './GrowiArchive/UploadForm'; class GrowiArchiveSection extends React.Component { constructor(props) { super(props); this.initialState = { fileName: null, innerFileStats: null, isTheSameVersion: null, }; this.state = this.initialState; this.handleUpload = this.handleUpload.bind(this); this.discardData = this.discardData.bind(this); this.resetState = this.resetState.bind(this); this.handleMismatchedVersions = this.handleMismatchedVersions.bind(this); this.renderDefferentVersionAlert = this.renderDefferentVersionAlert.bind(this); } async componentWillMount() { // get uploaded file status const res = await apiv3Get('/import/status'); if (res.data.zipFileStat != null) { const { fileName, innerFileStats } = res.data.zipFileStat; const { isTheSameVersion } = res.data; this.setState({ fileName, innerFileStats, isTheSameVersion }); } } handleUpload({ meta, fileName, innerFileStats, }) { this.setState({ fileName, innerFileStats, isTheSameVersion: true, }); } async discardData() { try { const { fileName } = this.state; await apiv3Delete('/import/all'); this.resetState(); // TODO: toastSuccess, toastError toastr.success(undefined, `Deleted ${fileName}`, { closeButton: true, progressBar: true, newestOnTop: false, showDuration: '100', hideDuration: '100', timeOut: '1200', extendedTimeOut: '150', }); } catch (err) { // TODO: toastSuccess, toastError toastr.error(err, 'Error', { closeButton: true, progressBar: true, newestOnTop: false, showDuration: '100', hideDuration: '100', timeOut: '3000', }); } } handleMismatchedVersions(err) { this.setState({ isTheSameVersion: false, }); } renderDefferentVersionAlert() { const { t } = this.props; return (