strapi-plugin-config-sync/admin/src/state/actions/Config.js

71 lines
2.0 KiB
JavaScript
Raw Normal View History

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() {
return async function(dispatch, getState, toggleNotification) {
2021-03-21 17:55:14 +01:00
dispatch(setLoadingState(true));
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) {
toggleNotification({ type: 'warning', message: { id: 'notification.error' } });
2021-03-21 17:55:14 +01:00
dispatch(setLoadingState(false));
}
2021-10-14 17:13:12 +02: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) {
return {
2021-03-24 18:41:03 +01:00
type: SET_CONFIG_DIFF_IN_STATE,
config,
};
2021-03-20 16:51:34 +01:00
}
export function exportAllConfig() {
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 {
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
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) {
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
}
export function importAllConfig() {
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 {
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
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) {
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
}