import React, { Component } from 'react'; import { connect } from 'react-redux'; import { Modal, ModalBody, ModalFooter, ModalHeader } from 'reactstrap'; import PropTypes from 'prop-types'; import { pick, identity } from 'ramda'; import { shortUrlType } from '../reducers/shortUrlsList'; import { deleteShortUrl, resetDeleteShortUrl, shortUrlDeleted, shortUrlDeletionType, } from '../reducers/shortUrlDeletion'; import './QrCodeModal.scss'; export class DeleteShortUrlModalComponent extends Component { static propTypes = { shortUrl: shortUrlType, toggle: PropTypes.func, isOpen: PropTypes.bool, shortUrlDeletion: shortUrlDeletionType, deleteShortUrl: PropTypes.func, resetDeleteShortUrl: PropTypes.func, shortUrlDeleted: PropTypes.func, }; state = { inputValue: '' }; handleDeleteUrl = (e) => { e.preventDefault(); const { deleteShortUrl, shortUrl, toggle, shortUrlDeleted } = this.props; const { shortCode } = shortUrl; deleteShortUrl(shortCode) .then(() => { shortUrlDeleted(shortCode); toggle(); }) .catch(identity); }; componentWillUnmount() { const { resetDeleteShortUrl } = this.props; resetDeleteShortUrl(); } render() { const { shortUrl, toggle, isOpen, shortUrlDeletion } = this.props; const THRESHOLD_REACHED = 'INVALID_SHORTCODE_DELETION'; return (
Delete short URL

Caution! You are about to delete a short URL.

This action cannot be undone. Once you have deleted it, all the visits stats will be lost.

this.setState({ inputValue: e.target.value })} /> {shortUrlDeletion.error && shortUrlDeletion.errorData.error === THRESHOLD_REACHED && (
This short URL has received too many visits and therefore, it cannot be deleted
)} {shortUrlDeletion.error && shortUrlDeletion.errorData.error !== THRESHOLD_REACHED && (
Something went wrong while deleting the URL :(
)}
); } } const DeleteShortUrlModal = connect( pick([ 'shortUrlDeletion' ]), { deleteShortUrl, resetDeleteShortUrl, shortUrlDeleted } )(DeleteShortUrlModalComponent); export default DeleteShortUrlModal;