2019-01-18 17:17:48 +00:00
|
|
|
import { combineReducers } from 'redux';
|
|
|
|
import { handleActions } from 'redux-actions';
|
|
|
|
import { reducer as formReducer } from 'redux-form';
|
2019-01-21 08:55:39 +00:00
|
|
|
import nanoid from 'nanoid';
|
2019-01-18 17:17:48 +00:00
|
|
|
|
|
|
|
import * as actions from '../actions/install';
|
2019-01-21 08:55:39 +00:00
|
|
|
import { INSTALL_FIRST_STEP } from '../helpers/constants';
|
2019-01-18 17:17:48 +00:00
|
|
|
|
|
|
|
const install = handleActions({
|
|
|
|
[actions.getDefaultAddressesRequest]: state => ({ ...state, processingDefault: true }),
|
|
|
|
[actions.getDefaultAddressesFailure]: state => ({ ...state, processingDefault: false }),
|
|
|
|
[actions.getDefaultAddressesSuccess]: (state, { payload }) => {
|
|
|
|
const newState = { ...state, ...payload, processingDefault: false };
|
|
|
|
return newState;
|
|
|
|
},
|
|
|
|
|
|
|
|
[actions.nextStep]: state => ({ ...state, step: state.step + 1 }),
|
|
|
|
[actions.prevStep]: state => ({ ...state, step: state.step - 1 }),
|
|
|
|
|
|
|
|
[actions.setAllSettingsRequest]: state => ({ ...state, processingSubmit: true }),
|
|
|
|
[actions.setAllSettingsFailure]: state => ({ ...state, processingSubmit: false }),
|
|
|
|
[actions.setAllSettingsSuccess]: state => ({ ...state, processingSubmit: false }),
|
|
|
|
}, {
|
2019-01-21 08:55:39 +00:00
|
|
|
step: INSTALL_FIRST_STEP,
|
2019-01-18 17:17:48 +00:00
|
|
|
processingDefault: true,
|
|
|
|
});
|
|
|
|
|
2019-01-21 08:55:39 +00:00
|
|
|
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: [] });
|
|
|
|
|
2019-01-18 17:17:48 +00:00
|
|
|
export default combineReducers({
|
|
|
|
install,
|
2019-01-21 08:55:39 +00:00
|
|
|
toasts,
|
2019-01-18 17:17:48 +00:00
|
|
|
form: formReducer,
|
|
|
|
});
|