Removed unnecesarry promise references in delete short URL modal

This commit is contained in:
Alejandro Celaya 2022-11-06 18:48:47 +01:00
parent 0f552ae6f4
commit cf4143e4e2
3 changed files with 10 additions and 16 deletions

View file

@ -1,6 +1,6 @@
import { useEffect, useState } from 'react';
import { Modal, ModalBody, ModalFooter, ModalHeader } from 'reactstrap';
import { identity, pipe } from 'ramda';
import { pipe } from 'ramda';
import { DeleteShortUrl, ShortUrlDeletion } from '../reducers/shortUrlDeletion';
import { ShortUrlModalProps } from '../data';
import { handleEventPreventingDefault } from '../../utils/utils';
@ -10,7 +10,7 @@ import { ShlinkApiError } from '../../api/ShlinkApiError';
interface DeleteShortUrlModalConnectProps extends ShortUrlModalProps {
shortUrlDeletion: ShortUrlDeletion;
deleteShortUrl: (shortUrl: DeleteShortUrl) => Promise<void>;
deleteShortUrl: (shortUrl: DeleteShortUrl) => void;
resetDeleteShortUrl: () => void;
}
@ -23,13 +23,7 @@ export const DeleteShortUrlModal = (
const { loading, error, errorData } = shortUrlDeletion;
const close = pipe(resetDeleteShortUrl, toggle);
const handleDeleteUrl = handleEventPreventingDefault(() => {
const { shortCode, domain } = shortUrl;
deleteShortUrl({ shortCode, domain })
.then(toggle)
.catch(identity);
});
const handleDeleteUrl = handleEventPreventingDefault(() => deleteShortUrl(shortUrl));
return (
<Modal isOpen={isOpen} toggle={close} centered>

View file

@ -24,8 +24,8 @@ export const ShortUrlsRowMenu = (
QrCodeModal: ShortUrlModal,
) => ({ shortUrl, selectedServer }: ShortUrlsRowMenuProps) => {
const [isOpen, toggle] = useToggle();
const [isQrModalOpen, toggleQrCode] = useToggle();
const [isDeleteModalOpen, toggleDelete] = useToggle();
const [isQrModalOpen,, openQrCodeModal, closeQrCodeModal] = useToggle();
const [isDeleteModalOpen,, openDeleteModal, closeDeleteModal] = useToggle();
return (
<DropdownBtnMenu toggle={toggle} isOpen={isOpen}>
@ -37,17 +37,17 @@ export const ShortUrlsRowMenu = (
<FontAwesomeIcon icon={editIcon} fixedWidth /> Edit short URL
</DropdownItem>
<DropdownItem onClick={toggleQrCode}>
<DropdownItem onClick={openQrCodeModal}>
<FontAwesomeIcon icon={qrIcon} fixedWidth /> QR code
</DropdownItem>
<QrCodeModal shortUrl={shortUrl} isOpen={isQrModalOpen} toggle={toggleQrCode} />
<QrCodeModal shortUrl={shortUrl} isOpen={isQrModalOpen} toggle={closeQrCodeModal} />
<DropdownItem divider />
<DropdownItem className="dropdown-item--danger" onClick={toggleDelete}>
<DropdownItem className="dropdown-item--danger" onClick={openDeleteModal}>
<FontAwesomeIcon icon={deleteIcon} fixedWidth /> Delete short URL
</DropdownItem>
<DeleteShortUrlModal shortUrl={shortUrl} isOpen={isDeleteModalOpen} toggle={toggleDelete} />
<DeleteShortUrlModal shortUrl={shortUrl} isOpen={isDeleteModalOpen} toggle={closeDeleteModal} />
</DropdownBtnMenu>
);
};

View file

@ -12,7 +12,7 @@ describe('<DeleteShortUrlModal />', () => {
shortCode: 'abc123',
longUrl: 'https://long-domain.com/foo/bar',
});
const deleteShortUrl = jest.fn(async () => Promise.resolve());
const deleteShortUrl = jest.fn();
const setUp = (shortUrlDeletion: Partial<ShortUrlDeletion>) => renderWithEvents(
<DeleteShortUrlModal
isOpen