UNPKG

@plone/volto

Version:
63 lines (59 loc) 1.4 kB
import { GET_CONTENT_RULES_EVENTS } from '@plone/volto/constants/ActionTypes'; const initialState = { get: { loaded: false, loading: false, error: null, }, items: [], }; /** * Get request key * @function getRequestKey * @param {string} actionType Action type. * @returns {string} Request key. */ function getRequestKey(actionType) { return actionType.split('_')[0].toLowerCase(); } /** * Rules reducer. * @function rules * @param {Object} state Current state. * @param {Object} action Action to be handled. * @returns {Object} New state. */ export default function contentrulesevents(state = initialState, action = {}) { switch (action.type) { case `${GET_CONTENT_RULES_EVENTS}_PENDING`: return { ...state, [getRequestKey(action.type)]: { loading: true, loaded: false, error: null, }, }; case `${GET_CONTENT_RULES_EVENTS}_SUCCESS`: return { ...state, items: action.result?.items, [getRequestKey(action.type)]: { loading: false, loaded: true, error: null, }, }; case `${GET_CONTENT_RULES_EVENTS}_FAIL`: return { ...state, [getRequestKey(action.type)]: { loading: false, loaded: false, error: action.error, }, }; default: return state; } }