2021-03-20 00:54:18 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Main actions
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2021-10-14 17:13:12 +02:00
|
|
|
import { request } from '@strapi/helper-plugin';
|
2021-03-20 00:54:18 +01:00
|
|
|
import { Map } from 'immutable';
|
|
|
|
|
2021-03-24 18:41:03 +01:00
|
|
|
export function getAllConfigDiff() {
|
2021-11-13 14:15:31 +01:00
|
|
|
return async function(dispatch, getState, toggleNotification) {
|
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-10-14 17:13:12 +02:00
|
|
|
} catch (err) {
|
2021-11-13 14:15:31 +01:00
|
|
|
toggleNotification({ type: 'warning', message: { id: 'notification.error' } });
|
2021-03-21 17:55:14 +01:00
|
|
|
dispatch(setLoadingState(false));
|
2021-03-20 03:20:48 +01:00
|
|
|
}
|
2021-10-14 17:13:12 +02:00
|
|
|
};
|
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
|
|
|
}
|
|
|
|
|
2021-11-20 19:06:01 +01:00
|
|
|
export const SET_CONFIG_PARTIAL_DIFF_IN_STATE = 'SET_CONFIG_PARTIAL_DIFF_IN_STATE';
|
|
|
|
export function setConfigPartialDiffInState(config) {
|
|
|
|
return {
|
|
|
|
type: SET_CONFIG_PARTIAL_DIFF_IN_STATE,
|
|
|
|
config,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function exportAllConfig(partialDiff) {
|
2021-11-13 14:15:31 +01:00
|
|
|
return async function(dispatch, getState, toggleNotification) {
|
2021-03-21 17:55:14 +01:00
|
|
|
dispatch(setLoadingState(true));
|
2021-03-20 16:51:34 +01:00
|
|
|
try {
|
2021-11-20 19:06:01 +01:00
|
|
|
const { message } = await request('/config-sync/export', {
|
|
|
|
method: 'POST',
|
|
|
|
body: partialDiff,
|
|
|
|
});
|
2021-11-13 14:15:31 +01:00
|
|
|
toggleNotification({ type: 'success', message });
|
2021-03-21 17:55:14 +01:00
|
|
|
dispatch(setLoadingState(false));
|
2021-10-14 17:13:12 +02:00
|
|
|
} catch (err) {
|
2021-11-13 14:15:31 +01:00
|
|
|
toggleNotification({ type: 'warning', message: { id: 'notification.error' } });
|
2021-03-21 17:55:14 +01:00
|
|
|
dispatch(setLoadingState(false));
|
2021-03-20 16:51:34 +01:00
|
|
|
}
|
2021-10-14 17:13:12 +02:00
|
|
|
};
|
2021-03-20 16:51:34 +01:00
|
|
|
}
|
|
|
|
|
2021-11-20 19:06:01 +01:00
|
|
|
export function importAllConfig(partialDiff) {
|
2021-11-13 14:15:31 +01:00
|
|
|
return async function(dispatch, getState, toggleNotification) {
|
2021-03-21 17:55:14 +01:00
|
|
|
dispatch(setLoadingState(true));
|
2021-03-20 16:51:34 +01:00
|
|
|
try {
|
2021-11-20 19:06:01 +01:00
|
|
|
const { message } = await request('/config-sync/import', {
|
|
|
|
method: 'POST',
|
|
|
|
body: partialDiff,
|
|
|
|
});
|
2021-11-13 14:15:31 +01:00
|
|
|
toggleNotification({ type: 'success', message });
|
2021-03-21 17:55:14 +01:00
|
|
|
dispatch(setLoadingState(false));
|
2021-10-14 17:13:12 +02:00
|
|
|
} catch (err) {
|
2021-11-13 14:15:31 +01:00
|
|
|
toggleNotification({ type: 'warning', message: { id: 'notification.error' } });
|
2021-03-21 17:55:14 +01:00
|
|
|
dispatch(setLoadingState(false));
|
2021-03-20 16:51:34 +01:00
|
|
|
}
|
2021-10-14 17:13:12 +02: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-10-14 17:13:12 +02:00
|
|
|
}
|