AdGuardHome/client/src/reducers/install.js

66 lines
2.1 KiB
JavaScript
Raw Normal View History

2019-01-18 17:17:48 +00:00
import { combineReducers } from 'redux';
import { handleActions } from 'redux-actions';
import { reducer as formReducer } from 'redux-form';
import * as actions from '../actions/install';
2019-02-07 12:40:26 +00:00
import toasts from './toasts';
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 { interfaces } = payload;
const web = { ...state.web, ...payload.web };
const dns = { ...state.dns, ...payload.dns };
const newState = {
...state, web, dns, interfaces, processingDefault: false,
};
2019-01-18 17:17:48 +00:00
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 }),
[actions.checkConfigRequest]: state => ({ ...state, processingCheck: true }),
[actions.checkConfigFailure]: state => ({ ...state, processingCheck: false }),
[actions.checkConfigSuccess]: (state, { payload }) => {
const web = { ...state.web, ...payload.web };
const dns = { ...state.dns, ...payload.dns };
const newState = {
...state, web, dns, processingCheck: false,
};
return newState;
},
2019-01-18 17:17:48 +00:00
}, {
2019-01-21 08:55:39 +00:00
step: INSTALL_FIRST_STEP,
2019-01-18 17:17:48 +00:00
processingDefault: true,
2019-02-07 13:09:12 +00:00
processingSubmit: false,
processingCheck: false,
2019-02-01 16:52:42 +00:00
web: {
ip: '0.0.0.0',
port: 80,
status: '',
can_autofix: false,
2019-02-01 16:52:42 +00:00
},
dns: {
ip: '0.0.0.0',
port: 53,
status: '',
can_autofix: false,
2019-02-01 16:52:42 +00:00
},
interfaces: {},
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,
});