diff --git a/src/tags/reducers/tagDelete.ts b/src/tags/reducers/tagDelete.ts index 2c6683d6..ec5e3ebe 100644 --- a/src/tags/reducers/tagDelete.ts +++ b/src/tags/reducers/tagDelete.ts @@ -1,4 +1,5 @@ -import { Action, Dispatch } from 'redux'; +import { createAction, PayloadAction } from '@reduxjs/toolkit'; +import { Dispatch } from 'redux'; import { buildReducer } from '../../utils/helpers/redux'; import { GetState } from '../../container/types'; import { ShlinkApiClientBuilder } from '../../api/services/ShlinkApiClientBuilder'; @@ -18,9 +19,7 @@ export interface TagDeletion { errorData?: ProblemDetailsError; } -export interface DeleteTagAction extends Action { - tag: string; -} +export type DeleteTagAction = PayloadAction; const initialState: TagDeletion = { deleting: false, @@ -51,4 +50,4 @@ export const deleteTag = (buildShlinkApiClient: ShlinkApiClientBuilder) => (tag: } }; -export const tagDeleted = (tag: string): DeleteTagAction => ({ type: TAG_DELETED, tag }); +export const tagDeleted = createAction(TAG_DELETED); diff --git a/src/tags/reducers/tagsList.ts b/src/tags/reducers/tagsList.ts index ae52954e..b954e04d 100644 --- a/src/tags/reducers/tagsList.ts +++ b/src/tags/reducers/tagsList.ts @@ -85,7 +85,7 @@ export default buildReducer({ [LIST_TAGS_START]: () => ({ ...initialState, loading: true }), [LIST_TAGS_ERROR]: (_, { errorData }) => ({ ...initialState, error: true, errorData }), [LIST_TAGS]: (_, { tags, stats }) => ({ ...initialState, stats, tags, filteredTags: tags }), - [TAG_DELETED]: (state, { tag }) => ({ + [TAG_DELETED]: (state, { payload: tag }) => ({ ...state, tags: rejectTag(state.tags, tag), filteredTags: rejectTag(state.filteredTags, tag), diff --git a/test/tags/reducers/tagDelete.test.ts b/test/tags/reducers/tagDelete.test.ts index cb05952c..c87e2bfd 100644 --- a/test/tags/reducers/tagDelete.test.ts +++ b/test/tags/reducers/tagDelete.test.ts @@ -41,7 +41,7 @@ describe('tagDeleteReducer', () => { it('returns action based on provided params', () => expect(tagDeleted('foo')).toEqual({ type: TAG_DELETED, - tag: 'foo', + payload: 'foo', })); }); diff --git a/test/tags/reducers/tagsList.test.ts b/test/tags/reducers/tagsList.test.ts index bce325b0..1fcb390e 100644 --- a/test/tags/reducers/tagsList.test.ts +++ b/test/tags/reducers/tagsList.test.ts @@ -48,7 +48,7 @@ describe('tagsListReducer', () => { const tag = 'foo'; const expectedTags = ['bar', 'baz']; - expect(reducer(state({ tags, filteredTags: tags }), { type: TAG_DELETED, tag } as any)).toEqual({ + expect(reducer(state({ tags, filteredTags: tags }), { type: TAG_DELETED, payload: tag } as any)).toEqual({ tags: expectedTags, filteredTags: expectedTags, });