/* eslint-disable react/no-danger */ import React from 'react'; import PropTypes from 'prop-types'; import { withTranslation } from 'react-i18next'; import Modal from 'react-bootstrap/es/Modal'; import GrowiArchiveImportOption from '@commons/models/admin/growi-archive-import-option'; import { createSubscribedElement } from '../../UnstatedUtils'; import AppContainer from '../../../services/AppContainer'; // import { toastSuccess, toastError } from '../../../util/apiNotification'; class GrowiZipImportConfigurationModal extends React.Component { constructor(props) { super(props); this.state = { option: null, }; this.initialize = this.initialize.bind(this); this.updateOption = this.updateOption.bind(this); } async initialize() { await this.setState({ option: Object.assign({}, this.props.option), // clone }); } /** * invoked when the value of control is changed * @param {object} updateObj */ changeHandler(updateObj) { const { option } = this.state; const newOption = Object.assign(option, updateObj); this.setState({ option: newOption }); } updateOption() { const { collectionName, onOptionChange, onClose, } = this.props; if (onOptionChange != null) { onOptionChange(collectionName, this.state.option); } onClose(); } renderPagesContents() { const { t } = this.props; const { option } = this.state; const translationBase = 'importer_management.growi_settings.configuration.pages'; /* eslint-disable react/no-unescaped-entities */ return ( <>
this.changeHandler({ isOverwriteAuthorWithCurrentUser: !option.isOverwriteAuthorWithCurrentUser })} />
this.changeHandler({ makePublicForGrant2: !option.makePublicForGrant2 })} />
this.changeHandler({ makePublicForGrant4: !option.makePublicForGrant4 })} />
this.changeHandler({ makePublicForGrant5: !option.makePublicForGrant5 })} />
this.changeHandler({ initPageMetadatas: !option.initPageMetadatas })} />
this.changeHandler({ initHackmdDatas: !option.initHackmdDatas })} />
); /* eslint-enable react/no-unescaped-entities */ } renderRevisionsContents() { const { t } = this.props; const { option } = this.state; const translationBase = 'importer_management.growi_settings.configuration.revisions'; /* eslint-disable react/no-unescaped-entities */ return ( <>
this.changeHandler({ isOverwriteAuthorWithCurrentUser: !option.isOverwriteAuthorWithCurrentUser })} />
); /* eslint-enable react/no-unescaped-entities */ } render() { const { t, collectionName } = this.props; const { option } = this.state; let contents = null; if (option != null) { switch (collectionName) { case 'pages': contents = this.renderPagesContents(); break; case 'revisions': contents = this.renderRevisionsContents(); break; } } return ( {`'${collectionName}'`} Configuration {contents} ); } } GrowiZipImportConfigurationModal.propTypes = { t: PropTypes.func.isRequired, // i18next isOpen: PropTypes.bool.isRequired, onClose: PropTypes.func.isRequired, onOptionChange: PropTypes.func, collectionName: PropTypes.string, option: PropTypes.instanceOf(GrowiArchiveImportOption).isRequired, }; /** * Wrapper component for using unstated */ const GrowiZipImportConfigurationModalWrapper = (props) => { return createSubscribedElement(GrowiZipImportConfigurationModal, props, [AppContainer]); }; export default withTranslation()(GrowiZipImportConfigurationModalWrapper);