Fixed validation and added toasts

This commit is contained in:
Ildar Kamalov
2019-01-21 11:55:39 +03:00
committed by Eugene Bujak
parent 2bd4840ba5
commit a7416f9c34
9 changed files with 68 additions and 34 deletions

View File

@@ -1,8 +1,10 @@
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 { INSTALL_FIRST_STEP } from '../helpers/constants';
const install = handleActions({
[actions.getDefaultAddressesRequest]: state => ({ ...state, processingDefault: true }),
@@ -19,11 +21,40 @@ const install = handleActions({
[actions.setAllSettingsFailure]: state => ({ ...state, processingSubmit: false }),
[actions.setAllSettingsSuccess]: state => ({ ...state, processingSubmit: false }),
}, {
step: 1,
step: INSTALL_FIRST_STEP,
processingDefault: true,
});
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,
form: formReducer,
});