Created component holding the logic to render Shlink API errors

This commit is contained in:
Alejandro Celaya
2020-12-21 21:19:02 +01:00
parent f69f791790
commit 51379eb2a0
9 changed files with 43 additions and 39 deletions

View File

@@ -6,6 +6,7 @@ import { ShortUrlModalProps } from '../data';
import { handleEventPreventingDefault, OptionalString } from '../../utils/utils';
import { Result } from '../../utils/Result';
import { isInvalidDeletionError } from '../../utils/services/types';
import { ShlinkApiError } from '../../api/ShlinkApiError';
interface DeleteShortUrlModalConnectProps extends ShortUrlModalProps {
shortUrlDeletion: ShortUrlDeletion;
@@ -49,15 +50,9 @@ const DeleteShortUrlModal = (
onChange={(e) => setInputValue(e.target.value)}
/>
{error && isInvalidDeletionError(errorData) && (
<Result type="warning" small className="mt-2">
{errorData.threshold && `This short URL has received more than ${errorData.threshold} visits, and therefore, it cannot be deleted.`}
{!errorData.threshold && 'This short URL has received too many visits, and therefore, it cannot be deleted.'}
</Result>
)}
{error && !isInvalidDeletionError(errorData) && (
<Result type="error" small className="mt-2">
{errorData?.detail ?? 'Something went wrong while deleting the URL :('}
{error && (
<Result type={isInvalidDeletionError(errorData) ? 'warning' : 'error'} small className="mt-2">
<ShlinkApiError errorData={errorData} fallbackMessage="Something went wrong while deleting the URL :(" />
</Result>
)}
</ModalBody>