mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-02-27 12:16:36 +00:00
Migrated tagDeleted action to payload
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -41,7 +41,7 @@ describe('tagDeleteReducer', () => {
|
||||
it('returns action based on provided params', () =>
|
||||
expect(tagDeleted('foo')).toEqual({
|
||||
type: TAG_DELETED,
|
||||
tag: 'foo',
|
||||
payload: 'foo',
|
||||
}));
|
||||
});
|
||||
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user