2021-03-20 00:54:18 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Main actions
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { request } from 'strapi-helper-plugin';
|
|
|
|
import { Map } from 'immutable';
|
|
|
|
|
2021-03-24 18:41:03 +01:00
|
|
|
export function getAllConfigDiff() {
|
2021-03-20 03:20:48 +01:00
|
|
|
return async function(dispatch) {
|
2021-03-21 17:55:14 +01:00
|
|
|
dispatch(setLoadingState(true));
|
2021-03-20 03:20:48 +01:00
|
|
|
try {
|
2021-03-24 18:41:03 +01:00
|
|
|
const configDiff = await request('/config-sync/diff', { method: 'GET' });
|
|
|
|
dispatch(setConfigDiffInState(configDiff));
|
2021-03-21 17:55:14 +01:00
|
|
|
dispatch(setLoadingState(false));
|
2021-03-20 03:20:48 +01:00
|
|
|
} catch(err) {
|
|
|
|
strapi.notification.error('notification.error');
|
2021-03-21 17:55:14 +01:00
|
|
|
dispatch(setLoadingState(false));
|
2021-03-20 03:20:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-24 18:41:03 +01:00
|
|
|
export const SET_CONFIG_DIFF_IN_STATE = 'SET_CONFIG_DIFF_IN_STATE';
|
|
|
|
export function setConfigDiffInState(config) {
|
2021-03-20 03:20:48 +01:00
|
|
|
return {
|
2021-03-24 18:41:03 +01:00
|
|
|
type: SET_CONFIG_DIFF_IN_STATE,
|
2021-03-20 03:20:48 +01:00
|
|
|
config,
|
|
|
|
};
|
2021-03-20 16:51:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export function exportAllConfig() {
|
|
|
|
return async function(dispatch) {
|
2021-03-21 17:55:14 +01:00
|
|
|
dispatch(setLoadingState(true));
|
2021-03-20 16:51:34 +01:00
|
|
|
try {
|
2021-03-21 18:04:18 +01:00
|
|
|
const { message } = await request('/config-sync/export', { method: 'GET' });
|
2021-03-24 18:41:03 +01:00
|
|
|
dispatch(setConfigDiffInState(Map({})));
|
2021-03-20 16:51:34 +01:00
|
|
|
|
|
|
|
strapi.notification.success(message);
|
2021-03-21 17:55:14 +01:00
|
|
|
dispatch(setLoadingState(false));
|
2021-03-20 16:51:34 +01:00
|
|
|
} catch(err) {
|
|
|
|
strapi.notification.error('notification.error');
|
2021-03-21 17:55:14 +01:00
|
|
|
dispatch(setLoadingState(false));
|
2021-03-20 16:51:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function importAllConfig() {
|
|
|
|
return async function(dispatch) {
|
2021-03-21 17:55:14 +01:00
|
|
|
dispatch(setLoadingState(true));
|
2021-03-20 16:51:34 +01:00
|
|
|
try {
|
2021-03-21 18:04:18 +01:00
|
|
|
const { message } = await request('/config-sync/import', { method: 'GET' });
|
2021-03-24 19:17:07 +01:00
|
|
|
dispatch(setConfigDiffInState(Map({})));
|
2021-03-20 16:51:34 +01:00
|
|
|
|
|
|
|
strapi.notification.success(message);
|
2021-03-21 17:55:14 +01:00
|
|
|
dispatch(setLoadingState(false));
|
2021-03-20 16:51:34 +01:00
|
|
|
} catch(err) {
|
|
|
|
strapi.notification.error('notification.error');
|
2021-03-21 17:55:14 +01:00
|
|
|
dispatch(setLoadingState(false));
|
2021-03-20 16:51:34 +01:00
|
|
|
}
|
|
|
|
}
|
2021-03-21 17:55:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export const SET_LOADING_STATE = 'SET_LOADING_STATE';
|
|
|
|
export function setLoadingState(value) {
|
|
|
|
return {
|
|
|
|
type: SET_LOADING_STATE,
|
|
|
|
value,
|
|
|
|
};
|
2021-03-20 03:20:48 +01:00
|
|
|
}
|