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({
|
2020-05-22 14:06:05 +00:00
|
|
|
[actions.getDefaultAddressesRequest]: (state) => ({ ...state, processingDefault: true }),
|
|
|
|
[actions.getDefaultAddressesFailure]: (state) => ({ ...state, processingDefault: false }),
|
2019-01-18 17:17:48 +00:00
|
|
|
[actions.getDefaultAddressesSuccess]: (state, { payload }) => {
|
2019-04-17 11:50:27 +00:00
|
|
|
const { interfaces } = payload;
|
2019-04-22 09:25:40 +00:00
|
|
|
const web = { ...state.web, port: payload.web_port };
|
|
|
|
const dns = { ...state.dns, port: payload.dns_port };
|
2019-04-17 11:50:27 +00:00
|
|
|
|
|
|
|
const newState = {
|
|
|
|
...state, web, dns, interfaces, processingDefault: false,
|
|
|
|
};
|
2019-01-18 17:17:48 +00:00
|
|
|
return newState;
|
|
|
|
},
|
|
|
|
|
2020-05-22 14:06:05 +00:00
|
|
|
[actions.nextStep]: (state) => ({ ...state, step: state.step + 1 }),
|
|
|
|
[actions.prevStep]: (state) => ({ ...state, step: state.step - 1 }),
|
2019-01-18 17:17:48 +00:00
|
|
|
|
2020-05-22 14:06:05 +00:00
|
|
|
[actions.setAllSettingsRequest]: (state) => ({ ...state, processingSubmit: true }),
|
|
|
|
[actions.setAllSettingsFailure]: (state) => ({ ...state, processingSubmit: false }),
|
|
|
|
[actions.setAllSettingsSuccess]: (state) => ({ ...state, processingSubmit: false }),
|
2019-04-17 11:50:27 +00:00
|
|
|
|
2020-05-22 14:06:05 +00:00
|
|
|
[actions.checkConfigRequest]: (state) => ({ ...state, processingCheck: true }),
|
|
|
|
[actions.checkConfigFailure]: (state) => ({ ...state, processingCheck: false }),
|
2019-04-17 11:50:27 +00:00
|
|
|
[actions.checkConfigSuccess]: (state, { payload }) => {
|
|
|
|
const web = { ...state.web, ...payload.web };
|
|
|
|
const dns = { ...state.dns, ...payload.dns };
|
2020-02-13 15:42:07 +00:00
|
|
|
const staticIp = { ...state.staticIp, ...payload.static_ip };
|
2019-04-17 11:50:27 +00:00
|
|
|
|
|
|
|
const newState = {
|
2020-02-13 15:42:07 +00:00
|
|
|
...state, web, dns, staticIp, processingCheck: false,
|
2019-04-17 11:50:27 +00:00
|
|
|
};
|
|
|
|
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,
|
2019-04-17 11:50:27 +00:00
|
|
|
processingCheck: false,
|
2019-02-01 16:52:42 +00:00
|
|
|
web: {
|
|
|
|
ip: '0.0.0.0',
|
|
|
|
port: 80,
|
2019-04-17 11:50:27 +00:00
|
|
|
status: '',
|
|
|
|
can_autofix: false,
|
2019-02-01 16:52:42 +00:00
|
|
|
},
|
|
|
|
dns: {
|
|
|
|
ip: '0.0.0.0',
|
|
|
|
port: 53,
|
2019-04-17 11:50:27 +00:00
|
|
|
status: '',
|
|
|
|
can_autofix: false,
|
2019-02-01 16:52:42 +00:00
|
|
|
},
|
2020-02-13 15:42:07 +00:00
|
|
|
staticIp: {
|
|
|
|
static: '',
|
|
|
|
ip: '',
|
|
|
|
error: '',
|
|
|
|
},
|
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,
|
|
|
|
});
|