Removed redundant types

This commit is contained in:
Alejandro Celaya 2022-11-06 19:12:41 +01:00
parent 526d7195bc
commit ea199dbf8f
4 changed files with 13 additions and 20 deletions

View file

@ -21,6 +21,11 @@ export interface ShortUrlData extends EditShortUrlData {
findIfExists?: boolean; findIfExists?: boolean;
} }
export interface ShortUrlIdentifier {
shortCode: string;
domain?: OptionalString;
}
export interface ShortUrl { export interface ShortUrl {
shortCode: string; shortCode: string;
shortUrl: string; shortUrl: string;
@ -47,11 +52,6 @@ export interface ShortUrlModalProps {
toggle: () => void; toggle: () => void;
} }
export interface ShortUrlIdentifier {
shortCode: string;
domain: OptionalString;
}
export const SHORT_URLS_ORDERABLE_FIELDS = { export const SHORT_URLS_ORDERABLE_FIELDS = {
dateCreated: 'Created at', dateCreated: 'Created at',
shortCode: 'Short URL', shortCode: 'Short URL',

View file

@ -1,8 +1,8 @@
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import { Modal, ModalBody, ModalFooter, ModalHeader } from 'reactstrap'; import { Modal, ModalBody, ModalFooter, ModalHeader } from 'reactstrap';
import { pipe } from 'ramda'; import { pipe } from 'ramda';
import { DeleteShortUrl, ShortUrlDeletion } from '../reducers/shortUrlDeletion'; import { ShortUrlDeletion } from '../reducers/shortUrlDeletion';
import { ShortUrlModalProps } from '../data'; import { ShortUrlIdentifier, ShortUrlModalProps } from '../data';
import { handleEventPreventingDefault } from '../../utils/utils'; import { handleEventPreventingDefault } from '../../utils/utils';
import { Result } from '../../utils/Result'; import { Result } from '../../utils/Result';
import { isInvalidDeletionError } from '../../api/utils'; import { isInvalidDeletionError } from '../../api/utils';
@ -10,7 +10,7 @@ import { ShlinkApiError } from '../../api/ShlinkApiError';
interface DeleteShortUrlModalConnectProps extends ShortUrlModalProps { interface DeleteShortUrlModalConnectProps extends ShortUrlModalProps {
shortUrlDeletion: ShortUrlDeletion; shortUrlDeletion: ShortUrlDeletion;
deleteShortUrl: (shortUrl: DeleteShortUrl) => void; deleteShortUrl: (shortUrl: ShortUrlIdentifier) => void;
resetDeleteShortUrl: () => void; resetDeleteShortUrl: () => void;
} }

View file

@ -3,6 +3,7 @@ import { createAsyncThunk } from '../../utils/helpers/redux';
import { ShlinkApiClientBuilder } from '../../api/services/ShlinkApiClientBuilder'; import { ShlinkApiClientBuilder } from '../../api/services/ShlinkApiClientBuilder';
import { parseApiError } from '../../api/utils'; import { parseApiError } from '../../api/utils';
import { ProblemDetailsError } from '../../api/types/errors'; import { ProblemDetailsError } from '../../api/types/errors';
import { ShortUrlIdentifier } from '../data';
export const SHORT_URL_DELETED = 'shlink/deleteShortUrl/SHORT_URL_DELETED'; export const SHORT_URL_DELETED = 'shlink/deleteShortUrl/SHORT_URL_DELETED';
@ -14,12 +15,7 @@ export interface ShortUrlDeletion {
errorData?: ProblemDetailsError; errorData?: ProblemDetailsError;
} }
export interface DeleteShortUrl { export type DeleteShortUrlAction = PayloadAction<ShortUrlIdentifier>;
shortCode: string;
domain?: string | null;
}
export type DeleteShortUrlAction = PayloadAction<DeleteShortUrl>;
const initialState: ShortUrlDeletion = { const initialState: ShortUrlDeletion = {
shortCode: '', shortCode: '',
@ -31,7 +27,7 @@ const initialState: ShortUrlDeletion = {
export const shortUrlDeletionReducerCreator = (buildShlinkApiClient: ShlinkApiClientBuilder) => { export const shortUrlDeletionReducerCreator = (buildShlinkApiClient: ShlinkApiClientBuilder) => {
const deleteShortUrl = createAsyncThunk( const deleteShortUrl = createAsyncThunk(
SHORT_URL_DELETED, SHORT_URL_DELETED,
async ({ shortCode, domain }: DeleteShortUrl, { getState }): Promise<DeleteShortUrl> => { async ({ shortCode, domain }: ShortUrlIdentifier, { getState }): Promise<ShortUrlIdentifier> => {
const { deleteShortUrl: shlinkDeleteShortUrl } = buildShlinkApiClient(getState); const { deleteShortUrl: shlinkDeleteShortUrl } = buildShlinkApiClient(getState);
await shlinkDeleteShortUrl(shortCode, domain); await shlinkDeleteShortUrl(shortCode, domain);
return { shortCode, domain }; return { shortCode, domain };

View file

@ -1,7 +1,6 @@
import { createSlice, PayloadAction } from '@reduxjs/toolkit'; import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import { createAsyncThunk } from '../../utils/helpers/redux'; import { createAsyncThunk } from '../../utils/helpers/redux';
import { OptionalString } from '../../utils/utils'; import { EditShortUrlData, ShortUrl, ShortUrlIdentifier } from '../data';
import { EditShortUrlData, ShortUrl } from '../data';
import { ShlinkApiClientBuilder } from '../../api/services/ShlinkApiClientBuilder'; import { ShlinkApiClientBuilder } from '../../api/services/ShlinkApiClientBuilder';
import { parseApiError } from '../../api/utils'; import { parseApiError } from '../../api/utils';
import { ProblemDetailsError } from '../../api/types/errors'; import { ProblemDetailsError } from '../../api/types/errors';
@ -16,9 +15,7 @@ export interface ShortUrlEdition {
errorData?: ProblemDetailsError; errorData?: ProblemDetailsError;
} }
export interface EditShortUrl { export interface EditShortUrl extends ShortUrlIdentifier {
shortCode: string;
domain?: OptionalString;
data: EditShortUrlData; data: EditShortUrlData;
} }