@shopgate/engage 7.22.0-beta.2 → 7.22.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/checkout/paymentMethods/index.js +10 -3
- package/locations/actions/fetchDefaultLocation.js +4 -0
- package/locations/actions/index.js +1 -1
- package/locations/actions/sendDefaultLocationCode.js +6 -0
- package/locations/components/GlobalLocationSelector/GlobalLocationSelector.js +0 -1
- package/locations/components/StoreFinder/StoreFinderSelectLocationButton.js +1 -1
- package/locations/components/StoreList/StoreSelectLocationButton.js +1 -1
- package/locations/subscriptions.js +14 -12
- package/package.json +8 -8
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import _regeneratorRuntime from"@babel/runtime/regenerator";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);}function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value;}catch(error){reject(error);return;}if(info.done){resolve(value);}else{Promise.resolve(value).then(_next,_throw);}}function _asyncToGenerator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value);}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err);}_next(undefined);});};}function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance");}function _iterableToArrayLimit(arr,i){var _arr=[];var _n=true;var _d=false;var _e=undefined;try{for(var _i=arr[Symbol.iterator](),_s;!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break;}}catch(err){_d=true;_e=err;}finally{try{if(!_n&&_i["return"]!=null)_i["return"]();}finally{if(_d)throw _e;}}return _arr;}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr;}import React,{useContext,useCallback,useEffect,useMemo,useRef,useState}from'react';import{connect}from'react-redux';import PropTypes from'prop-types';import{css}from'glamor';import{themeConfig}from'@shopgate/pwa-common/helpers/config';import{getPaymentMethods}from"../selectors/payment";import{getCheckoutOrder}from"../selectors/order";import CheckoutContext from"../providers/CheckoutProvider.context";import{updateCheckoutOrder}from"../actions/updateCheckoutOrder";import{fetchCheckoutOrder}from"../actions/fetchCheckoutOrder";import{i18n}from"../../core/helpers/i18n";import Context from"./context";import paypal from"./paypal";import stripe from"./stripe";var AVAILABLE_PAYMENT_METHOD=[paypal,stripe];/**
|
|
1
|
+
import _regeneratorRuntime from"@babel/runtime/regenerator";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);}function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value;}catch(error){reject(error);return;}if(info.done){resolve(value);}else{Promise.resolve(value).then(_next,_throw);}}function _asyncToGenerator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value);}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err);}_next(undefined);});};}function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance");}function _iterableToArrayLimit(arr,i){var _arr=[];var _n=true;var _d=false;var _e=undefined;try{for(var _i=arr[Symbol.iterator](),_s;!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break;}}catch(err){_d=true;_e=err;}finally{try{if(!_n&&_i["return"]!=null)_i["return"]();}finally{if(_d)throw _e;}}return _arr;}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr;}import React,{useContext,useCallback,useEffect,useMemo,useRef,useState}from'react';import{connect,useStore}from'react-redux';import PropTypes from'prop-types';import{css}from'glamor';import{themeConfig}from'@shopgate/pwa-common/helpers/config';import{getPaymentMethods}from"../selectors/payment";import{getCheckoutOrder}from"../selectors/order";import CheckoutContext from"../providers/CheckoutProvider.context";import{updateCheckoutOrder}from"../actions/updateCheckoutOrder";import{fetchCheckoutOrder}from"../actions/fetchCheckoutOrder";import{i18n}from"../../core/helpers/i18n";import Context from"./context";import paypal from"./paypal";import stripe from"./stripe";var AVAILABLE_PAYMENT_METHOD=[paypal,stripe];/**
|
|
2
2
|
* Maps state to props
|
|
3
3
|
* @param {Object} state State
|
|
4
4
|
* @returns {Object}
|
|
@@ -16,6 +16,13 @@ var paymentMethodCode=useMemo(function(){var _order$paymentTransac;var transacti
|
|
|
16
16
|
useEffect(function(){setPaymentHandler({getSupportsRedirect:(paymentImpl===null||paymentImpl===void 0?void 0:paymentImpl.getSupportsRedirect)||function(){return true;},getCustomPayButton:function getCustomPayButton(){return paymentImpl===null||paymentImpl===void 0?void 0:paymentImpl.payButton;},fulfillTransaction:function(){var _fulfillTransaction=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref2){var paymentTransactions,resolved;return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:paymentTransactions=_ref2.paymentTransactions;_context.next=3;return paymentMethodRef.current.fulfillTransaction({paymentTransactions:paymentTransactions});case 3:resolved=_context.sent;return _context.abrupt("return",resolved);case 5:case"end":return _context.stop();}},_callee);}));function fulfillTransaction(_x){return _fulfillTransaction.apply(this,arguments);}return fulfillTransaction;}()});},[paymentImpl,setButtonLocked,setPaymentHandler]);// Map configured payment methods
|
|
17
17
|
var availablePaymentMethods=useMemo(function(){return paymentMethods.map(function(method){return _extends({},AVAILABLE_PAYMENT_METHOD.find(function(m){return m.code===method.paymentProvider.code;}),{internalCode:method.code,settings:method.settings});});},[paymentMethods]);// Change payment method.
|
|
18
18
|
var handleChangePayment=useCallback(/*#__PURE__*/function(){var _ref3=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(code){var meta,_args2=arguments;return _regeneratorRuntime.wrap(function _callee2$(_context2){while(1)switch(_context2.prev=_context2.next){case 0:meta=_args2.length>1&&_args2[1]!==undefined?_args2[1]:null;if(!(paymentMethodCode===code)){_context2.next=5;break;}setActivePaymentMeta(meta);setPaymentData({meta:meta});return _context2.abrupt("return");case 5:setLocked(true);_context2.next=8;return updateOrder({paymentTransactions:[{paymentMethod:{code:code}}]});case 8:_context2.next=10;return fetchOrder();case 10:setActivePaymentMeta(meta);setPaymentData({meta:meta});setLocked(false);case 13:case"end":return _context2.stop();}},_callee2);}));return function(_x2){return _ref3.apply(this,arguments);};}(),[setPaymentData,paymentMethodCode,setLocked,updateOrder,fetchOrder]);// API for the underlying payment methods.
|
|
19
|
-
var paymentMethodApi=useMemo(function(){return{registerPaymentMethod:function registerPaymentMethod(api){setButtonLocked(false);paymentMethodRef.current=api;}};},[setButtonLocked]);// Ignore for ROPIS.
|
|
19
|
+
var paymentMethodApi=useMemo(function(){return{registerPaymentMethod:function registerPaymentMethod(api){setButtonLocked(false);paymentMethodRef.current=api;}};},[setButtonLocked]);var store=useStore();// Ignore for ROPIS.
|
|
20
20
|
if(!needsPayment){return null;}// Render the respective payment method provider.
|
|
21
|
-
var _ref4=paymentImpl||{},Provider=_ref4.provider,Content=_ref4.content;return React.createElement(Context.Provider,{value:paymentMethodApi},React.createElement("div",{className:styles.section},React.createElement("h3",{className:styles.headline},i18n.text('checkout.payment.title')),React.createElement("div",{className:styles.buttons},availablePaymentMethods.map(function(method){return React.createElement(method.button,{key:method.internalCode,settings:method.settings,onChange:function onChange(meta){return handleChangePayment(method.internalCode,meta);},active:method.internalCode===paymentMethodCode,activePaymentMeta:activePaymentMeta});})),paymentImpl?React.createElement(Provider
|
|
21
|
+
var _ref4=paymentImpl||{},Provider=_ref4.provider,Content=_ref4.content;return React.createElement(Context.Provider,{value:paymentMethodApi},React.createElement("div",{className:styles.section},React.createElement("h3",{className:styles.headline},i18n.text('checkout.payment.title')),React.createElement("div",{className:styles.buttons},availablePaymentMethods.map(function(method){return React.createElement(method.button,{key:method.internalCode,settings:method.settings,onChange:function onChange(meta){return handleChangePayment(method.internalCode,meta);},active:method.internalCode===paymentMethodCode,activePaymentMeta:activePaymentMeta});})),paymentImpl?React.createElement(Provider/**
|
|
22
|
+
* 2025-01-10: Not 100% sure why a context is being passed here. It seems to work
|
|
23
|
+
* without it, but since the payment component implementation has a high complexity,
|
|
24
|
+
* but isn't really used right now in production shops, i kept it for now.
|
|
25
|
+
* To enable compatibility with react-redux > 7, the "store" prop was added so that
|
|
26
|
+
* Redux connected child components can still access the store.
|
|
27
|
+
* Should be revisited when the "native checkout" gets relevance.
|
|
28
|
+
*/,{context:Context,store:store,data:paymentData,activePaymentMeta:activePaymentMeta},React.createElement(Content,null)):null));};PaymentMethodProvider.defaultProps={order:null,paymentMethods:null};export default connect(mapStateToProps,mapDispatchToProps)(PaymentMethodProvider);
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import _regeneratorRuntime from"@babel/runtime/regenerator";function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value;}catch(error){reject(error);return;}if(info.done){resolve(value);}else{Promise.resolve(value).then(_next,_throw);}}function _asyncToGenerator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value);}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err);}_next(undefined);});};}import{PipelineRequest}from"../../core";import selectLocation from"../action-creators/selectLocation";/**
|
|
2
|
+
* Fetches the default location of the user
|
|
3
|
+
* @returns {Function} redux thunk
|
|
4
|
+
*/var fetchDefaultLocation=function fetchDefaultLocation(){return(/*#__PURE__*/function(){var _ref=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(dispatch){var request,_ref2,location;return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:request=new PipelineRequest('shopgate.user.getDefaultLocation').dispatch();_context.next=3;return request;case 3:_ref2=_context.sent;location=_ref2.location;if(location){dispatch(selectLocation(location));}return _context.abrupt("return",request);case 7:case"end":return _context.stop();}},_callee);}));return function(_x){return _ref.apply(this,arguments);};}());};export default fetchDefaultLocation;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{SET_LOCATIONS_PENDING}from"../constants/ActionTypes";export{default as fetchFulfillmentSlots}from"./fetchFulfillmentSlots";export{default as fetchInventories}from"./fetchInventories";export{default as fetchLocations}from"./fetchLocations";export{default as fetchProductInventories}from"./fetchProductInventories";export{default as fetchProductLocations}from"./fetchProductLocations";export{default as submitReservation}from"./submitReservation";export{default as setUserSearchGeolocation}from"./setUserSearchGeolocation";export{default as setUserGeolocation}from"./setUserGeolocation";/**
|
|
1
|
+
import{SET_LOCATIONS_PENDING}from"../constants/ActionTypes";export{default as fetchFulfillmentSlots}from"./fetchFulfillmentSlots";export{default as fetchInventories}from"./fetchInventories";export{default as fetchLocations}from"./fetchLocations";export{default as fetchProductInventories}from"./fetchProductInventories";export{default as fetchProductLocations}from"./fetchProductLocations";export{default as submitReservation}from"./submitReservation";export{default as setUserSearchGeolocation}from"./setUserSearchGeolocation";export{default as setUserGeolocation}from"./setUserGeolocation";export{default as sendDefaultLocationCode}from"./sendDefaultLocationCode";export{default as fetchDefaultLocation}from"./fetchDefaultLocation";/**
|
|
2
2
|
* Sets pending state of locations
|
|
3
3
|
* @param {boolean} value Value
|
|
4
4
|
* @returns {Object}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{PipelineRequest}from"../../core";/**
|
|
2
|
+
* pipeline call to shopgate.user.sendDefaultLocationCodeCode.v1
|
|
3
|
+
* to set user default location in data base
|
|
4
|
+
* @param {string} locationCode The location code to send to backend
|
|
5
|
+
* @returns {Function} redux thunk
|
|
6
|
+
*/var sendDefaultLocationCode=function sendDefaultLocationCode(locationCode){return function(){return new PipelineRequest('shopgate.user.setDefaultLocationCode').setInput({locationCode:locationCode}).dispatch();};};export default sendDefaultLocationCode;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import React,{useCallback,useMemo}from'react';import PropTypes from'prop-types';import{connect}from'react-redux';import{getCurrentRoute}from'@shopgate/pwa-common/selectors/router';import{selectGlobalLocation}from'@shopgate/engage/locations/action-creators';import{getPreferredLocation,getIsPending}from"../../selectors";import{getIsLocationBasedShopping}from"../../../core/selectors";import{FulfillmentSheet}from"../FulfillmentSheet";import{STAGE_SELECT_STORE,MULTI_LINE_RESERVE}from"../../constants";/**
|
|
2
2
|
* Maps state to props.
|
|
3
3
|
* @param {Object} state State
|
|
4
|
-
* @param {Object} props Props
|
|
5
4
|
* @return {Object}
|
|
6
5
|
*/var mapStateToProps=function mapStateToProps(state){return{currentRoute:getCurrentRoute(state),isLocationBasedShopping:getIsLocationBasedShopping(state),isPending:getIsPending(state),preferredLocation:getPreferredLocation(state)};};/**
|
|
7
6
|
* Maps the contents of the state to the component props.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React,{useCallback,useContext}from'react';import{RippleButton}from'@shopgate/engage/components';import{StoreContext}from"./Store.context";import{i18n}from"../../../core";import{StoreFinderContext}from"../../locations.context";import{selectLocationButton,selectLocationButtonWrapper}from"../StoreList/Store.style";/**
|
|
2
2
|
* The StoreFinderSelectLocationButton component.
|
|
3
3
|
* Renders if route query.selectLocation param is passed
|
|
4
|
-
* @returns {JSX}
|
|
4
|
+
* @returns {JSX.Element}
|
|
5
5
|
*/export var StoreFinderSelectLocationButton=function StoreFinderSelectLocationButton(){var store=useContext(StoreContext);var _useContext=useContext(StoreFinderContext),selectLocation=_useContext.selectLocation,isLoading=_useContext.isLoading;var handleClick=useCallback(function(e){e.stopPropagation();selectLocation(store);},[selectLocation,store]);return React.createElement("div",{className:selectLocationButtonWrapper},React.createElement(RippleButton,{onClick:handleClick,className:selectLocationButton.toString(),disabled:isLoading||(store===null||store===void 0?void 0:store.isComingSoon)},i18n.text('locations.select_location')));};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React,{useContext,useCallback}from'react';import{RippleButton}from'@shopgate/engage/components';import PropTypes from'prop-types';import{isProductAvailable}from"../../helpers";import{StoreContext}from"./Store.context";import{i18n,useWidgetSettings}from"../../../core";import{FulfillmentContext}from"../../locations.context";import{selectLocationButton,selectLocationButtonWrapper}from"./Store.style";import connect from"./StoreListSearch.connector";/**
|
|
2
2
|
* The StoreSelectLocationButton component.
|
|
3
|
-
* @returns {JSX}
|
|
3
|
+
* @returns {JSX.Element}
|
|
4
4
|
*/var StoreSelectLocationButton=function StoreSelectLocationButton(_ref){var setPostalCode=_ref.setPostalCode;var store=useContext(StoreContext);var _ref2=useWidgetSettings('@shopgate/engage/locations')||{},_ref2$setUserSearchZi=_ref2.setUserSearchZipLocationFromSelection,setUserSearchZipLocationFromSelection=_ref2$setUserSearchZi===void 0?true:_ref2$setUserSearchZi;var _useContext=useContext(FulfillmentContext),selectLocation=_useContext.selectLocation,noInventory=_useContext.noInventory,isLoading=_useContext.isLoading,product=_useContext.product;var isAvailable=isProductAvailable(store,store===null||store===void 0?void 0:store.inventory);var handleClick=useCallback(function(e){e.stopPropagation();if(noInventory||isAvailable){if(setUserSearchZipLocationFromSelection){setPostalCode(store.address.postalCode,product===null||product===void 0?void 0:product.id);}selectLocation(store);}},[isAvailable,noInventory,product,selectLocation,setPostalCode,setUserSearchZipLocationFromSelection,store]);return React.createElement("div",{className:selectLocationButtonWrapper},React.createElement(RippleButton,{onClick:handleClick,className:selectLocationButton.toString(),disabled:isLoading||(store===null||store===void 0?void 0:store.isComingSoon)||!noInventory&&!isAvailable},i18n.text('locations.select_location')));};var connectedStoreSelectLocationButton=connect(StoreSelectLocationButton);export{connectedStoreSelectLocationButton as StoreSelectLocationButton};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import _regeneratorRuntime from"@babel/runtime/regenerator";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);}function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value;}catch(error){reject(error);return;}if(info.done){resolve(value);}else{Promise.resolve(value).then(_next,_throw);}}function _asyncToGenerator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value);}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err);}_next(undefined);});};}import{getProductsResult,productIsReady$,productsReceived$,productsReceivedCached$,RECEIVE_PRODUCTS_CACHED,variantDidChange$}from'@shopgate/engage/product';import{cartReceived$,fetchCart,cartDidEnter$,getCartItems}from'@shopgate/engage/cart';import{userDidLogin$}from'@shopgate/engage/user';import{appDidStart$,routeWillEnter$,UIEvents,getCurrentRoute,hex2bin,getThemeSettings,getCurrentSearchQuery}from'@shopgate/engage/core';import{receiveFavoritesWhileVisible$}from'@shopgate/pwa-common-commerce/favorites/streams';import{getFavoritesProductsIds,isFetching}from'@shopgate/pwa-common-commerce/favorites/selectors';import{categoryDidBackEnter$}from'@shopgate/pwa-common-commerce/category/streams';import{searchDidBackEntered$}from'@shopgate/pwa-common-commerce/search/streams';import{hasNewServices}from'@shopgate/engage/core/helpers';import{cookieConsentInitialized$}from'@shopgate/engage/tracking/streams';import{getUserSearch,getStoreFinderSearch,getPreferredLocation,getIsPending,getProductAlternativeLocationParams,getProductAlternativeLocations}from"./selectors";import{fetchLocations,fetchProductLocations,setPending,setUserGeolocation}from"./actions";import{setShowInventoryInLists,showInventoryInLists}from"./helpers
|
|
1
|
+
import _regeneratorRuntime from"@babel/runtime/regenerator";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);}function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value;}catch(error){reject(error);return;}if(info.done){resolve(value);}else{Promise.resolve(value).then(_next,_throw);}}function _asyncToGenerator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value);}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err);}_next(undefined);});};}import{getProductsResult,productIsReady$,productsReceived$,productsReceivedCached$,RECEIVE_PRODUCTS_CACHED,variantDidChange$}from'@shopgate/engage/product';import{cartReceived$,fetchCart,cartDidEnter$,getCartItems}from'@shopgate/engage/cart';import{userDidLogin$}from'@shopgate/engage/user';import{appDidStart$,routeWillEnter$,UIEvents,getCurrentRoute,hex2bin,getThemeSettings,getCurrentSearchQuery,appWillInit$,appInitialization}from'@shopgate/engage/core';import{receiveFavoritesWhileVisible$}from'@shopgate/pwa-common-commerce/favorites/streams';import{getFavoritesProductsIds,isFetching}from'@shopgate/pwa-common-commerce/favorites/selectors';import{categoryDidBackEnter$}from'@shopgate/pwa-common-commerce/category/streams';import{searchDidBackEntered$}from'@shopgate/pwa-common-commerce/search/streams';import{hasNewServices}from'@shopgate/engage/core/helpers';import{cookieConsentInitialized$}from'@shopgate/engage/tracking/streams';import{getUserSearch,getStoreFinderSearch,getPreferredLocation,getIsPending,getProductAlternativeLocationParams,getProductAlternativeLocations}from"./selectors";import{fetchDefaultLocation,fetchLocations,fetchProductLocations,sendDefaultLocationCode,setPending,setUserGeolocation}from"./actions";import{setShowInventoryInLists,showInventoryInLists}from"./helpers";import fetchInventories from"./actions/fetchInventories";import{EVENT_SET_OPEN}from"./providers/FulfillmentProvider";import fetchProductInventories from"./actions/fetchProductInventories";import{submitReservationSuccess$,userSearchChanged$,storeFinderWillEnter$,preferredLocationDidUpdateOnPDP$,provideAlternativeLocation$,preferredLocationDidUpdateGlobalOnWishlist$,preferredLocationDidUpdate$}from"./locations.streams";import selectLocation from"./action-creators/selectLocation";import{SET_STORE_FINDER_SEARCH_RADIUS}from"./constants";import selectGlobalLocation from"./action-creators/selectGlobalLocation";var initialLocationsResolve;var initialLocationsReject;var initialLocationsPromise=new Promise(function(resolve,reject){initialLocationsResolve=resolve;initialLocationsReject=reject;});/**
|
|
2
2
|
* Sets a location once the location has been validated.
|
|
3
3
|
* @param {string} locationCode Location code
|
|
4
4
|
* @param {Function} dispatch Redux dispatch function
|
|
@@ -6,22 +6,24 @@ import _regeneratorRuntime from"@babel/runtime/regenerator";function _extends(){
|
|
|
6
6
|
*/var setLocationOnceAvailable=/*#__PURE__*/function(){var _ref=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(locationCode,dispatch){var _ref3,initialLocations;return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:_context.prev=0;_context.next=3;return initialLocationsPromise;case 3:_ref3=_context.sent;initialLocations=_ref3.locations;if(initialLocations.some(function(l){return l.code===locationCode;})){_context.next=7;break;}return _context.abrupt("return");case 7:dispatch(selectLocation({code:locationCode}));requestAnimationFrame(function(){dispatch(setPending(false));});_context.next=13;break;case 11:_context.prev=11;_context.t0=_context["catch"](0);case 13:case"end":return _context.stop();}},_callee,null,[[0,11]]);}));return function setLocationOnceAvailable(_x,_x2){return _ref.apply(this,arguments);};}();/**
|
|
7
7
|
* Locations subscriptions.
|
|
8
8
|
* @param {Function} subscribe The subscribe function.
|
|
9
|
-
*/function locationsSubscriber(subscribe){subscribe(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
*/function locationsSubscriber(subscribe){subscribe(appWillInit$,function(){appInitialization.set('location',/*#__PURE__*/function(){var _ref5=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref4){var dispatch,getState,location;return _regeneratorRuntime.wrap(function _callee2$(_context2){while(1)switch(_context2.prev=_context2.next){case 0:dispatch=_ref4.dispatch,getState=_ref4.getState;// check if location was set by user and is stored in redux
|
|
10
|
+
location=getPreferredLocation(getState());// if NO location has been set: get location from backend and set in redux
|
|
11
|
+
if(!(!location&&hasNewServices())){_context2.next=5;break;}_context2.next=5;return dispatch(fetchDefaultLocation());case 5:case"end":return _context2.stop();}},_callee2);}));return function(_x3){return _ref5.apply(this,arguments);};}());});subscribe(preferredLocationDidUpdate$,function(_ref6){var dispatch=_ref6.dispatch,getState=_ref6.getState;var preferredLocation=getPreferredLocation(getState());if(preferredLocation){dispatch(sendDefaultLocationCode(preferredLocation.code));}});subscribe(cookieConsentInitialized$,/*#__PURE__*/function(){var _ref8=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(_ref7){var dispatch,getState,userSearch,_ref10,locations,preferredLocation,code,hasLocation,_ref12,preferredLocationDefault,locationToPreselect;return _regeneratorRuntime.wrap(function _callee3$(_context3){while(1)switch(_context3.prev=_context3.next){case 0:dispatch=_ref7.dispatch,getState=_ref7.getState;if(hasNewServices()){_context3.next=3;break;}return _context3.abrupt("return");case 3:// Fetch merchants locations.
|
|
12
|
+
userSearch=getUserSearch(getState());_context3.prev=4;_context3.next=7;return dispatch(fetchLocations(userSearch));case 7:_ref10=_context3.sent;locations=_ref10.locations;preferredLocation=getPreferredLocation(getState());if(!preferredLocation){_context3.next=16;break;}code=preferredLocation.code;// Check if the preferred location is included within the fetched locations
|
|
13
|
+
hasLocation=!!locations.find(function(location){return location.code===code;});if(hasLocation){_context3.next=16;break;}_context3.next=16;return dispatch(fetchLocations({codes:[code]}));case 16:// Preset preferredLocation if configured
|
|
14
|
+
_ref12=getThemeSettings('@shopgate/engage/locations')||{},preferredLocationDefault=_ref12.preferredLocationDefault;if(preferredLocationDefault){// check if there is already a preferredLocation for the user, if not set one
|
|
15
|
+
if(!preferredLocation){locationToPreselect=locations.find(function(l){return l.code===preferredLocationDefault;});if(locationToPreselect){dispatch(selectLocation({code:preferredLocationDefault}));}}}initialLocationsResolve(locations);_context3.next=24;break;case 21:_context3.prev=21;_context3.t0=_context3["catch"](4);initialLocationsReject(_context3.t0);case 24:UIEvents.addListener(EVENT_SET_OPEN,function(){var route=getCurrentRoute(getState());if(!route.params.productId&&!route.state.productId){return;}var productId=route.state.productId||hex2bin(route.params.productId);if(productId){dispatch(fetchProductLocations(productId,getUserSearch(getState())));}});case 25:case"end":return _context3.stop();}},_callee3,null,[[4,21]]);}));return function(_x4){return _ref8.apply(this,arguments);};}());subscribe(userSearchChanged$,/*#__PURE__*/function(){var _ref14=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(_ref13){var dispatch,getState,action,productId,isStoreFinder,silent,state,userSearch,storeFinderSearch;return _regeneratorRuntime.wrap(function _callee4$(_context4){while(1)switch(_context4.prev=_context4.next){case 0:dispatch=_ref13.dispatch,getState=_ref13.getState,action=_ref13.action;productId=action.productId,isStoreFinder=action.isStoreFinder,silent=action.silent;if(!(silent===true)){_context4.next=4;break;}return _context4.abrupt("return");case 4:state=getState();userSearch=getUserSearch(state);if(!(isStoreFinder||action.type===SET_STORE_FINDER_SEARCH_RADIUS)){_context4.next=12;break;}storeFinderSearch=getStoreFinderSearch(state);_context4.next=10;return dispatch(fetchLocations(_extends({},userSearch,{},storeFinderSearch,{enableInLocationFinder:true})));case 10:_context4.next=19;break;case 12:if(productId){_context4.next=17;break;}_context4.next=15;return dispatch(fetchLocations(userSearch));case 15:_context4.next=19;break;case 17:_context4.next=19;return dispatch(fetchProductLocations(productId,userSearch));case 19:case"end":return _context4.stop();}},_callee4);}));return function(_x5){return _ref14.apply(this,arguments);};}());var productInventoryNeedsUpdate$=productIsReady$.merge(variantDidChange$).merge(preferredLocationDidUpdateOnPDP$).debounceTime(200);subscribe(productInventoryNeedsUpdate$,function(_ref15){var action=_ref15.action,dispatch=_ref15.dispatch,getState=_ref15.getState;var productData=action.productData;// Skip if no fulfillment methods are set.
|
|
14
16
|
if(!productData||!productData.fulfillmentMethods||productData.fulfillmentMethods.length===0){return;}var state=getState();var preferredLocation=getPreferredLocation(state);if(!preferredLocation){return;}// Fetch inventories for this specific product.
|
|
15
17
|
dispatch(fetchProductInventories(action.productData.id,{locationCodes:[preferredLocation.code]}));});// Core config and cart subscriptions
|
|
16
|
-
var fetchCart$=cartDidEnter$.switchMap(function(){return submitReservationSuccess$.first();}).delay(500);subscribe(fetchCart$,function(
|
|
17
|
-
userSearch=getUserSearch(state);storeFinderSearch=getStoreFinderSearch(state);
|
|
18
|
+
var fetchCart$=cartDidEnter$.switchMap(function(){return submitReservationSuccess$.first();}).delay(500);subscribe(fetchCart$,function(_ref16){var dispatch=_ref16.dispatch;dispatch(fetchCart());});subscribe(storeFinderWillEnter$,/*#__PURE__*/function(){var _ref18=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5(_ref17){var dispatch,getState,state,userSearch,storeFinderSearch;return _regeneratorRuntime.wrap(function _callee5$(_context5){while(1)switch(_context5.prev=_context5.next){case 0:dispatch=_ref17.dispatch,getState=_ref17.getState;state=getState();// Fetch merchants locations.
|
|
19
|
+
userSearch=getUserSearch(state);storeFinderSearch=getStoreFinderSearch(state);_context5.next=6;return dispatch(fetchLocations(_extends({},userSearch,{},storeFinderSearch,{enableInLocationFinder:true})));case 6:case"end":return _context5.stop();}},_callee5);}));return function(_x6){return _ref18.apply(this,arguments);};}());/**
|
|
18
20
|
* Makes sure that the active location is switched after logging in
|
|
19
21
|
* to a location that is also available in the cart.
|
|
20
22
|
* Avoids having a selected location that differs from the cart
|
|
21
|
-
*/var afterCartMerge$=userDidLogin$.mergeMap(function(){return cartReceived$.first();});subscribe(afterCartMerge$,/*#__PURE__*/function(){var
|
|
23
|
+
*/var afterCartMerge$=userDidLogin$.mergeMap(function(){return cartReceived$.first();});subscribe(afterCartMerge$,/*#__PURE__*/function(){var _ref20=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6(_ref19){var _cartItems$,_cartItems$$fulfillme,_cartItems$$fulfillme2;var dispatch,getState,state,cartItems,preferredLocation,activeCartLocation,firstLocationCode;return _regeneratorRuntime.wrap(function _callee6$(_context6){while(1)switch(_context6.prev=_context6.next){case 0:dispatch=_ref19.dispatch,getState=_ref19.getState;state=getState();cartItems=getCartItems(state);preferredLocation=getPreferredLocation(state,{});if(cartItems===null||cartItems===void 0?void 0:cartItems.length){_context6.next=6;break;}return _context6.abrupt("return");case 6:activeCartLocation=cartItems.find(function(item){var _item$fulfillment,_item$fulfillment$loc;return((_item$fulfillment=item.fulfillment)===null||_item$fulfillment===void 0?void 0:(_item$fulfillment$loc=_item$fulfillment.location)===null||_item$fulfillment$loc===void 0?void 0:_item$fulfillment$loc.code)===(preferredLocation===null||preferredLocation===void 0?void 0:preferredLocation.code);});if(!activeCartLocation){_context6.next=9;break;}return _context6.abrupt("return");case 9:firstLocationCode=(_cartItems$=cartItems[0])===null||_cartItems$===void 0?void 0:(_cartItems$$fulfillme=_cartItems$.fulfillment)===null||_cartItems$$fulfillme===void 0?void 0:(_cartItems$$fulfillme2=_cartItems$$fulfillme.location)===null||_cartItems$$fulfillme2===void 0?void 0:_cartItems$$fulfillme2.code;if(firstLocationCode){_context6.next=12;break;}return _context6.abrupt("return");case 12:dispatch(selectLocation({code:firstLocationCode}));dispatch(selectGlobalLocation({code:firstLocationCode}));case 14:case"end":return _context6.stop();}},_callee6);}));return function(_x7){return _ref20.apply(this,arguments);};}());/**
|
|
22
24
|
* Handles an added store url parameter that will set the default store location
|
|
23
|
-
*/subscribe(routeWillEnter$,function(
|
|
25
|
+
*/subscribe(routeWillEnter$,function(_ref21){var action=_ref21.action,dispatch=_ref21.dispatch,getState=_ref21.getState;var locationCode=action.route.query.store;if(!locationCode){if(!getIsPending(getState())){dispatch(setPending(false));}return;}setLocationOnceAvailable(locationCode,dispatch);});var alternative$=productInventoryNeedsUpdate$.switchMap(function(){return provideAlternativeLocation$.first();});/**
|
|
24
26
|
* Provide alternative location on PDP when preferred location is out of stock
|
|
25
|
-
*/subscribe(alternative$,/*#__PURE__*/function(){var
|
|
26
|
-
state=getState();alternativeLocations=getProductAlternativeLocations(state,action);if(!alternativeLocations){
|
|
27
|
+
*/subscribe(alternative$,/*#__PURE__*/function(){var _ref23=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee7(_ref22){var action,dispatch,getState,state,alternativeLocations,productId,params,alternativeParams,fetchParams;return _regeneratorRuntime.wrap(function _callee7$(_context7){while(1)switch(_context7.prev=_context7.next){case 0:action=_ref22.action,dispatch=_ref22.dispatch,getState=_ref22.getState;_context7.next=3;return dispatch(setUserGeolocation({silent:true}));case 3:// Get new state with geolocation
|
|
28
|
+
state=getState();alternativeLocations=getProductAlternativeLocations(state,action);if(!alternativeLocations){_context7.next=7;break;}return _context7.abrupt("return");case 7:productId=action.productId,params=action.params;alternativeParams=getProductAlternativeLocationParams(state);fetchParams=_extends({},alternativeParams,{},params);if(fetchParams.geolocation||fetchParams.postalCode){dispatch(fetchProductLocations(productId,fetchParams));}case 11:case"end":return _context7.stop();}},_callee7);}));return function(_x8){return _ref23.apply(this,arguments);};}());subscribe(categoryDidBackEnter$.merge(searchDidBackEntered$),function(_ref24){var _getProductsResult;var action=_ref24.action,dispatch=_ref24.dispatch,getState=_ref24.getState;var state=getState();if(!showInventoryInLists(state)){return;}var categoryId=action.route.params.categoryId;var query=getCurrentSearchQuery(state);var products=(_getProductsResult=getProductsResult(state,{categoryId:hex2bin(categoryId),searchPhrase:query}))===null||_getProductsResult===void 0?void 0:_getProductsResult.products;if(!products||!products.length){return;}var productCodes=products.map(function(_ref25){var id=_ref25.id;return id;});dispatch(fetchInventories(productCodes));});subscribe(productsReceived$.merge(productsReceivedCached$),function(_ref26){var action=_ref26.action,dispatch=_ref26.dispatch,getState=_ref26.getState;if(!showInventoryInLists(getState())){return;}if(!action.products||!action.products.length||(action===null||action===void 0?void 0:action.fetchInventory)===false){return;}var productCodes=action.type!==RECEIVE_PRODUCTS_CACHED?action.products.map(function(_ref27){var id=_ref27.id;return id;}):action.products;dispatch(fetchInventories(productCodes));});subscribe(receiveFavoritesWhileVisible$.merge(preferredLocationDidUpdateGlobalOnWishlist$),function(_ref28){var dispatch=_ref28.dispatch,getState=_ref28.getState;var state=getState();if(!showInventoryInLists(state)||isFetching(getState())){return;}var productIds=getFavoritesProductsIds(state);if(!productIds||!productIds.length){return;}dispatch(fetchInventories(productIds));});subscribe(appDidStart$,function(_ref29){var getState=_ref29.getState;// enable inventory in product lists for some users
|
|
27
29
|
setShowInventoryInLists(getState());});}export default locationsSubscriber;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shopgate/engage",
|
|
3
|
-
"version": "7.22.0-beta.
|
|
3
|
+
"version": "7.22.0-beta.4",
|
|
4
4
|
"description": "Shopgate's ENGAGE library.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Shopgate <support@shopgate.com>",
|
|
@@ -16,13 +16,13 @@
|
|
|
16
16
|
],
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@shopgate/native-modules": "1.0.0-beta.18",
|
|
19
|
-
"@shopgate/pwa-common": "7.22.0-beta.
|
|
20
|
-
"@shopgate/pwa-common-commerce": "7.22.0-beta.
|
|
21
|
-
"@shopgate/pwa-core": "7.22.0-beta.
|
|
22
|
-
"@shopgate/pwa-ui-ios": "7.22.0-beta.
|
|
23
|
-
"@shopgate/pwa-ui-material": "7.22.0-beta.
|
|
24
|
-
"@shopgate/pwa-ui-shared": "7.22.0-beta.
|
|
25
|
-
"@stripe/react-stripe-js": "^1.
|
|
19
|
+
"@shopgate/pwa-common": "7.22.0-beta.4",
|
|
20
|
+
"@shopgate/pwa-common-commerce": "7.22.0-beta.4",
|
|
21
|
+
"@shopgate/pwa-core": "7.22.0-beta.4",
|
|
22
|
+
"@shopgate/pwa-ui-ios": "7.22.0-beta.4",
|
|
23
|
+
"@shopgate/pwa-ui-material": "7.22.0-beta.4",
|
|
24
|
+
"@shopgate/pwa-ui-shared": "7.22.0-beta.4",
|
|
25
|
+
"@stripe/react-stripe-js": "^1.16.5",
|
|
26
26
|
"@stripe/stripe-js": "^1.3.1",
|
|
27
27
|
"@virtuous/conductor": "~2.5.0",
|
|
28
28
|
"babel-plugin-transform-es3-member-expression-literals": "^6.8.0",
|