2019-12-04 18:52:38 +00:00
|
|
|
import { createAction } from 'redux-actions';
|
|
|
|
|
|
|
|
import apiClient from '../api/Api';
|
2020-04-22 16:32:07 +00:00
|
|
|
import { normalizeTextarea } from '../helpers/helpers';
|
2020-05-22 14:06:05 +00:00
|
|
|
import { addErrorToast, addSuccessToast } from './toasts';
|
2019-12-04 18:52:38 +00:00
|
|
|
|
|
|
|
export const getDnsConfigRequest = createAction('GET_DNS_CONFIG_REQUEST');
|
|
|
|
export const getDnsConfigFailure = createAction('GET_DNS_CONFIG_FAILURE');
|
|
|
|
export const getDnsConfigSuccess = createAction('GET_DNS_CONFIG_SUCCESS');
|
|
|
|
|
|
|
|
export const getDnsConfig = () => async (dispatch) => {
|
|
|
|
dispatch(getDnsConfigRequest());
|
|
|
|
try {
|
|
|
|
const data = await apiClient.getDnsConfig();
|
|
|
|
dispatch(getDnsConfigSuccess(data));
|
|
|
|
} catch (error) {
|
|
|
|
dispatch(addErrorToast({ error }));
|
|
|
|
dispatch(getDnsConfigFailure());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export const setDnsConfigRequest = createAction('SET_DNS_CONFIG_REQUEST');
|
|
|
|
export const setDnsConfigFailure = createAction('SET_DNS_CONFIG_FAILURE');
|
|
|
|
export const setDnsConfigSuccess = createAction('SET_DNS_CONFIG_SUCCESS');
|
|
|
|
|
2020-05-22 14:06:05 +00:00
|
|
|
export const setDnsConfig = (config) => async (dispatch) => {
|
2019-12-04 18:52:38 +00:00
|
|
|
dispatch(setDnsConfigRequest());
|
|
|
|
try {
|
2020-04-22 16:32:07 +00:00
|
|
|
const data = { ...config };
|
|
|
|
|
|
|
|
let hasDnsSettings = false;
|
|
|
|
if (Object.prototype.hasOwnProperty.call(data, 'bootstrap_dns')) {
|
|
|
|
data.bootstrap_dns = normalizeTextarea(config.bootstrap_dns);
|
|
|
|
hasDnsSettings = true;
|
|
|
|
}
|
|
|
|
if (Object.prototype.hasOwnProperty.call(data, 'upstream_dns')) {
|
|
|
|
data.upstream_dns = normalizeTextarea(config.upstream_dns);
|
|
|
|
hasDnsSettings = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
await apiClient.setDnsConfig(data);
|
|
|
|
|
|
|
|
if (hasDnsSettings) {
|
|
|
|
dispatch(addSuccessToast('updated_upstream_dns_toast'));
|
|
|
|
} else {
|
|
|
|
dispatch(addSuccessToast('config_successfully_saved'));
|
|
|
|
}
|
|
|
|
|
2019-12-04 18:52:38 +00:00
|
|
|
dispatch(setDnsConfigSuccess(config));
|
|
|
|
} catch (error) {
|
|
|
|
dispatch(addErrorToast({ error }));
|
|
|
|
dispatch(setDnsConfigFailure());
|
|
|
|
}
|
|
|
|
};
|