From cf4143e4e225c5a67c93fc9a209079bb83e30e7a Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 6 Nov 2022 18:48:47 +0100 Subject: [PATCH] Removed unnecesarry promise references in delete short URL modal --- src/short-urls/helpers/DeleteShortUrlModal.tsx | 12 +++--------- src/short-urls/helpers/ShortUrlsRowMenu.tsx | 12 ++++++------ test/short-urls/helpers/DeleteShortUrlModal.test.tsx | 2 +- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/short-urls/helpers/DeleteShortUrlModal.tsx b/src/short-urls/helpers/DeleteShortUrlModal.tsx index 4704d666..06caab5e 100644 --- a/src/short-urls/helpers/DeleteShortUrlModal.tsx +++ b/src/short-urls/helpers/DeleteShortUrlModal.tsx @@ -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; + 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 ( diff --git a/src/short-urls/helpers/ShortUrlsRowMenu.tsx b/src/short-urls/helpers/ShortUrlsRowMenu.tsx index 877233f3..a4563a52 100644 --- a/src/short-urls/helpers/ShortUrlsRowMenu.tsx +++ b/src/short-urls/helpers/ShortUrlsRowMenu.tsx @@ -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 ( @@ -37,17 +37,17 @@ export const ShortUrlsRowMenu = ( Edit short URL - + QR code - + - + Delete short URL - + ); }; diff --git a/test/short-urls/helpers/DeleteShortUrlModal.test.tsx b/test/short-urls/helpers/DeleteShortUrlModal.test.tsx index a386b198..282c4738 100644 --- a/test/short-urls/helpers/DeleteShortUrlModal.test.tsx +++ b/test/short-urls/helpers/DeleteShortUrlModal.test.tsx @@ -12,7 +12,7 @@ describe('', () => { shortCode: 'abc123', longUrl: 'https://long-domain.com/foo/bar', }); - const deleteShortUrl = jest.fn(async () => Promise.resolve()); + const deleteShortUrl = jest.fn(); const setUp = (shortUrlDeletion: Partial) => renderWithEvents(