import _ from 'lodash'; import PropTypes from 'prop-types'; import React, { Component } from 'react'; import Alert from 'Components/Alert'; import Button from 'Components/Link/Button'; import LoadingIndicator from 'Components/Loading/LoadingIndicator'; import ModalBody from 'Components/Modal/ModalBody'; import ModalContent from 'Components/Modal/ModalContent'; import ModalFooter from 'Components/Modal/ModalFooter'; import ModalHeader from 'Components/Modal/ModalHeader'; import { kinds } from 'Helpers/Props'; import translate from 'Utilities/String/translate'; function formatAlbumFiles(items, album) { return (
{album.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 { albums, items, onConfirmImportPress, onModalClose, isFetching, isPopulated } = this.props; // don't render if nothing to do if (!isFetching && isPopulated && !items.length) { return null; } return ( { !isFetching && isPopulated && {translate('AreYouSure')} } { isFetching && } { !isFetching && isPopulated &&
You already have files imported for the albums 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('albumId') .mapValues((value, key) => formatAlbumFiles(value, _.find(albums, (a) => a.id === parseInt(key)))) .values() .value() }
}
{ !isFetching && isPopulated && }
); } } ConfirmImportModalContent.propTypes = { albums: 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;