import _ from 'lodash'; import PropTypes from 'prop-types'; import React, { Component } from 'react'; import Button from 'Components/Link/Button'; import LoadingIndicator from 'Components/Loading/LoadingIndicator'; import { kinds } from 'Helpers/Props'; import ModalContent from 'Components/Modal/ModalContent'; import ModalHeader from 'Components/Modal/ModalHeader'; import ModalBody from 'Components/Modal/ModalBody'; import ModalFooter from 'Components/Modal/ModalFooter'; import Alert from 'Components/Alert'; function formatBookFiles(items, book) { return (
{book.title}
); } class ConfirmImportModalContent extends Component { // // Lifecycle componentDidUpdate(prevProps) { const { items, isFetching, isPopulated } = this.props; if (!isFetching && isPopulated && !items.length) { this.props.onModalClose(); this.props.onConfirmImportPress(); } } // // Render render() { const { books, items, onConfirmImportPress, onModalClose, isFetching, isPopulated } = this.props; // don't render if nothing to do if (!isFetching && isPopulated && !items.length) { return null; } return ( { !isFetching && isPopulated && Are you sure? } { isFetching && } { !isFetching && isPopulated &&
You already have files imported for the books listed below. If you continue, the existing files will be deleted and the new files imported in their place. To avoid deleting existing files, press 'Cancel' and use the 'Combine with existing files' option. { _.chain(items) .groupBy('bookId') .mapValues((value, key) => formatBookFiles(value, _.find(books, (a) => a.id === parseInt(key)))) .values() .value() }
}
{ !isFetching && isPopulated && }
); } } ConfirmImportModalContent.propTypes = { books: PropTypes.arrayOf(PropTypes.object).isRequired, items: PropTypes.arrayOf(PropTypes.object).isRequired, isFetching: PropTypes.bool.isRequired, isPopulated: PropTypes.bool.isRequired, onConfirmImportPress: PropTypes.func.isRequired, onModalClose: PropTypes.func.isRequired }; export default ConfirmImportModalContent;