Migrated tagDeleted action to payload

This commit is contained in:
Alejandro Celaya 2022-11-07 22:22:44 +01:00
parent dbb08a6ce0
commit 22b3794154
4 changed files with 7 additions and 8 deletions

View file

@ -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<string> {
tag: string;
}
export type DeleteTagAction = PayloadAction<string>;
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<string>(TAG_DELETED);

View file

@ -85,7 +85,7 @@ export default buildReducer<TagsList, TagsCombinedAction>({
[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),

View file

@ -41,7 +41,7 @@ describe('tagDeleteReducer', () => {
it('returns action based on provided params', () =>
expect(tagDeleted('foo')).toEqual({
type: TAG_DELETED,
tag: 'foo',
payload: 'foo',
}));
});

View file

@ -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,
});