UNPKG

@shopgate/engage

Version:
6 lines 1.47 kB
import{produce}from'immer';import{SUCCESS_LOGOUT}from'@shopgate/engage/core/constants';import{FETCH_CUSTOMER_CONTACTS,FETCH_CUSTOMER_CONTACTS_SUCCESS,FETCH_CUSTOMER_CONTACTS_ERROR,FETCH_CUSTOMER,FETCH_CUSTOMER_SUCCESS,FETCH_CUSTOMER_ERROR}from"../constants/actions";var initialState={customer:{isFetching:false,data:null},contacts:{isFetching:false,items:[]}};/** * The reducer for all checkout related state. * @param {Object} state The application state. * @param {Object} action The redux action. * @returns {Object} */export default function checkoutReducer(){var state=arguments.length>0&&arguments[0]!==undefined?arguments[0]:initialState;var action=arguments.length>1?arguments[1]:undefined;/* eslint-disable no-param-reassign */var producer=produce(function(draft){switch(action.type){case FETCH_CUSTOMER_CONTACTS:{draft.contacts.isFetching=true;break;}case FETCH_CUSTOMER_CONTACTS_ERROR:{draft.contacts.isFetching=false;break;}case FETCH_CUSTOMER_CONTACTS_SUCCESS:{draft.contacts.isFetching=false;draft.contacts.items=action.contacts;break;}case FETCH_CUSTOMER:{draft.customer.isFetching=true;break;}case FETCH_CUSTOMER_ERROR:{draft.customer.isFetching=false;break;}case FETCH_CUSTOMER_SUCCESS:{draft.customer.isFetching=false;draft.customer.data=action.customer;break;}case SUCCESS_LOGOUT:{draft.customer=initialState.customer;draft.contacts=initialState.contacts;break;}default:break;}});/* eslint-enable no-param-reassign */return producer(state);}