@shopgate/engage
Version:
Shopgate's ENGAGE library.
6 lines • 1.32 kB
JavaScript
function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}import appConfig from'@shopgate/pwa-common/helpers/config';import{SET_USER_SEARCH_COUNTRY_CODE,SET_USER_SEARCH_POSTAL_CODE,SET_USER_SEARCH_GEOLOCATION,USER_SEARCH_GEOLOCATION_LIFETIME}from"../constants";export var defaultState={geolocation:null,postalCode:null,countryCode:appConfig.marketId};/**
* Stores the user's search input.
* @param {Object} state The current state.
* @param {Object} action The action Object
* @returns {Object} The new state.
*/export default function search(){var state=arguments.length>0&&arguments[0]!==undefined?arguments[0]:defaultState;var action=arguments.length>1?arguments[1]:undefined;switch(action.type){case SET_USER_SEARCH_COUNTRY_CODE:return _extends({},state,{countryCode:action.countryCode});case SET_USER_SEARCH_POSTAL_CODE:return _extends({},state,{geolocation:null,postalCode:action.postalCode});case SET_USER_SEARCH_GEOLOCATION:return _extends({},state,{geolocation:_extends({},action.geolocation,{expires:Date.now()+USER_SEARCH_GEOLOCATION_LIFETIME}),postalCode:null});default:return state;}}