77import { request } from 'strapi-helper-plugin' ;
88import { Map } from 'immutable' ;
99
10- export function getAllDatabaseConfig ( ) {
10+ export function getAllConfig ( ) {
1111 return async function ( dispatch ) {
12+ dispatch ( setLoadingState ( true ) ) ;
1213 try {
13- const data = await request ( '/config/all/from-database' , { method : 'GET' } ) ;
14- dispatch ( setDatabaseConfigInState ( data ) ) ;
15-
16- strapi . notification . success ( 'woop!' ) ;
17- } catch ( err ) {
18- console . log ( err ) ;
19- strapi . notification . error ( 'notification.error' ) ;
20- }
21- }
22- }
23-
24- export function getAllFileConfig ( ) {
25- return async function ( dispatch ) {
26- try {
27- const data = await request ( '/config/all/from-files' , { method : 'GET' } ) ;
28- dispatch ( setFileConfigInState ( data ) ) ;
29-
30- strapi . notification . success ( 'woop!' ) ;
14+ const databaseConfig = await request ( '/config/all/from-database' , { method : 'GET' } ) ;
15+ const fileConfig = await request ( '/config/all/from-files' , { method : 'GET' } ) ;
16+ dispatch ( setFileConfigInState ( fileConfig ) ) ;
17+ dispatch ( setDatabaseConfigInState ( databaseConfig ) ) ;
18+ dispatch ( setLoadingState ( false ) ) ;
3119 } catch ( err ) {
32- console . log ( err ) ;
3320 strapi . notification . error ( 'notification.error' ) ;
21+ dispatch ( setLoadingState ( false ) ) ;
3422 }
3523 }
3624}
@@ -53,30 +41,42 @@ export function setFileConfigInState(config) {
5341
5442export function exportAllConfig ( ) {
5543 return async function ( dispatch ) {
44+ dispatch ( setLoadingState ( true ) ) ;
5645 try {
5746 const { message } = await request ( '/config/export' , { method : 'GET' } ) ;
58- dispatch ( getAllFileConfig ( ) ) ;
59- dispatch ( getAllDatabaseConfig ( ) ) ;
47+ dispatch ( setFileConfigInState ( Map ( { } ) ) ) ;
48+ dispatch ( setDatabaseConfigInState ( Map ( { } ) ) ) ;
6049
6150 strapi . notification . success ( message ) ;
51+ dispatch ( setLoadingState ( false ) ) ;
6252 } catch ( err ) {
63- console . log ( err ) ;
6453 strapi . notification . error ( 'notification.error' ) ;
54+ dispatch ( setLoadingState ( false ) ) ;
6555 }
6656 }
6757}
6858
6959export function importAllConfig ( ) {
7060 return async function ( dispatch ) {
61+ dispatch ( setLoadingState ( true ) ) ;
7162 try {
7263 const { message } = await request ( '/config/import' , { method : 'GET' } ) ;
73- dispatch ( getAllFileConfig ( ) ) ;
74- dispatch ( getAllDatabaseConfig ( ) ) ;
64+ dispatch ( setFileConfigInState ( Map ( { } ) ) ) ;
65+ dispatch ( setDatabaseConfigInState ( Map ( { } ) ) ) ;
7566
7667 strapi . notification . success ( message ) ;
68+ dispatch ( setLoadingState ( false ) ) ;
7769 } catch ( err ) {
78- console . log ( err ) ;
7970 strapi . notification . error ( 'notification.error' ) ;
71+ dispatch ( setLoadingState ( false ) ) ;
8072 }
8173 }
74+ }
75+
76+ export const SET_LOADING_STATE = 'SET_LOADING_STATE' ;
77+ export function setLoadingState ( value ) {
78+ return {
79+ type : SET_LOADING_STATE ,
80+ value,
81+ } ;
8282}
0 commit comments