import { pipe } from 'ramda'; import { useEffect, useState } from 'react'; import { Modal, ModalBody, ModalFooter, ModalHeader } from 'reactstrap'; import { Result } from '../../../src/utils/Result'; import { isInvalidDeletionError } from '../../api-contract/utils'; import { ShlinkApiError } from '../../common/ShlinkApiError'; import { handleEventPreventingDefault } from '../../utils/helpers'; import type { ShortUrlIdentifier, ShortUrlModalProps } from '../data'; import type { ShortUrlDeletion } from '../reducers/shortUrlDeletion'; interface DeleteShortUrlModalConnectProps extends ShortUrlModalProps { shortUrlDeletion: ShortUrlDeletion; deleteShortUrl: (shortUrl: ShortUrlIdentifier) => Promise; shortUrlDeleted: (shortUrl: ShortUrlIdentifier) => void; resetDeleteShortUrl: () => void; } const DELETION_PATTERN = 'delete'; export const DeleteShortUrlModal = ({ shortUrl, toggle, isOpen, shortUrlDeletion, resetDeleteShortUrl, deleteShortUrl, shortUrlDeleted, }: DeleteShortUrlModalConnectProps) => { const [inputValue, setInputValue] = useState(''); useEffect(() => resetDeleteShortUrl, []); const { loading, error, deleted, errorData } = shortUrlDeletion; const close = pipe(resetDeleteShortUrl, toggle); const handleDeleteUrl = handleEventPreventingDefault(() => deleteShortUrl(shortUrl).then(toggle)); return ( deleted && shortUrlDeleted(shortUrl)}>
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 {DELETION_PATTERN} to confirm deletion.

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