import { useEffect, useState } from 'react'; import { Modal, ModalBody, ModalFooter, ModalHeader } from 'reactstrap'; import { identity, pipe } from 'ramda'; import { ShortUrlDeletion } from '../reducers/shortUrlDeletion'; import { ShortUrlModalProps } from '../data'; import { handleEventPreventingDefault, OptionalString } from '../../utils/utils'; import { Result } from '../../utils/Result'; import { isInvalidDeletionError } from '../../api/utils'; import { ShlinkApiError } from '../../api/ShlinkApiError'; interface DeleteShortUrlModalConnectProps extends ShortUrlModalProps { shortUrlDeletion: ShortUrlDeletion; deleteShortUrl: (shortCode: string, domain: OptionalString) => Promise; resetDeleteShortUrl: () => void; } const DeleteShortUrlModal = ( { shortUrl, toggle, isOpen, shortUrlDeletion, resetDeleteShortUrl, deleteShortUrl }: DeleteShortUrlModalConnectProps, ) => { const [ inputValue, setInputValue ] = useState(''); useEffect(() => resetDeleteShortUrl, []); const { error, errorData } = shortUrlDeletion; const close = pipe(resetDeleteShortUrl, toggle); const handleDeleteUrl = handleEventPreventingDefault(() => { const { shortCode, domain } = shortUrl; deleteShortUrl(shortCode, domain) .then(toggle) .catch(identity); }); 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.

Write {shortUrl.shortCode} to confirm deletion.

setInputValue(e.target.value)} /> {error && ( )}
); }; export default DeleteShortUrlModal;