mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-10 02:07:26 +03:00
Migrated tagDeleted action to payload
This commit is contained in:
parent
dbb08a6ce0
commit
22b3794154
4 changed files with 7 additions and 8 deletions
|
@ -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 { buildReducer } from '../../utils/helpers/redux';
|
||||||
import { GetState } from '../../container/types';
|
import { GetState } from '../../container/types';
|
||||||
import { ShlinkApiClientBuilder } from '../../api/services/ShlinkApiClientBuilder';
|
import { ShlinkApiClientBuilder } from '../../api/services/ShlinkApiClientBuilder';
|
||||||
|
@ -18,9 +19,7 @@ export interface TagDeletion {
|
||||||
errorData?: ProblemDetailsError;
|
errorData?: ProblemDetailsError;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DeleteTagAction extends Action<string> {
|
export type DeleteTagAction = PayloadAction<string>;
|
||||||
tag: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const initialState: TagDeletion = {
|
const initialState: TagDeletion = {
|
||||||
deleting: false,
|
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_START]: () => ({ ...initialState, loading: true }),
|
||||||
[LIST_TAGS_ERROR]: (_, { errorData }) => ({ ...initialState, error: true, errorData }),
|
[LIST_TAGS_ERROR]: (_, { errorData }) => ({ ...initialState, error: true, errorData }),
|
||||||
[LIST_TAGS]: (_, { tags, stats }) => ({ ...initialState, stats, tags, filteredTags: tags }),
|
[LIST_TAGS]: (_, { tags, stats }) => ({ ...initialState, stats, tags, filteredTags: tags }),
|
||||||
[TAG_DELETED]: (state, { tag }) => ({
|
[TAG_DELETED]: (state, { payload: tag }) => ({
|
||||||
...state,
|
...state,
|
||||||
tags: rejectTag(state.tags, tag),
|
tags: rejectTag(state.tags, tag),
|
||||||
filteredTags: rejectTag(state.filteredTags, tag),
|
filteredTags: rejectTag(state.filteredTags, tag),
|
||||||
|
|
|
@ -41,7 +41,7 @@ describe('tagDeleteReducer', () => {
|
||||||
it('returns action based on provided params', () =>
|
it('returns action based on provided params', () =>
|
||||||
expect(tagDeleted('foo')).toEqual({
|
expect(tagDeleted('foo')).toEqual({
|
||||||
type: TAG_DELETED,
|
type: TAG_DELETED,
|
||||||
tag: 'foo',
|
payload: 'foo',
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ describe('tagsListReducer', () => {
|
||||||
const tag = 'foo';
|
const tag = 'foo';
|
||||||
const expectedTags = ['bar', 'baz'];
|
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,
|
tags: expectedTags,
|
||||||
filteredTags: expectedTags,
|
filteredTags: expectedTags,
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue