From 85e2aab4df84b166eb14892759073c8dbae233a5 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Fri, 4 Nov 2022 19:39:15 +0100 Subject: [PATCH] Migrated appUpdated reducer to RTK --- src/app/reducers/appUpdates.ts | 24 +++++++++++------------- src/reducers/index.ts | 2 +- test/app/reducers/appUpdates.test.ts | 15 +++++---------- 3 files changed, 17 insertions(+), 24 deletions(-) diff --git a/src/app/reducers/appUpdates.ts b/src/app/reducers/appUpdates.ts index 36db12ec..7a74d537 100644 --- a/src/app/reducers/appUpdates.ts +++ b/src/app/reducers/appUpdates.ts @@ -1,16 +1,14 @@ -import { Action } from 'redux'; -import { buildActionCreator, buildReducer } from '../../utils/helpers/redux'; +import { createSlice } from '@reduxjs/toolkit'; -export const APP_UPDATE_AVAILABLE = 'shlink/appUpdates/APP_UPDATE_AVAILABLE'; -export const RESET_APP_UPDATE = 'shlink/appUpdates/RESET_APP_UPDATE'; +const { actions, reducer } = createSlice({ + name: 'appUpdatesReducer', + initialState: false, + reducers: { + appUpdateAvailable: () => true, + resetAppUpdate: () => false, + }, +}); -const initialState = false; +export const { appUpdateAvailable, resetAppUpdate } = actions; -export default buildReducer>({ - [APP_UPDATE_AVAILABLE]: () => true, - [RESET_APP_UPDATE]: () => false, -}, initialState); - -export const appUpdateAvailable = buildActionCreator(APP_UPDATE_AVAILABLE); - -export const resetAppUpdate = buildActionCreator(RESET_APP_UPDATE); +export const appUpdatesReducer = reducer; diff --git a/src/reducers/index.ts b/src/reducers/index.ts index 2d3e41ee..06d51d85 100644 --- a/src/reducers/index.ts +++ b/src/reducers/index.ts @@ -18,7 +18,7 @@ import tagEditReducer from '../tags/reducers/tagEdit'; import mercureInfoReducer from '../mercure/reducers/mercureInfo'; import settingsReducer from '../settings/reducers/settings'; import visitsOverviewReducer from '../visits/reducers/visitsOverview'; -import appUpdatesReducer from '../app/reducers/appUpdates'; +import { appUpdatesReducer } from '../app/reducers/appUpdates'; import sidebarReducer from '../common/reducers/sidebar'; import { ShlinkState } from '../container/types'; diff --git a/test/app/reducers/appUpdates.test.ts b/test/app/reducers/appUpdates.test.ts index 82a11f91..32070612 100644 --- a/test/app/reducers/appUpdates.test.ts +++ b/test/app/reducers/appUpdates.test.ts @@ -1,30 +1,25 @@ -import reducer, { - APP_UPDATE_AVAILABLE, - RESET_APP_UPDATE, - appUpdateAvailable, - resetAppUpdate, -} from '../../../src/app/reducers/appUpdates'; +import { appUpdatesReducer, appUpdateAvailable, resetAppUpdate } from '../../../src/app/reducers/appUpdates'; describe('appUpdatesReducer', () => { describe('reducer', () => { it('returns true on APP_UPDATE_AVAILABLE', () => { - expect(reducer(undefined, { type: APP_UPDATE_AVAILABLE })).toEqual(true); + expect(appUpdatesReducer(undefined, { type: appUpdateAvailable.toString() })).toEqual(true); }); it('returns false on RESET_APP_UPDATE', () => { - expect(reducer(undefined, { type: RESET_APP_UPDATE })).toEqual(false); + expect(appUpdatesReducer(undefined, { type: resetAppUpdate.toString() })).toEqual(false); }); }); describe('appUpdateAvailable', () => { it('creates expected action', () => { - expect(appUpdateAvailable()).toEqual({ type: APP_UPDATE_AVAILABLE }); + expect(appUpdateAvailable()).toEqual({ type: appUpdateAvailable.toString() }); }); }); describe('resetAppUpdate', () => { it('creates expected action', () => { - expect(resetAppUpdate()).toEqual({ type: RESET_APP_UPDATE }); + expect(resetAppUpdate()).toEqual({ type: resetAppUpdate.toString() }); }); }); });