2021-03-20 00:54:18 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Main actions
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { request } from 'strapi-helper-plugin';
|
|
|
|
import { Map } from 'immutable';
|
|
|
|
|
2021-03-21 17:55:14 +01:00
|
|
|
export function getAllConfig() {
|
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-21 18:04:18 +01:00
|
|
|
const databaseConfig = await request('/config-sync/all/from-database', { method: 'GET' });
|
|
|
|
const fileConfig = await request('/config-sync/all/from-files', { method: 'GET' });
|
2021-03-21 17:55:14 +01:00
|
|
|
dispatch(setFileConfigInState(fileConfig));
|
|
|
|
dispatch(setDatabaseConfigInState(databaseConfig));
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const SET_DATABASE_CONFIG_IN_STATE = 'SET_DATABASE_CONFIG_IN_STATE';
|
|
|
|
export function setDatabaseConfigInState(config) {
|
|
|
|
return {
|
|
|
|
type: SET_DATABASE_CONFIG_IN_STATE,
|
|
|
|
config,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export const SET_FILE_CONFIG_IN_STATE = 'SET_FILE_CONFIG_IN_STATE';
|
|
|
|
export function setFileConfigInState(config) {
|
|
|
|
return {
|
|
|
|
type: SET_FILE_CONFIG_IN_STATE,
|
|
|
|
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-21 17:55:14 +01:00
|
|
|
dispatch(setFileConfigInState(Map({})));
|
|
|
|
dispatch(setDatabaseConfigInState(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-21 17:55:14 +01:00
|
|
|
dispatch(setFileConfigInState(Map({})));
|
|
|
|
dispatch(setDatabaseConfigInState(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
|
|
|
}
|