File size: 1,399 Bytes
1e92f2d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | import { withStorageKey } from '@automattic/state-utils';
import {
GOOGLE_MY_BUSINESS_STATS_FAILURE,
GOOGLE_MY_BUSINESS_STATS_RECEIVE,
GOOGLE_MY_BUSINESS_STATS_REQUEST,
} from 'calypso/state/action-types';
import { statsInterval } from 'calypso/state/google-my-business/ui/reducer';
import { combineReducers, keyedReducer } from 'calypso/state/utils';
const stats = ( state = null, action ) => {
switch ( action.type ) {
case GOOGLE_MY_BUSINESS_STATS_RECEIVE: {
const { data } = action;
return data;
}
case GOOGLE_MY_BUSINESS_STATS_REQUEST:
return null;
case GOOGLE_MY_BUSINESS_STATS_FAILURE:
return null;
}
return state;
};
const statsError = ( state = null, action ) => {
switch ( action.type ) {
case GOOGLE_MY_BUSINESS_STATS_RECEIVE:
return null;
case GOOGLE_MY_BUSINESS_STATS_REQUEST:
return null;
case GOOGLE_MY_BUSINESS_STATS_FAILURE: {
const { error } = action;
return error;
}
}
return state;
};
const combinedReducer = keyedReducer(
'siteId',
combineReducers( {
stats: keyedReducer(
'statType',
keyedReducer( 'interval', keyedReducer( 'aggregation', stats ) )
),
statsError: keyedReducer(
'statType',
keyedReducer( 'interval', keyedReducer( 'aggregation', statsError ) )
),
statsInterval: keyedReducer( 'statType', statsInterval ),
} )
);
export default withStorageKey( 'googleMyBusiness', combinedReducer );
|