diff --git a/client/src/actions/install.js b/client/src/actions/install.js index 3b612927..c6882daa 100644 --- a/client/src/actions/install.js +++ b/client/src/actions/install.js @@ -1,11 +1,9 @@ import { createAction } from 'redux-actions'; import Api from '../api/Api'; +import { addErrorToast, addSuccessToast } from './index'; const apiClient = new Api(); -export const addErrorToast = createAction('ADD_ERROR_TOAST'); -export const addSuccessToast = createAction('ADD_SUCCESS_TOAST'); -export const removeToast = createAction('REMOVE_TOAST'); export const nextStep = createAction('NEXT_STEP'); export const prevStep = createAction('PREV_STEP'); diff --git a/client/src/reducers/index.js b/client/src/reducers/index.js index f2e450ba..19bbbf63 100644 --- a/client/src/reducers/index.js +++ b/client/src/reducers/index.js @@ -1,11 +1,11 @@ import { combineReducers } from 'redux'; import { handleActions } from 'redux-actions'; import { loadingBarReducer } from 'react-redux-loading-bar'; -import nanoid from 'nanoid'; import { reducer as formReducer } from 'redux-form'; import versionCompare from '../helpers/versionCompare'; import * as actions from '../actions'; +import toasts from './toasts'; const settings = handleActions({ [actions.initSettingsRequest]: state => ({ ...state, processing: true }), @@ -241,34 +241,6 @@ const filtering = handleActions({ userRules: '', }); -const toasts = handleActions({ - [actions.addErrorToast]: (state, { payload }) => { - const errorToast = { - id: nanoid(), - message: payload.error.toString(), - type: 'error', - }; - - const newState = { ...state, notices: [...state.notices, errorToast] }; - return newState; - }, - [actions.addSuccessToast]: (state, { payload }) => { - const successToast = { - id: nanoid(), - message: payload, - type: 'success', - }; - - const newState = { ...state, notices: [...state.notices, successToast] }; - return newState; - }, - [actions.removeToast]: (state, { payload }) => { - const filtered = state.notices.filter(notice => notice.id !== payload); - const newState = { ...state, notices: filtered }; - return newState; - }, -}, { notices: [] }); - const dhcp = handleActions({ [actions.getDhcpStatusRequest]: state => ({ ...state, processing: true }), [actions.getDhcpStatusFailure]: state => ({ ...state, processing: false }), diff --git a/client/src/reducers/install.js b/client/src/reducers/install.js index 0df3c79e..08165072 100644 --- a/client/src/reducers/install.js +++ b/client/src/reducers/install.js @@ -1,9 +1,9 @@ import { combineReducers } from 'redux'; import { handleActions } from 'redux-actions'; import { reducer as formReducer } from 'redux-form'; -import nanoid from 'nanoid'; import * as actions from '../actions/install'; +import toasts from './toasts'; import { INSTALL_FIRST_STEP } from '../helpers/constants'; const install = handleActions({ @@ -39,34 +39,6 @@ const install = handleActions({ interfaces: {}, }); -const toasts = handleActions({ - [actions.addErrorToast]: (state, { payload }) => { - const errorToast = { - id: nanoid(), - message: payload.error.toString(), - type: 'error', - }; - - const newState = { ...state, notices: [...state.notices, errorToast] }; - return newState; - }, - [actions.addSuccessToast]: (state, { payload }) => { - const successToast = { - id: nanoid(), - message: payload, - type: 'success', - }; - - const newState = { ...state, notices: [...state.notices, successToast] }; - return newState; - }, - [actions.removeToast]: (state, { payload }) => { - const filtered = state.notices.filter(notice => notice.id !== payload); - const newState = { ...state, notices: filtered }; - return newState; - }, -}, { notices: [] }); - export default combineReducers({ install, toasts, diff --git a/client/src/reducers/toasts.js b/client/src/reducers/toasts.js new file mode 100644 index 00000000..c56085d3 --- /dev/null +++ b/client/src/reducers/toasts.js @@ -0,0 +1,34 @@ +import { handleActions } from 'redux-actions'; +import nanoid from 'nanoid'; + +import { addErrorToast, addSuccessToast, removeToast } from '../actions'; + +const toasts = handleActions({ + [addErrorToast]: (state, { payload }) => { + const errorToast = { + id: nanoid(), + message: payload.error.toString(), + type: 'error', + }; + + const newState = { ...state, notices: [...state.notices, errorToast] }; + return newState; + }, + [addSuccessToast]: (state, { payload }) => { + const successToast = { + id: nanoid(), + message: payload, + type: 'success', + }; + + const newState = { ...state, notices: [...state.notices, successToast] }; + return newState; + }, + [removeToast]: (state, { payload }) => { + const filtered = state.notices.filter(notice => notice.id !== payload); + const newState = { ...state, notices: filtered }; + return newState; + }, +}, { notices: [] }); + +export default toasts;