File size: 1,260 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 |
import { withStorageKey } from '@automattic/state-utils';
import {
ALL_DOMAINS_REQUEST,
ALL_DOMAINS_REQUEST_FAILURE,
ALL_DOMAINS_REQUEST_SUCCESS,
} from 'calypso/state/action-types';
import { createLightSiteDomainObject } from 'calypso/state/all-domains/helpers';
import { combineReducers, withSchemaValidation } from 'calypso/state/utils';
import { allDomainsSchema } from './schema';
export const allDomains = withSchemaValidation( allDomainsSchema, ( state = [], action ) => {
switch ( action.type ) {
case ALL_DOMAINS_REQUEST_SUCCESS:
return ( action?.domains ?? [] ).map( createLightSiteDomainObject );
}
return state;
} );
export const errors = ( state = null, action ) => {
switch ( action.type ) {
case ALL_DOMAINS_REQUEST:
case ALL_DOMAINS_REQUEST_SUCCESS:
return null;
case ALL_DOMAINS_REQUEST_FAILURE:
return action.error;
}
return state;
};
export const requesting = ( state = false, action ) => {
switch ( action.type ) {
case ALL_DOMAINS_REQUEST:
case ALL_DOMAINS_REQUEST_FAILURE:
case ALL_DOMAINS_REQUEST_SUCCESS:
return action.type === ALL_DOMAINS_REQUEST;
}
return state;
};
export default withStorageKey(
'all-domains',
combineReducers( {
domains: allDomains,
requesting,
errors,
} )
);
|