From 61b274bab9e2eb12b31f0cea538d6027db943944 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Mon, 7 Nov 2022 18:27:41 +0100 Subject: [PATCH] Replaced inheritance by composition on short URL creation interface --- src/short-urls/CreateShortUrl.tsx | 2 +- src/short-urls/helpers/CreateShortUrlResult.tsx | 6 ++++-- test/short-urls/helpers/CreateShortUrlResult.test.tsx | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/short-urls/CreateShortUrl.tsx b/src/short-urls/CreateShortUrl.tsx index 890f2af5..2f045023 100644 --- a/src/short-urls/CreateShortUrl.tsx +++ b/src/short-urls/CreateShortUrl.tsx @@ -59,7 +59,7 @@ export const CreateShortUrl = ( }} /> diff --git a/src/short-urls/helpers/CreateShortUrlResult.tsx b/src/short-urls/helpers/CreateShortUrlResult.tsx index e89bab34..d37b511c 100644 --- a/src/short-urls/helpers/CreateShortUrlResult.tsx +++ b/src/short-urls/helpers/CreateShortUrlResult.tsx @@ -10,15 +10,17 @@ import { Result } from '../../utils/Result'; import './CreateShortUrlResult.scss'; import { ShlinkApiError } from '../../api/ShlinkApiError'; -export interface CreateShortUrlResultProps extends ShortUrlCreation { +export interface CreateShortUrlResultProps { + creation: ShortUrlCreation; resetCreateShortUrl: () => void; canBeClosed?: boolean; } export const CreateShortUrlResult = (useTimeoutToggle: TimeoutToggle) => ( - { error, errorData, result, resetCreateShortUrl, canBeClosed = false }: CreateShortUrlResultProps, + { creation, resetCreateShortUrl, canBeClosed = false }: CreateShortUrlResultProps, ) => { const [showCopyTooltip, setShowCopyTooltip] = useTimeoutToggle(); + const { error, errorData, result } = creation; useEffect(() => { resetCreateShortUrl(); diff --git a/test/short-urls/helpers/CreateShortUrlResult.test.tsx b/test/short-urls/helpers/CreateShortUrlResult.test.tsx index 03082a93..55b46e13 100644 --- a/test/short-urls/helpers/CreateShortUrlResult.test.tsx +++ b/test/short-urls/helpers/CreateShortUrlResult.test.tsx @@ -9,8 +9,8 @@ describe('', () => { const copyToClipboard = jest.fn(); const useTimeoutToggle = jest.fn(() => [false, copyToClipboard]) as TimeoutToggle; const CreateShortUrlResult = createResult(useTimeoutToggle); - const setUp = (result: ShortUrl | null = null, error = false) => renderWithEvents( - {}} result={result} error={error} saving={false} />, + const setUp = (result?: ShortUrl, error = false) => renderWithEvents( + {}} creation={{ result, saving: false, error, saved: false }} />, ); afterEach(jest.clearAllMocks);