@shopgate/engage 6.21.0 → 6.22.0-beta.2
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/app-rating/action-creators/appStart.js +3 -3
- package/app-rating/action-creators/ordersPlaced.js +3 -3
- package/app-rating/action-creators/popup.js +4 -4
- package/app-rating/action-creators/timer.js +3 -3
- package/app-rating/actions/showModal.js +2 -2
- package/app-rating/constants/index.js +2 -2
- package/app-rating/reducers/index.js +2 -2
- package/app-rating/subscriptions/index.js +2 -2
- package/back-in-stock/actions/index.js +14 -0
- package/back-in-stock/components/BackInStockButton/connector.js +1 -0
- package/back-in-stock/components/BackInStockButton/index.js +13 -0
- package/back-in-stock/components/BackInStockButton/style.js +1 -0
- package/back-in-stock/components/CharacteristicsButton/connector.js +3 -0
- package/back-in-stock/components/CharacteristicsButton/index.js +8 -0
- package/back-in-stock/components/ProductInfoBackInStockButton/connector.js +3 -0
- package/back-in-stock/components/ProductInfoBackInStockButton/index.js +10 -0
- package/back-in-stock/components/Subscriptions/components/List/index.js +4 -0
- package/back-in-stock/components/Subscriptions/components/Subscription/connector.js +3 -0
- package/back-in-stock/components/Subscriptions/components/Subscription/index.js +7 -0
- package/back-in-stock/components/Subscriptions/index.js +4 -0
- package/back-in-stock/components/index.js +1 -0
- package/back-in-stock/constants/Actions.js +1 -0
- package/back-in-stock/constants/Common.js +1 -0
- package/back-in-stock/constants/Pipelines.js +1 -0
- package/back-in-stock/constants/Portals.js +9 -0
- package/back-in-stock/constants/index.js +1 -0
- package/back-in-stock/hooks/index.js +4 -0
- package/back-in-stock/providers/BackInStockSubscriptionsProvider.connector.js +7 -0
- package/back-in-stock/providers/BackInStockSubscriptionsProvider.context.js +1 -0
- package/back-in-stock/providers/BackInStockSubscriptionsProvider.js +5 -0
- package/back-in-stock/providers/index.js +1 -0
- package/back-in-stock/reducers/index.js +5 -0
- package/back-in-stock/selectors/index.js +24 -0
- package/back-in-stock/streams/index.js +1 -0
- package/back-in-stock/subscriptions/index.js +3 -0
- package/components/index.js +1 -1
- package/core/actions/__tests__/grantPermissions.spec.js +4 -4
- package/core/actions/grantPermissions.js +11 -4
- package/core/actions/grantPushPermissions.js +22 -0
- package/core/index.js +1 -1
- package/package.json +7 -7
- package/product/components/Characteristics/Characteristic/components/Sheet/index.js +2 -2
- package/product/components/Characteristics/Characteristic/components/SheetItem/index.js +3 -3
- package/product/components/Characteristics/Characteristic/components/SheetItem/style.js +1 -1
- package/product/index.js +1 -1
- package/product/selectors/product.js +5 -1
- package/product/selectors/variants.js +2 -2
- package/push-opt-in/action-creators/index.js +1 -0
- package/push-opt-in/action-creators/optInTrigger.js +23 -0
- package/push-opt-in/actions/index.js +1 -0
- package/push-opt-in/actions/optInTrigger.js +6 -0
- package/push-opt-in/constants/index.js +1 -0
- package/push-opt-in/constants/optInTrigger.js +1 -0
- package/push-opt-in/reducers/index.js +1 -0
- package/push-opt-in/reducers/optInTrigger.js +6 -0
- package/push-opt-in/selectors/index.js +1 -0
- package/push-opt-in/selectors/optInTrigger.js +5 -0
- package/push-opt-in/subscriptions/index.js +1 -0
- package/push-opt-in/subscriptions/optInTrigger.js +12 -0
- package/push-opt-in/subscriptions/optInTrigger.spec.js +41 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{APP_RATING_RESET_APP_START_COUNT,APP_RATING_INCREASE_APP_START_COUNT}from"../constants";/**
|
|
2
2
|
* Increment the app start count
|
|
3
3
|
* @return {Object} The dispatched action object.
|
|
4
|
-
*/export var increaseAppStartCount=function increaseAppStartCount(){return{type:
|
|
4
|
+
*/export var increaseAppStartCount=function increaseAppStartCount(){return{type:APP_RATING_INCREASE_APP_START_COUNT};};/**
|
|
5
5
|
* Reset the app start count, and increment reset counts
|
|
6
6
|
* @return {Object} The dispatched action object.
|
|
7
|
-
*/export var resetAppStartCount=function resetAppStartCount(){return{type:
|
|
7
|
+
*/export var resetAppStartCount=function resetAppStartCount(){return{type:APP_RATING_RESET_APP_START_COUNT};};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{APP_RATING_RESET_ORDERS_PLACED_COUNT,APP_RATING_INCREASE_ORDERS_PLACED_COUNT}from"../constants";/**
|
|
2
2
|
* Increment the orders placed count
|
|
3
3
|
* @return {Object} The dispatched action object.
|
|
4
|
-
*/export var increaseOrdersPlacedCount=function increaseOrdersPlacedCount(){return{type:
|
|
4
|
+
*/export var increaseOrdersPlacedCount=function increaseOrdersPlacedCount(){return{type:APP_RATING_INCREASE_ORDERS_PLACED_COUNT};};/**
|
|
5
5
|
* Reset the orders placed count, and increment reset counts
|
|
6
6
|
* @return {Object} The dispatched action object.
|
|
7
|
-
*/export var resetOrdersPlacedCount=function resetOrdersPlacedCount(){return{type:
|
|
7
|
+
*/export var resetOrdersPlacedCount=function resetOrdersPlacedCount(){return{type:APP_RATING_RESET_ORDERS_PLACED_COUNT};};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{APP_RATING_INCREASE_REJECTION_COUNT,APP_RATING_SET_ALREADY_RATED,APP_RATING_SET_LAST_POPUP_TIMESTAMP}from"../constants";/**
|
|
2
2
|
* Sets the last popup timestamp
|
|
3
3
|
* @return {Object} The dispatched action object.
|
|
4
|
-
*/export var setLastPopupTimestamp=function setLastPopupTimestamp(){return{type:
|
|
4
|
+
*/export var setLastPopupTimestamp=function setLastPopupTimestamp(){return{type:APP_RATING_SET_LAST_POPUP_TIMESTAMP};};/**
|
|
5
5
|
* Sets the last popup timestamp
|
|
6
6
|
* @return {Object} The dispatched action object.
|
|
7
|
-
*/export var increaseRejectionCount=function increaseRejectionCount(){return{type:
|
|
7
|
+
*/export var increaseRejectionCount=function increaseRejectionCount(){return{type:APP_RATING_INCREASE_REJECTION_COUNT};};/**
|
|
8
8
|
* Sets the last popup timestamp
|
|
9
9
|
* @param {boolean} to the value to set the rated status
|
|
10
10
|
* @return {Object} The dispatched action object.
|
|
11
|
-
*/export var setAlreadyRated=function setAlreadyRated(to){return{type:
|
|
11
|
+
*/export var setAlreadyRated=function setAlreadyRated(to){return{type:APP_RATING_SET_ALREADY_RATED,to:to};};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{APP_RATING_SET_TIMER_START_TIME,APP_RATING_INCREASE_TIMER_REPEATS}from"../constants";/**
|
|
2
2
|
* Reset the orders placed count, and increment reset counts
|
|
3
3
|
* @return {Object} The dispatched action object.
|
|
4
|
-
*/export var resetTimerState=function resetTimerState(){return{type:
|
|
4
|
+
*/export var resetTimerState=function resetTimerState(){return{type:APP_RATING_INCREASE_TIMER_REPEATS};};/**
|
|
5
5
|
* Sets the timer start time
|
|
6
6
|
* @return {Object} The dispatched action object.
|
|
7
|
-
*/export var setTimerStartTime=function setTimerStartTime(){return{type:
|
|
7
|
+
*/export var setTimerStartTime=function setTimerStartTime(){return{type:APP_RATING_SET_TIMER_START_TIME};};
|
|
@@ -1,4 +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);});};}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 showModalAction from'@shopgate/pwa-common/actions/modal/showModal';import{getPlatform}from'@shopgate/pwa-common/selectors/client';import{historyPush}from'@shopgate/pwa-common/actions/router';import appConfig from'@shopgate/pwa-common/helpers/config';import{track}from'@shopgate/pwa-tracking/helpers';import{increaseRejectionCount,setAlreadyRated,setLastPopupTimestamp}from"../action-creators/popup";import{generateReviewLink}from"../helpers";import{
|
|
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);});};}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 showModalAction from'@shopgate/pwa-common/actions/modal/showModal';import{getPlatform}from'@shopgate/pwa-common/selectors/client';import{historyPush}from'@shopgate/pwa-common/actions/router';import appConfig from'@shopgate/pwa-common/helpers/config';import{track}from'@shopgate/pwa-tracking/helpers';import{increaseRejectionCount,setAlreadyRated,setLastPopupTimestamp}from"../action-creators/popup";import{generateReviewLink}from"../helpers";import{APP_RATING_TIMER_TIMESPAN}from"../constants";import{getAppRatingState}from"../selectors/appRating";var _appConfig$appRating=appConfig.appRating,bundleId=_appConfig$appRating.bundleId,minDaysBetweenPopups=_appConfig$appRating.minDaysBetweenPopups,askForFeedback=_appConfig$appRating.askForFeedback,feedbackLink=_appConfig$appRating.feedbackLink;/**
|
|
2
2
|
* to handle the modal confirmation
|
|
3
3
|
* @param {string} url the url to redirect to
|
|
4
4
|
* @param {boolean | null} setRated the url to redirect to
|
|
@@ -11,7 +11,7 @@ import _regeneratorRuntime from"@babel/runtime/regenerator";function asyncGenera
|
|
|
11
11
|
* @param {boolean} hasRepeats if the counters has repeats
|
|
12
12
|
* @return {(function(*, *): void)|*}
|
|
13
13
|
*/export function showModal(resetAction,increaseAction,mustShow,hasRepeats){return/*#__PURE__*/function(){var _ref=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(dispatch,getState){var state,platform,reviewLink,appRatingState,isMinDaysBetweenPopupsElapsed,firstModalConfirmed,userGivesFeedback;return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:state=getState();platform=getPlatform(state);reviewLink=generateReviewLink(bundleId[platform],platform);// no review link for current platform found -> don't show modal
|
|
14
|
-
if(reviewLink){_context.next=5;break;}return _context.abrupt("return");case 5:if(!mustShow&&hasRepeats&&increaseAction){dispatch(increaseAction());}if(mustShow&&hasRepeats){_context.next=8;break;}return _context.abrupt("return");case 8:appRatingState=getAppRatingState(state);isMinDaysBetweenPopupsElapsed=Date.now()-appRatingState.lastPopupAt>=minDaysBetweenPopups*
|
|
14
|
+
if(reviewLink){_context.next=5;break;}return _context.abrupt("return");case 5:if(!mustShow&&hasRepeats&&increaseAction){dispatch(increaseAction());}if(mustShow&&hasRepeats){_context.next=8;break;}return _context.abrupt("return");case 8:appRatingState=getAppRatingState(state);isMinDaysBetweenPopupsElapsed=Date.now()-appRatingState.lastPopupAt>=minDaysBetweenPopups*APP_RATING_TIMER_TIMESPAN;if(isMinDaysBetweenPopupsElapsed){_context.next=12;break;}return _context.abrupt("return");case 12:dispatch(resetAction());dispatch(setLastPopupTimestamp());_context.next=16;return dispatch(showModalAction({confirm:'appRating.yes',dismiss:'appRating.no',title:'appRating.title',message:'appRating.message'}));case 16:firstModalConfirmed=_context.sent;track('customEvent',{eventCategory:'appReviewPrompt',eventAction:'decision',eventLabel:firstModalConfirmed?'yes':'no'},state);// user touched yes and we
|
|
15
15
|
// redirect to store
|
|
16
16
|
if(!firstModalConfirmed){_context.next=21;break;}dispatch(redirectTo(reviewLink,true));return _context.abrupt("return");case 21:// user doesn't want to rate
|
|
17
17
|
dispatch(increaseRejectionCount());// we approve for rejection
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export var
|
|
2
|
-
export var
|
|
1
|
+
export var APP_RATING_INCREASE_APP_START_COUNT='APP_RATING_INCREASE_APP_START_COUNT';export var APP_RATING_RESET_APP_START_COUNT='APP_RATING_RESET_APP_START_COUNT';export var APP_RATING_RESET_APP_START_STATE='APP_RATING_RESET_APP_START_STATE';export var APP_RATING_INCREASE_ORDERS_PLACED_COUNT='APP_RATING_INCREASE_ORDERS_PLACED_COUNT';export var APP_RATING_RESET_ORDERS_PLACED_COUNT='APP_RATING_RESET_ORDERS_PLACED_COUNT';export var APP_RATING_RESET_ORDERS_PLACED_STATE='APP_RATING_RESET_ORDERS_PLACED_STATE';export var APP_RATING_INCREASE_TIMER_REPEATS='APP_RATING_INCREASE_TIMER_REPEATS';export var APP_RATING_SET_TIMER_START_TIME='APP_RATING_SET_TIMER_START_TIME';export var APP_RATING_SET_LAST_POPUP_TIMESTAMP='APP_RATING_SET_LAST_POPUP_TIMESTAMP';export var APP_RATING_INCREASE_REJECTION_COUNT='APP_RATING_INCREASE_REJECTION_COUNT';export var APP_RATING_SET_ALREADY_RATED='APP_RATING_SET_ALREADY_RATED';// currently the timespan is set to a day
|
|
2
|
+
export var APP_RATING_TIMER_TIMESPAN=1000*60*60*24;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
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{
|
|
1
|
+
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{APP_RATING_INCREASE_APP_START_COUNT,APP_RATING_RESET_APP_START_STATE,APP_RATING_RESET_APP_START_COUNT,APP_RATING_INCREASE_ORDERS_PLACED_COUNT,APP_RATING_RESET_ORDERS_PLACED_COUNT,APP_RATING_RESET_ORDERS_PLACED_STATE,APP_RATING_INCREASE_TIMER_REPEATS,APP_RATING_SET_TIMER_START_TIME,APP_RATING_SET_LAST_POPUP_TIMESTAMP,APP_RATING_INCREASE_REJECTION_COUNT,APP_RATING_SET_ALREADY_RATED}from"../constants";var defaultState={appStartCount:0,appStartResetCount:0,ordersPlacedCount:0,ordersPlacedResetCount:0,timerRepeatsCount:0,timerStartTimestamp:null,lastPopupAt:null,rejectionCount:0,alreadyRated:false};/**
|
|
2
2
|
* Stores all the app rating states.
|
|
3
3
|
* @param {Object} [state] The current state.
|
|
4
4
|
* @param {Object} action The action object.
|
|
5
5
|
* @return {Object} The new state.
|
|
6
|
-
*/export default(function(){var state=arguments.length>0&&arguments[0]!==undefined?arguments[0]:defaultState;var action=arguments.length>1?arguments[1]:undefined;switch(action.type){case
|
|
6
|
+
*/export default(function(){var state=arguments.length>0&&arguments[0]!==undefined?arguments[0]:defaultState;var action=arguments.length>1?arguments[1]:undefined;switch(action.type){case APP_RATING_INCREASE_APP_START_COUNT:{return _extends({},state,{appStartCount:state.appStartCount+1});}case APP_RATING_RESET_APP_START_COUNT:{return _extends({},state,{appStartCount:0,appStartResetCount:state.appStartResetCount+1});}case APP_RATING_RESET_APP_START_STATE:{return _extends({},state,{appStartCount:0,appStartResetCount:0});}case APP_RATING_INCREASE_ORDERS_PLACED_COUNT:{return _extends({},state,{ordersPlacedCount:state.ordersPlacedCount+1});}case APP_RATING_RESET_ORDERS_PLACED_COUNT:{return _extends({},state,{ordersPlacedCount:0,ordersPlacedResetCount:state.ordersPlacedResetCount+1});}case APP_RATING_RESET_ORDERS_PLACED_STATE:{return _extends({},state,{ordersPlacedCount:0,ordersPlacedResetCount:0});}case APP_RATING_INCREASE_TIMER_REPEATS:{return _extends({},state,{timerRepeatsCount:state.timerRepeatsCount+1});}case APP_RATING_SET_TIMER_START_TIME:{return _extends({},state,{timerStartTimestamp:Date.now()});}case APP_RATING_SET_LAST_POPUP_TIMESTAMP:{return _extends({},state,{lastPopupAt:Date.now()});}case APP_RATING_INCREASE_REJECTION_COUNT:{return _extends({},state,{rejectionCount:state.rejectionCount+1});}case APP_RATING_SET_ALREADY_RATED:{return _extends({},state,{alreadyRated:action.to});}default:return state;}});
|
|
@@ -1,4 +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 appConfig from'@shopgate/pwa-common/helpers/config';import{appDidStart$}from'@shopgate/pwa-common/streams/app';import event from'@shopgate/pwa-core/classes/Event';import{increaseAppStartCount,resetAppStartCount}from"../action-creators/appStart";import{increaseOrdersPlacedCount,resetOrdersPlacedCount}from"../action-creators/ordersPlaced";import{resetTimerState,setTimerStartTime}from"../action-creators/timer";import{
|
|
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 appConfig from'@shopgate/pwa-common/helpers/config';import{appDidStart$}from'@shopgate/pwa-common/streams/app';import event from'@shopgate/pwa-core/classes/Event';import{increaseAppStartCount,resetAppStartCount}from"../action-creators/appStart";import{increaseOrdersPlacedCount,resetOrdersPlacedCount}from"../action-creators/ordersPlaced";import{resetTimerState,setTimerStartTime}from"../action-creators/timer";import{APP_RATING_TIMER_TIMESPAN}from"../constants";import{getAppRatingState}from"../selectors/appRating";import{showModal}from"../actions/showModal";/**
|
|
2
2
|
* App rating subscriptions
|
|
3
3
|
* @param {Function} subscribe The subscribe function
|
|
4
4
|
*/export default function appRating(subscribe){var _appConfig$appRating=appConfig.appRating,appStarts=_appConfig$appRating.appStarts,ordersPlaced=_appConfig$appRating.ordersPlaced,timeInterval=_appConfig$appRating.timeInterval,rejectionMaxCount=_appConfig$appRating.rejectionMaxCount,bundleId=_appConfig$appRating.bundleId;// even subscriber to handle app start ratings
|
|
@@ -9,7 +9,7 @@ dispatch(increaseAppStartCount());state=getAppRatingState(getState());// if the
|
|
|
9
9
|
// we'll cancel the operations as we
|
|
10
10
|
// don't have to show the modal once more
|
|
11
11
|
if(!state.alreadyRated){_context.next=7;break;}return _context.abrupt("return");case 7:if(!(state.rejectionCount>=rejectionMaxCount)){_context.next=9;break;}return _context.abrupt("return");case 9:// initiate the first start time
|
|
12
|
-
if(state.timerStartTimestamp===null){dispatch(setTimerStartTime());}mustShowModal=false;hasRepeats=false;resetAction=null;increaseAction=null;if(timeInterval&&Number(timeInterval.value)>0&&Number(state.timerStartTimestamp)>0&&Date.now()-state.timerStartTimestamp>=timeInterval.value*
|
|
12
|
+
if(state.timerStartTimestamp===null){dispatch(setTimerStartTime());}mustShowModal=false;hasRepeats=false;resetAction=null;increaseAction=null;if(timeInterval&&Number(timeInterval.value)>0&&Number(state.timerStartTimestamp)>0&&Date.now()-state.timerStartTimestamp>=timeInterval.value*APP_RATING_TIMER_TIMESPAN){mustShowModal=true;hasRepeats=timeInterval.repeats===null||state.timerRepeatsCount<=timeInterval.repeats;resetAction=resetTimerState;// since the time is elapsed
|
|
13
13
|
// we reset the starting time
|
|
14
14
|
increaseAction=setTimerStartTime;}else if(appStarts){mustShowModal=Number(appStarts.value)>0&&state.appStartCount>=appStarts.value;hasRepeats=appStarts.repeats===null||state.appStartResetCount<=appStarts.repeats;resetAction=resetAppStartCount;increaseAction=null;}// the actual show modal logic
|
|
15
15
|
dispatch(showModal(resetAction,increaseAction,mustShowModal,hasRepeats));case 16:case"end":return _context.stop();}}},_callee);}));return function(_x){return _ref2.apply(this,arguments);};}());// event subscriber to handle order placed ratings
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import{PipelineRequest}from'@shopgate/engage/core';import{SHOPGATE_USER_ADD_BACK_IN_STOCK_SUBSCRIPTION,SHOPGATE_USER_DELETE_BACK_IN_STOCK_SUBSCRIPTION,SHOPGATE_USER_GET_BACK_IN_STOCK_SUBSCRIPTIONS,ADD_BACK_IN_STOCK_SUBSCRIPTION,ADD_BACK_IN_STOCK_SUBSCRIPTION_ERROR,ADD_BACK_IN_STOCK_SUBSCRIPTION_SUCCESS,FETCH_BACK_IN_STOCK_SUBSCRIPTIONS,FETCH_BACK_IN_STOCK_SUBSCRIPTIONS_ERROR,FETCH_BACK_IN_STOCK_SUBSCRIPTIONS_SUCCESS,REMOVE_BACK_IN_STOCK_SUBSCRIPTION,REMOVE_BACK_IN_STOCK_SUBSCRIPTION_ERROR,REMOVE_BACK_IN_STOCK_SUBSCRIPTION_SUCCESS}from'@shopgate/engage/back-in-stock/constants';/**
|
|
2
|
+
* Fetch Back in Stock Subscriptions
|
|
3
|
+
* @returns {Function}
|
|
4
|
+
*/export var fetchBackInStockSubscriptions=function fetchBackInStockSubscriptions(){return function(dispatch){dispatch({type:FETCH_BACK_IN_STOCK_SUBSCRIPTIONS});var request=new PipelineRequest(SHOPGATE_USER_GET_BACK_IN_STOCK_SUBSCRIPTIONS).setInput({limit:100,filters:{status:{$in:['active','triggered']}}}).setRetries(0).dispatch();request.then(function(_ref){var subscriptions=_ref.subscriptions;dispatch({type:FETCH_BACK_IN_STOCK_SUBSCRIPTIONS_SUCCESS,subscriptions:subscriptions});})["catch"](function(error){dispatch({type:FETCH_BACK_IN_STOCK_SUBSCRIPTIONS_ERROR,error:error});});return request;};};/**
|
|
5
|
+
* Add a Back in Stock Subscription
|
|
6
|
+
* @param {Object} props Props.
|
|
7
|
+
* @param {string} props.productId The product for which the subscription should be added
|
|
8
|
+
* @returns {Function}
|
|
9
|
+
*/export var addBackInStockSubscription=function addBackInStockSubscription(_ref2){var productId=_ref2.productId;return function(dispatch){dispatch({type:ADD_BACK_IN_STOCK_SUBSCRIPTION});var request=new PipelineRequest(SHOPGATE_USER_ADD_BACK_IN_STOCK_SUBSCRIPTION).setInput({productCode:productId}).setRetries(0).dispatch();request.then(function(_ref3){var subscriptions=_ref3.subscriptions;dispatch({type:ADD_BACK_IN_STOCK_SUBSCRIPTION_SUCCESS,subscriptions:subscriptions});})["catch"](function(error){dispatch({type:ADD_BACK_IN_STOCK_SUBSCRIPTION_ERROR,error:error});});return request;};};/**
|
|
10
|
+
* Remove a Back in Stock Subscription
|
|
11
|
+
* @param {Object} props Props.
|
|
12
|
+
* @param {string} props.subscriptionCode The subscription which should be deleted
|
|
13
|
+
* @returns {Function}
|
|
14
|
+
*/export var removeBackInStockSubscription=function removeBackInStockSubscription(_ref4){var subscriptionCode=_ref4.subscriptionCode;return function(dispatch){dispatch({type:REMOVE_BACK_IN_STOCK_SUBSCRIPTION});var request=new PipelineRequest(SHOPGATE_USER_DELETE_BACK_IN_STOCK_SUBSCRIPTION).setInput({subscriptionCode:subscriptionCode}).setRetries(0).dispatch();request.then(function(_ref5){var subscriptions=_ref5.subscriptions;dispatch({type:REMOVE_BACK_IN_STOCK_SUBSCRIPTION_SUCCESS,subscriptions:subscriptions});})["catch"](function(error){dispatch({type:REMOVE_BACK_IN_STOCK_SUBSCRIPTION_ERROR,error:error});});return request;};};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{connect}from'react-redux';import{addBackInStockSubscription}from'@shopgate/engage/back-in-stock/actions';import grantPushPermissions from'@shopgate/engage/core/actions/grantPushPermissions';var mapDispatchToProps={addBackInStockSubscription:addBackInStockSubscription,grantPushPermissions:grantPushPermissions};export default connect(null,mapDispatchToProps);
|
|
@@ -0,0 +1,13 @@
|
|
|
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 React,{useCallback}from'react';import PropTypes from'prop-types';import{themeConfig}from'@shopgate/engage';import{Link,CheckedIcon,NotificationIcon}from'@shopgate/engage/components';import{BACK_IN_STOCK_PATTERN}from'@shopgate/engage/back-in-stock/constants';import{i18n}from'@shopgate/engage/core';import styles from"./style";import connect from"./connector";var colors=themeConfig.colors;/**
|
|
2
|
+
* This component renders a button to subscribe a product or a hint
|
|
3
|
+
* that the product is already subscribed
|
|
4
|
+
* @param {Object} props The component props
|
|
5
|
+
* @param {boolean} props.isLinkToBackInStockEnabled Whether the link to the back in
|
|
6
|
+
* stock page is active
|
|
7
|
+
* @param {boolean} props.stopPropagation Stop event propagation
|
|
8
|
+
* @param {string} props.productId The product id
|
|
9
|
+
* @param {Object} props.subscription The subscription
|
|
10
|
+
* @param {Function} props.addBackInStockSubscription Add product to back in stock list
|
|
11
|
+
* @param {Function} props.grantPushPermissions Request / Set push permission
|
|
12
|
+
* @return {JSX}
|
|
13
|
+
*/var BackInStockButton=function BackInStockButton(_ref){var productId=_ref.productId,_ref$isLinkToBackInSt=_ref.isLinkToBackInStockEnabled,isLinkToBackInStockEnabled=_ref$isLinkToBackInSt===void 0?false:_ref$isLinkToBackInSt,subscription=_ref.subscription,_ref$stopPropagation=_ref.stopPropagation,stopPropagation=_ref$stopPropagation===void 0?false:_ref$stopPropagation,addBackInStockSubscription=_ref.addBackInStockSubscription,grantPushPermissions=_ref.grantPushPermissions;var handleClick=useCallback(/*#__PURE__*/function(){var _ref2=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(event){var allowed;return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:if(stopPropagation){event.stopPropagation();}_context.next=3;return grantPushPermissions({rationaleModal:{message:'permissions.back_in_stock_push_notifications.message',confirm:'permissions.back_in_stock_push_notifications.confirm',dismiss:'permissions.back_in_stock_push_notifications.dismiss'}});case 3:allowed=_context.sent;if(allowed){addBackInStockSubscription({productId:productId});}case 5:case"end":return _context.stop();}}},_callee);}));return function(_x){return _ref2.apply(this,arguments);};}(),[addBackInStockSubscription,grantPushPermissions,productId,stopPropagation]);if((subscription===null||subscription===void 0?void 0:subscription.status)==='active'){return/*#__PURE__*/React.createElement(Link,{href:BACK_IN_STOCK_PATTERN,disabled:!isLinkToBackInStockEnabled,className:styles.backInStockMessageContainer,tag:"span"},/*#__PURE__*/React.createElement(CheckedIcon,{color:colors.success,className:styles.icon}),/*#__PURE__*/React.createElement("span",{className:styles.backInStockMessage},i18n.text('back_in_stock.we_will_remind_you')));}return/*#__PURE__*/React.createElement("div",null,/*#__PURE__*/React.createElement("a",{role:"button",onClick:handleClick,className:styles.button},/*#__PURE__*/React.createElement("div",{className:styles.buttonContent},/*#__PURE__*/React.createElement(NotificationIcon,{color:colors.primary}),/*#__PURE__*/React.createElement("span",{className:styles.buttonText},i18n.text('back_in_stock.get_notified')))));};BackInStockButton.defaultProps={stopPropagation:false,isLinkToBackInStockEnabled:false,subscription:null,productId:null};export default connect(BackInStockButton);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{css}from'glamor';import{themeConfig}from'@shopgate/engage';export default{button:css({color:themeConfig.colors.primary}).toString(),buttonContent:css({display:'flex',alignItems:'center'}).toString(),backInStockMessageContainer:css({lineHeight:'20px',display:'flex',alignItems:'center',textAlign:'end',width:'auto'}).toString(),backInStockMessage:css({marginLeft:'4px',verticalAlign:'middle',fontSize:'0.875rem'}).toString(),buttonText:css({marginLeft:'4px',fontSize:'0.875rem',lineHeight:'16.5px'}).toString(),icon:css({verticalAlign:'middle',display:'inline'}).toString()};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{connect}from'react-redux';import{getIsBackInStockEnabled,makeGetSubscriptionByCharacteristics}from'@shopgate/engage/back-in-stock/selectors';import{makeGetProductByCharacteristics}from'@shopgate/engage/product';/**
|
|
2
|
+
* @return {Object} The extended component props.
|
|
3
|
+
*/var makeMapStateToProps=function makeMapStateToProps(){var getProductByCharacteristics=makeGetProductByCharacteristics({strict:true});var getSubscriptionByCharacteristics=makeGetSubscriptionByCharacteristics();return function(state,props){var variant=getProductByCharacteristics(state,props)||{};return{variant:variant,subscription:getSubscriptionByCharacteristics(state,props),isBackInStockEnabled:getIsBackInStockEnabled(state,props)};};};export default connect(makeMapStateToProps);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from'react';import PropTypes from'prop-types';import{BackInStockButton}from'@shopgate/engage/back-in-stock/components';import{withCurrentProduct}from'@shopgate/engage/core';import connect from"./connector";/**
|
|
2
|
+
* The CharacteristicsButton component.
|
|
3
|
+
* @param {Object} props The component props.
|
|
4
|
+
* @param {boolean} props.isBackInStockEnabled Whether the back in stock feature is enabled
|
|
5
|
+
* @param {Object} props.variant The variant for this entry
|
|
6
|
+
* @param {Object} props.subscription The subscription
|
|
7
|
+
* @return {JSX}
|
|
8
|
+
*/var CharacteristicsButton=function CharacteristicsButton(_ref){var _variant$stock,_variant$stock2;var isBackInStockEnabled=_ref.isBackInStockEnabled,subscription=_ref.subscription,variant=_ref.variant;var productIsNotAVariant=!variant;var featureIsNotEnabled=!isBackInStockEnabled;var productIsNotAvailable=(variant===null||variant===void 0?void 0:(_variant$stock=variant.stock)===null||_variant$stock===void 0?void 0:_variant$stock.quantity)===0&&(variant===null||variant===void 0?void 0:(_variant$stock2=variant.stock)===null||_variant$stock2===void 0?void 0:_variant$stock2.ignoreQuantity)===false;if(productIsNotAVariant||featureIsNotEnabled||!productIsNotAvailable)return null;return/*#__PURE__*/React.createElement("div",{style:{display:'flex',justifyContent:'end'}},/*#__PURE__*/React.createElement(BackInStockButton,{subscription:subscription,stopPropagation:true,productId:variant.id}));};CharacteristicsButton.defaultProps={variant:{},subscription:null};export default withCurrentProduct(connect(CharacteristicsButton));
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{connect}from'react-redux';import{getIsBackInStockEnabled,makeGetSubscriptionByProduct}from'@shopgate/engage/back-in-stock/selectors';import{getProduct}from'@shopgate/engage/product';/**
|
|
2
|
+
* @return {Object} The extended component props.
|
|
3
|
+
*/var makeMapStateToProps=function makeMapStateToProps(){var getSubscriptionByProduct=makeGetSubscriptionByProduct();return function(state,props){return{subscription:getSubscriptionByProduct(state,props),isBackInStockEnabled:getIsBackInStockEnabled(state,props),product:getProduct(state,props)};};};export default connect(makeMapStateToProps);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React,{Fragment}from'react';import PropTypes from'prop-types';import{SurroundPortals}from'@shopgate/engage/components';import{PRODUCT_BACK_IN_STOCK}from'@shopgate/engage/back-in-stock/constants';import{BackInStockButton}from'@shopgate/engage/back-in-stock/components';import{withCurrentProduct}from'@shopgate/engage/core';import connect from"./connector";/**
|
|
2
|
+
* The ProductInfoBackInStockButton component.
|
|
3
|
+
* @param {Object} props The component props.
|
|
4
|
+
* @param {boolean} props.isBackInStockEnabled Whether the back in stock feature is enabled
|
|
5
|
+
* @param {string} props.productId The product id
|
|
6
|
+
* @param {string} props.variantId The variant id
|
|
7
|
+
* @param {Object} props.product The product
|
|
8
|
+
* @param {Object} props.subscription The subscription
|
|
9
|
+
* @return {JSX}
|
|
10
|
+
*/var ProductInfoBackInStockButton=function ProductInfoBackInStockButton(_ref){var _product$stock,_product$stock2;var productId=_ref.productId,variantId=_ref.variantId,isBackInStockEnabled=_ref.isBackInStockEnabled,subscription=_ref.subscription,product=_ref.product;var productIsAVariant=(product===null||product===void 0?void 0:product.type)!=='parent'&&(product===null||product===void 0?void 0:product.type)!==null;var productIsNotAvailable=(product===null||product===void 0?void 0:(_product$stock=product.stock)===null||_product$stock===void 0?void 0:_product$stock.quantity)===0&&(product===null||product===void 0?void 0:(_product$stock2=product.stock)===null||_product$stock2===void 0?void 0:_product$stock2.ignoreQuantity)===false;var showBackInStockButton=productIsAVariant&&productIsNotAvailable&&isBackInStockEnabled;return/*#__PURE__*/React.createElement(Fragment,null,/*#__PURE__*/React.createElement(SurroundPortals,{portalName:PRODUCT_BACK_IN_STOCK,portalProps:{showBackInStockButton:showBackInStockButton}},showBackInStockButton&&/*#__PURE__*/React.createElement(BackInStockButton,{subscription:subscription,isLinkToBackInStockEnabled:true,productId:variantId!==null&&variantId!==void 0?variantId:productId})));};ProductInfoBackInStockButton.defaultProps={subscription:null,variantId:null,product:null};export default withCurrentProduct(connect(ProductInfoBackInStockButton));
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_unsupportedIterableToArray(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}function _unsupportedIterableToArray(o,minLen){if(!o)return;if(typeof o==="string")return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(o);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(o,minLen);}function _arrayLikeToArray(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++){arr2[i]=arr[i];}return arr2;}function _iterableToArrayLimit(arr,i){var _i=arr==null?null:typeof Symbol!=="undefined"&&arr[Symbol.iterator]||arr["@@iterator"];if(_i==null)return;var _arr=[];var _n=true;var _d=false;var _s,_e;try{for(_i=_i.call(arr);!(_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,{useCallback}from'react';import{css}from'glamor';import{LoadingIndicator,Accordion,Card}from'@shopgate/engage/components';import{i18n}from'@shopgate/engage/core';import{useBackInStockSubscriptions}from'@shopgate/engage/back-in-stock/hooks';import Subscription from"../Subscription";var styles={divider:css({height:1,width:'calc(100% + 32px)',backgroundColor:'rgb(234, 234, 234)',marginLeft:-16,marginRight:-16,marginBottom:16}).toString(),emptyText:css({marginBottom:16,textAlign:'center'}).toString(),listTitle:css({fontWeight:'700'}).toString()};/**
|
|
2
|
+
* The Back In Stock Subscriptions List.
|
|
3
|
+
* @returns {JSX}
|
|
4
|
+
*/var List=function List(){var _useBackInStockSubscr=useBackInStockSubscriptions(),isInitial=_useBackInStockSubscr.isInitial,groupedSubscriptions=_useBackInStockSubscr.groupedSubscriptions;var _renderLabel=useCallback(function(groupKey){return/*#__PURE__*/React.createElement("div",{className:styles.listTitle},i18n.text("back_in_stock.list_states.".concat(groupKey)));},[]);return/*#__PURE__*/React.createElement("div",null,Object.entries(groupedSubscriptions).map(function(_ref){var _ref2=_slicedToArray(_ref,2),groupKey=_ref2[0],filteredSubscriptions=_ref2[1];return/*#__PURE__*/React.createElement(Card,{className:styles.root,key:groupKey},/*#__PURE__*/React.createElement(Accordion,{className:"",openWithChevron:true,renderLabel:function renderLabel(){return _renderLabel(groupKey);},chevronPosition:"left",startOpened:true},/*#__PURE__*/React.createElement("div",{className:styles.divider}),isInitial?/*#__PURE__*/React.createElement(LoadingIndicator,null):null,!isInitial&&filteredSubscriptions.length===0?/*#__PURE__*/React.createElement("div",{className:styles.emptyText},i18n.text('back_in_stock.empty_list_reminder')):null,!isInitial&&filteredSubscriptions.map(function(subscription,index){return/*#__PURE__*/React.createElement("div",{key:subscription.subscriptionCode},/*#__PURE__*/React.createElement(Subscription,{subscription:subscription,productId:subscription.productCode,key:subscription.subscriptionCode,group:groupKey}),index===filteredSubscriptions.length-1?null:/*#__PURE__*/React.createElement("div",{className:styles.divider}));})));}));};export default List;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{connect}from'react-redux';import{addBackInStockSubscription}from'@shopgate/engage/back-in-stock/actions';import{makeGetSubscriptionByProduct}from'@shopgate/engage/back-in-stock/selectors';/**
|
|
2
|
+
* @return {Object} The extended component props.
|
|
3
|
+
*/var makeMapStateToProps=function makeMapStateToProps(){var getSubscriptionByProduct=makeGetSubscriptionByProduct();return function(state,props){return{subscription:getSubscriptionByProduct(state,props)};};};var mapDispatchToProps={addBackInStockSubscription:addBackInStockSubscription};export default connect(makeMapStateToProps,mapDispatchToProps);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from'react';import{css}from'glamor';import{Link,Ripple,PriceInfo,CrossIcon,PriceStriked,Price,Availability}from'@shopgate/engage/components';import{getProductRoute,ProductImage}from'@shopgate/engage/product';import PropTypes from'prop-types';import classNames from'classnames';import{themeConfig}from'@shopgate/engage';import{BackInStockButton}from'@shopgate/engage/back-in-stock/components';import{getThemeSettings,i18n}from'@shopgate/engage/core';import{useBackInStockSubscriptions}from'@shopgate/engage/back-in-stock/hooks';var variables=themeConfig.variables;var styles={root:css({display:'flex',position:'relative',marginBottom:16}).toString(),imageContainer:css({flex:0.4,maxWidth:170,minWidth:70,paddingRight:'8px'}).toString(),infoContainer:css({flex:1}).toString(),infoContainerRow:css({display:'flex',justifyContent:'space-between'}).toString(),baseContainerRow:css({flexDirection:'column',display:'flex',marginTop:'8px'}).toString(),priceContainerRow:css({flexDirection:'column',display:'flex',alignItems:'end',marginTop:'8px'}).toString(),priceContainer:css({minWidth:100}).toString(),priceInfo:css({wordBreak:'break-word',fontSize:'0.875rem',lineHeight:'0.875rem',color:'var(--color-text-low-emphasis)',padding:"".concat(variables.gap.xsmall,"px 0"),textAlign:'right'}).toString(),titleContainer:css({}).toString(),title:css({fontSize:17,fontWeight:600,flexWrap:'wrap',overflowWrap:'anywhere'}).toString(),removeContainer:css({minWidth:'30px'}).toString(),availabilityText:css({fontSize:'0.875rem',marginBottom:'4px'}).toString(),ripple:css({minWidth:'17px'}).toString()};/**
|
|
2
|
+
* Renders on single Back in Stock subscription
|
|
3
|
+
* @param {Object} props Props.
|
|
4
|
+
* @param {string} props.subscription The subscription which should be rendered
|
|
5
|
+
* @returns {JSX}
|
|
6
|
+
*/var Subscription=function Subscription(_ref){var _product$price,_product$price2,_product$price3,_product$price4,_product$availability,_product$availability2;var subscription=_ref.subscription;var subscriptionCode=subscription.subscriptionCode,product=subscription.product;var _useBackInStockSubscr=useBackInStockSubscriptions(),removeBackInStockSubscription=_useBackInStockSubscr.removeBackInStockSubscription;var _ref2=getThemeSettings('AppImages')||{},gridResolutions=_ref2.ListImage;var currency=((_product$price=product.price)===null||_product$price===void 0?void 0:_product$price.currency)||'EUR';var defaultPrice=((_product$price2=product.price)===null||_product$price2===void 0?void 0:_product$price2.unitPrice)||0;var specialPrice=(_product$price3=product.price)===null||_product$price3===void 0?void 0:_product$price3.unitPriceStriked;var hasStrikePrice=((_product$price4=product.price)===null||_product$price4===void 0?void 0:_product$price4.discount)>0;var productLink=getProductRoute(product.id);return/*#__PURE__*/React.createElement("div",{className:styles.root},/*#__PURE__*/React.createElement(Link,{className:styles.imageContainer,component:"div",href:productLink,"aria-hidden":true},/*#__PURE__*/React.createElement(ProductImage,{src:product.featuredImageBaseUrl,resolutions:gridResolutions})),/*#__PURE__*/React.createElement("div",{className:styles.infoContainer},/*#__PURE__*/React.createElement("div",{className:styles.infoContainerRow},/*#__PURE__*/React.createElement(Link,{href:productLink,tag:"span",className:styles.titleContainer},/*#__PURE__*/React.createElement("span",{className:styles.title// eslint-disable-next-line react/no-danger
|
|
7
|
+
,dangerouslySetInnerHTML:{__html:"".concat(product.name)}})),/*#__PURE__*/React.createElement("div",{className:styles.removeContainer},/*#__PURE__*/React.createElement("button",{onClick:function onClick(){return removeBackInStockSubscription({subscriptionCode:subscriptionCode});},type:"button","aria-label":i18n.text('favorites.remove')},/*#__PURE__*/React.createElement(Ripple,{className:styles.ripple},/*#__PURE__*/React.createElement(CrossIcon,null))))),/*#__PURE__*/React.createElement("div",{className:classNames(styles.baseContainerRow)},/*#__PURE__*/React.createElement(Availability,{text:product===null||product===void 0?void 0:(_product$availability=product.availability)===null||_product$availability===void 0?void 0:_product$availability.text,state:product===null||product===void 0?void 0:(_product$availability2=product.availability)===null||_product$availability2===void 0?void 0:_product$availability2.state,showWhenAvailable:false,className:styles.availabilityText}),/*#__PURE__*/React.createElement(BackInStockButton,{subscription:subscription,onClick:function onClick(){}})),/*#__PURE__*/React.createElement("div",{className:styles.priceContainerRow},hasStrikePrice?/*#__PURE__*/React.createElement(PriceStriked,{value:specialPrice,currency:currency}):null,/*#__PURE__*/React.createElement(Price,{currency:currency,discounted:hasStrikePrice,unitPrice:defaultPrice}),!!product.price.info&&/*#__PURE__*/React.createElement(PriceInfo,{text:product.price.info,className:styles.priceInfo}))));};export default Subscription;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import React from'react';import{BackInStockSubscriptionsProvider}from'@shopgate/engage/back-in-stock/providers';import List from"./components/List";/**
|
|
2
|
+
* The Back in Stock Subscriptions component.
|
|
3
|
+
* @returns {JSX}
|
|
4
|
+
*/var Subscriptions=function Subscriptions(){return/*#__PURE__*/React.createElement(BackInStockSubscriptionsProvider,null,/*#__PURE__*/React.createElement(List,null));};export default Subscriptions;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{default as BackInStockButton}from"./BackInStockButton";export{default as BackInStockReminders}from"./Subscriptions";export{default as ProductInfoBackInStockButton}from"./ProductInfoBackInStockButton";export{default as CharacteristicsButton}from"./CharacteristicsButton";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export var FETCH_BACK_IN_STOCK_SUBSCRIPTIONS='FETCH_BACK_IN_STOCK_SUBSCRIPTIONS';export var FETCH_BACK_IN_STOCK_SUBSCRIPTIONS_SUCCESS='FETCH_BACK_IN_STOCK_SUBSCRIPTIONS_SUCCESS';export var FETCH_BACK_IN_STOCK_SUBSCRIPTIONS_ERROR='FETCH_BACK_IN_STOCK_SUBSCRIPTIONS_ERROR';export var ADD_BACK_IN_STOCK_SUBSCRIPTION='ADD_BACK_IN_STOCK_SUBSCRIPTION';export var ADD_BACK_IN_STOCK_SUBSCRIPTION_SUCCESS='ADD_BACK_IN_STOCK_SUBSCRIPTION_SUCCESS';export var ADD_BACK_IN_STOCK_SUBSCRIPTION_ERROR='ADD_BACK_IN_STOCK_SUBSCRIPTION_ERROR';export var REMOVE_BACK_IN_STOCK_SUBSCRIPTION='REMOVE_BACK_IN_STOCK_SUBSCRIPTION';export var REMOVE_BACK_IN_STOCK_SUBSCRIPTION_SUCCESS='REMOVE_BACK_IN_STOCK_SUBSCRIPTION_SUCCESS';export var REMOVE_BACK_IN_STOCK_SUBSCRIPTION_ERROR='REMOVE_BACK_IN_STOCK_SUBSCRIPTION_ERROR';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export var BACK_IN_STOCK_PATTERN='/back-in-stock';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export var SHOPGATE_USER_GET_BACK_IN_STOCK_SUBSCRIPTIONS='shopgate.user.getBackInStockSubscriptions';export var SHOPGATE_USER_ADD_BACK_IN_STOCK_SUBSCRIPTION='shopgate.user.addBackInStockSubscription';export var SHOPGATE_USER_DELETE_BACK_IN_STOCK_SUBSCRIPTION='shopgate.user.removeBackInStockSubscription';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2017-present, Shopgate, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache 2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/ // FEATURES
|
|
7
|
+
var NAV_MENU='nav-menu';var PRODUCT='product';// CONTENTS
|
|
8
|
+
var BACK_IN_STOCK='back-in-stock';// POSITIONS
|
|
9
|
+
var BEFORE='before';var AFTER='after';export var NAV_MENU_BACK_IN_STOCK_BEFORE="".concat(NAV_MENU,".").concat(BACK_IN_STOCK,".").concat(BEFORE);export var NAV_MENU_BACK_IN_STOCK="".concat(NAV_MENU,".").concat(BACK_IN_STOCK);export var NAV_MENU_BACK_IN_STOCK_AFTER="".concat(NAV_MENU,".").concat(BACK_IN_STOCK,".").concat(AFTER);export var PRODUCT_BACK_IN_STOCK_BEFORE="".concat(PRODUCT,".").concat(BACK_IN_STOCK,".").concat(BEFORE);export var PRODUCT_BACK_IN_STOCK="".concat(PRODUCT,".").concat(BACK_IN_STOCK);export var PRODUCT_BACK_IN_STOCK_AFTER="".concat(PRODUCT,".").concat(BACK_IN_STOCK,".").concat(AFTER);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export*from"./Actions";export*from"./Common";export*from"./Pipelines";export*from"./Portals";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import React from'react';import{BackInStockSubscriptionsProviderContext}from'@shopgate/engage/back-in-stock/providers';/**
|
|
2
|
+
* Gives access to the values which the context BackInStockSubscriptionsProvider provide
|
|
3
|
+
* @returns {JSX}
|
|
4
|
+
*/export var useBackInStockSubscriptions=function useBackInStockSubscriptions(){return React.useContext(BackInStockSubscriptionsProviderContext);};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import{connect}from'react-redux';import{getBackInStockSubscriptions,getBackInStockSubscriptionsFetching,getBackInStockSubscriptionsInitial}from'@shopgate/engage/back-in-stock/selectors';import{addBackInStockSubscription,removeBackInStockSubscription}from'@shopgate/engage/back-in-stock/actions';/**
|
|
2
|
+
* @return {Function} The extended component props.
|
|
3
|
+
*/function makeMapStateToProps(){/**
|
|
4
|
+
* @param {Object} state The application state.
|
|
5
|
+
* @param {Object} props The component props
|
|
6
|
+
* @returns {Object}
|
|
7
|
+
*/return function(state,props){return{subscriptions:getBackInStockSubscriptions(state,props),isFetching:getBackInStockSubscriptionsFetching(state,props),isInitial:getBackInStockSubscriptionsInitial(state,props)};};}var mapDispatchToProps={addBackInStockSubscription:addBackInStockSubscription,removeBackInStockSubscription:removeBackInStockSubscription};export default connect(makeMapStateToProps,mapDispatchToProps);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import React from'react';var initialContext={};export default/*#__PURE__*/React.createContext(initialContext);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import React,{useMemo}from'react';import PropTypes from'prop-types';import Context from"./BackInStockSubscriptionsProvider.context";import connect from"./BackInStockSubscriptionsProvider.connector";/**
|
|
2
|
+
* Back in Stock Provider
|
|
3
|
+
* @returns {JSX}
|
|
4
|
+
*/var BackInStockSubscriptionsProvider=function BackInStockSubscriptionsProvider(_ref){var subscriptions=_ref.subscriptions,children=_ref.children,addBackInStockSubscription=_ref.addBackInStockSubscription,isFetching=_ref.isFetching,isInitial=_ref.isInitial,removeBackInStockSubscription=_ref.removeBackInStockSubscription;var groupedSubscriptions=useMemo(function(){return subscriptions.reduce(function(acc,subscription){var status=subscription.status;var groupingStatus=status==='inactive'||status==='triggered'?'past':status;acc[groupingStatus].push(subscription);return acc;},{active:[],past:[]});},[subscriptions]);// Create memoized context value.
|
|
5
|
+
var value=useMemo(function(){return{subscriptions:subscriptions,groupedSubscriptions:groupedSubscriptions,addBackInStockSubscription:addBackInStockSubscription,removeBackInStockSubscription:removeBackInStockSubscription,isFetching:isFetching,isInitial:isInitial};},[addBackInStockSubscription,groupedSubscriptions,isFetching,isInitial,removeBackInStockSubscription,subscriptions]);return/*#__PURE__*/React.createElement(Context.Provider,{value:value},children);};BackInStockSubscriptionsProvider.defaultProps={children:null,isFetching:false,isInitial:true};export default connect(BackInStockSubscriptionsProvider);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{default as BackInStockSubscriptionsProviderContext}from"./BackInStockSubscriptionsProvider.context";export{default as BackInStockSubscriptionsProvider}from"./BackInStockSubscriptionsProvider";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
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{ADD_BACK_IN_STOCK_SUBSCRIPTION,ADD_BACK_IN_STOCK_SUBSCRIPTION_ERROR,ADD_BACK_IN_STOCK_SUBSCRIPTION_SUCCESS,FETCH_BACK_IN_STOCK_SUBSCRIPTIONS,FETCH_BACK_IN_STOCK_SUBSCRIPTIONS_ERROR,FETCH_BACK_IN_STOCK_SUBSCRIPTIONS_SUCCESS,REMOVE_BACK_IN_STOCK_SUBSCRIPTION,REMOVE_BACK_IN_STOCK_SUBSCRIPTION_ERROR,REMOVE_BACK_IN_STOCK_SUBSCRIPTION_SUCCESS}from'@shopgate/engage/back-in-stock/constants';var initialState={isFetching:false,isInitial:true,subscriptions:[]};/**
|
|
2
|
+
* @param {Object} state The application state.
|
|
3
|
+
* @param {Object} action The redux action.
|
|
4
|
+
* @returns {Object}
|
|
5
|
+
*/export default(function(){var state=arguments.length>0&&arguments[0]!==undefined?arguments[0]:initialState;var action=arguments.length>1?arguments[1]:undefined;switch(action.type){case FETCH_BACK_IN_STOCK_SUBSCRIPTIONS:{return _extends({},state,{isFetching:true});}case FETCH_BACK_IN_STOCK_SUBSCRIPTIONS_SUCCESS:{return _extends({},state,{isInitial:false,isFetching:false,subscriptions:action.subscriptions});}case FETCH_BACK_IN_STOCK_SUBSCRIPTIONS_ERROR:{return _extends({},state,{isFetching:false});}case ADD_BACK_IN_STOCK_SUBSCRIPTION:{return _extends({},state,{isFetching:true});}case ADD_BACK_IN_STOCK_SUBSCRIPTION_SUCCESS:{return _extends({},state,{isFetching:false});}case ADD_BACK_IN_STOCK_SUBSCRIPTION_ERROR:{return _extends({},state,{isFetching:false});}case REMOVE_BACK_IN_STOCK_SUBSCRIPTION:{return _extends({},state,{isFetching:true});}case REMOVE_BACK_IN_STOCK_SUBSCRIPTION_SUCCESS:{return _extends({},state,{isFetching:false});}case REMOVE_BACK_IN_STOCK_SUBSCRIPTION_ERROR:{return _extends({},state,{isFetching:false});}default:return state;}});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import{createSelector}from'reselect';import{makeGetProductByCharacteristics}from'@shopgate/engage/product';import{appConfig}from'@shopgate/engage';/**
|
|
2
|
+
* @param {Object} state The application state.
|
|
3
|
+
* @returns {Object}
|
|
4
|
+
*/export var getBackInStockSubscriptions=function getBackInStockSubscriptions(state){return state.backInStock.subscriptions;};/**
|
|
5
|
+
* @param {Object} state The application state.
|
|
6
|
+
* @returns {Object}
|
|
7
|
+
*/export var getBackInStockSubscriptionsFetching=function getBackInStockSubscriptionsFetching(state){return state.backInStock.isFetching;};/**
|
|
8
|
+
* @param {Object} state The application state.
|
|
9
|
+
* @returns {Object}
|
|
10
|
+
*/export var getBackInStockSubscriptionsInitial=function getBackInStockSubscriptionsInitial(state){return state.backInStock.isInitial;};/**
|
|
11
|
+
* Creates a selector that retrieves the subscription of
|
|
12
|
+
* a product / variant or null by its variantId / productId
|
|
13
|
+
* @returns {Function}
|
|
14
|
+
*/export var makeGetSubscriptionByProduct=function makeGetSubscriptionByProduct(){return createSelector(function(state){var props=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};return props.variantId?props.variantId:props.productId;},getBackInStockSubscriptions,function(requestedProductCode,subscriptions){if(!requestedProductCode){return false;}return subscriptions.find(function(_ref){var productCode=_ref.productCode;return productCode===requestedProductCode;})||null;});};/**
|
|
15
|
+
* Creates a selector that retrieves the subscription of
|
|
16
|
+
* a product / variant by its characteristics
|
|
17
|
+
* @returns {Function}
|
|
18
|
+
*/export var makeGetSubscriptionByCharacteristics=function makeGetSubscriptionByCharacteristics(){var getProductByCharacteristics=makeGetProductByCharacteristics();return createSelector(getProductByCharacteristics,getBackInStockSubscriptions,function(product,subscriptions){if(!product){return null;}return subscriptions.find(function(_ref2){var productCode=_ref2.productCode;return productCode===product.id;})||null;});};/**
|
|
19
|
+
* Returns if the back in stock feature is enabled
|
|
20
|
+
* @returns {Function}
|
|
21
|
+
*/export var getIsBackInStockEnabled=function getIsBackInStockEnabled(){return(appConfig===null||appConfig===void 0?void 0:appConfig.showBackInStock)||false;};/**
|
|
22
|
+
* Returns if subscription list is in use
|
|
23
|
+
* @returns {Function}
|
|
24
|
+
*/export var getHasBackInStockSubscriptions=createSelector(getBackInStockSubscriptions,function(subscriptions){return!!subscriptions.length;});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{appDidStart$,main$,routeDidEnter$}from'@shopgate/engage/core';import{productWillEnter$}from'@shopgate/engage/product';import{ADD_BACK_IN_STOCK_SUBSCRIPTION_SUCCESS,REMOVE_BACK_IN_STOCK_SUBSCRIPTION_SUCCESS,BACK_IN_STOCK_PATTERN}from'@shopgate/engage/back-in-stock/constants';export var backInStockRemindersDidEnter$=routeDidEnter$.filter(function(_ref){var action=_ref.action;return action.route.pattern===BACK_IN_STOCK_PATTERN;});export var addBackInStockReminderSuccess$=main$.filter(function(_ref2){var action=_ref2.action;return action.type===ADD_BACK_IN_STOCK_SUBSCRIPTION_SUCCESS;});export var removeBackInStockReminderSuccess$=main$.filter(function(_ref3){var action=_ref3.action;return action.type===REMOVE_BACK_IN_STOCK_SUBSCRIPTION_SUCCESS;});export var backInStockReminderNeedsFetch$=addBackInStockReminderSuccess$.merge(appDidStart$,removeBackInStockReminderSuccess$,backInStockRemindersDidEnter$,productWillEnter$);
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import showModal from'@shopgate/pwa-common/actions/modal/showModal';import{fetchBackInStockSubscriptions}from'@shopgate/engage/back-in-stock/actions';import{addBackInStockReminderSuccess$,backInStockReminderNeedsFetch$}from'@shopgate/engage/back-in-stock/streams';/**
|
|
2
|
+
* @param {Function} subscribe The subscribe function.
|
|
3
|
+
*/export default function backInStock(subscribe){subscribe(backInStockReminderNeedsFetch$,function(_ref){var dispatch=_ref.dispatch;dispatch(fetchBackInStockSubscriptions());});subscribe(addBackInStockReminderSuccess$,function(_ref2){var dispatch=_ref2.dispatch;dispatch(showModal({title:'back_in_stock.add_back_in_stock_success_modal.title',message:'back_in_stock.add_back_in_stock_success_modal.message',confirm:'modal.confirm',dismiss:null}));});}
|
package/components/index.js
CHANGED
|
@@ -8,5 +8,5 @@ export{default as Accordion}from'@shopgate/pwa-ui-material/Accordion';export{def
|
|
|
8
8
|
export{default as AccordionContainer}from'@shopgate/pwa-ui-shared/AccordionContainer';export{default as ActionButton}from'@shopgate/pwa-ui-shared/ActionButton';export{default as AddToCartButton}from'@shopgate/pwa-ui-shared/AddToCartButton';export{default as Availability}from'@shopgate/pwa-ui-shared/Availability';export{default as Button}from'@shopgate/pwa-ui-shared/Button';export{default as ButtonLink}from'@shopgate/pwa-ui-shared/ButtonLink';export{default as Card}from'@shopgate/pwa-ui-shared/Card';export{default as CardList}from'@shopgate/pwa-ui-shared/CardList';export{default as CartTotalLine}from'@shopgate/pwa-ui-shared/CartTotalLine';export{default as Chip}from'@shopgate/pwa-ui-shared/Chip';export{default as ClientInformation}from'@shopgate/pwa-ui-shared/ClientInformation';export{default as ContextMenu}from'@shopgate/pwa-ui-shared/ContextMenu';export{default as Dialog}from'@shopgate/pwa-ui-shared/Dialog';export{default as DiscountBadge}from'@shopgate/pwa-ui-shared/DiscountBadge';export{default as FavoritesButton}from'@shopgate/pwa-ui-shared/FavoritesButton';export{default as Checkbox}from'@shopgate/pwa-ui-shared/Form/Checkbox';export{default as Password}from'@shopgate/pwa-ui-shared/Form/Password';export{default as RadioGroup}from'@shopgate/pwa-ui-shared/Form/RadioGroup';export{default as Select}from'@shopgate/pwa-ui-shared/Form/Select';export{default as TextField}from'@shopgate/pwa-ui-shared/Form/TextField';export{default as FormElement}from'@shopgate/pwa-ui-shared/FormElement';export{default as Glow}from'@shopgate/pwa-ui-shared/Glow';export{default as IndicatorCircle}from'@shopgate/pwa-ui-shared/IndicatorCircle';export{default as LoadingIndicator}from'@shopgate/pwa-ui-shared/LoadingIndicator';export{default as Manufacturer}from'@shopgate/pwa-ui-shared/Manufacturer';export{default as MessageBar}from"./MessageBar";export{default as NoResults}from'@shopgate/pwa-ui-shared/NoResults';export{default as Placeholder}from'@shopgate/pwa-ui-shared/Placeholder';export{default as PlaceholderLabel}from'@shopgate/pwa-ui-shared/PlaceholderLabel';export{default as PlaceholderParagraph}from'@shopgate/pwa-ui-shared/PlaceholderParagraph';export{default as Price}from'@shopgate/pwa-ui-shared/Price';export{default as PriceInfo}from'@shopgate/pwa-ui-shared/PriceInfo';export{default as PriceStriked}from'@shopgate/pwa-ui-shared/PriceStriked';export{default as ProductProperties}from'@shopgate/pwa-ui-shared/ProductProperties';export{default as ProgressBar}from'@shopgate/pwa-ui-shared/ProgressBar';export{default as RadioButton}from'@shopgate/pwa-ui-shared/RadioButton';export{default as RatingNumber}from'@shopgate/pwa-ui-shared/RatingNumber';export{default as RatingStars}from'@shopgate/pwa-ui-shared/RatingStars';export{default as Ripple}from'@shopgate/pwa-ui-shared/Ripple';export{default as RippleButton}from'@shopgate/pwa-ui-shared/RippleButton';export{default as ScannerOverlay}from'@shopgate/pwa-ui-shared/ScannerOverlay';export{default as Sheet,SHEET_EVENTS}from'@shopgate/pwa-ui-shared/Sheet';export{default as TaxDisclaimer}from'@shopgate/pwa-ui-shared/TaxDisclaimer';export{default as ToggleIcon}from'@shopgate/pwa-ui-shared/ToggleIcon';// ICONS IOS
|
|
9
9
|
export{default as CartIconIOS}from'@shopgate/pwa-ui-ios/icons/CartIcon';export{default as FilterIconIOS}from'@shopgate/pwa-ui-ios/icons/FilterIcon';export{default as HomeIconIOS}from'@shopgate/pwa-ui-ios/icons/HomeIcon';export{default as ShareIconIOS}from'@shopgate/pwa-ui-ios/icons/ShareIcon';// ICONS ANDROID
|
|
10
10
|
export{default as ShareIconAndroid}from'@shopgate/pwa-ui-material/icons/ShareIcon';// ICONS SHARED
|
|
11
|
-
export{default as AccountBoxIcon}from'@shopgate/pwa-ui-shared/icons/AccountBoxIcon';export{default as AddMoreIcon}from'@shopgate/pwa-ui-shared/icons/AddMoreIcon';export{default as ArrowDropIcon}from'@shopgate/pwa-ui-shared/icons/ArrowDropIcon';export{default as ArrowIcon}from'@shopgate/pwa-ui-shared/icons/ArrowIcon';export{default as BarcodeScannerIcon}from'@shopgate/pwa-ui-shared/icons/BarcodeScannerIcon';export{default as BoxIcon}from'@shopgate/pwa-ui-shared/icons/BoxIcon';export{default as BrowseIcon}from'@shopgate/pwa-ui-shared/icons/BrowseIcon';export{default as BurgerIcon}from'@shopgate/pwa-ui-shared/icons/BurgerIcon';export{default as CartIcon}from'@shopgate/pwa-ui-shared/icons/CartIcon';export{default as CartPlusIcon}from'@shopgate/pwa-ui-shared/icons/CartPlusIcon';export{default as CartCouponIcon}from'@shopgate/pwa-ui-shared/icons/CartCouponIcon';export{default as CheckedIcon}from'@shopgate/pwa-ui-shared/icons/CheckedIcon';export{default as CheckIcon}from'@shopgate/pwa-ui-shared/icons/CheckIcon';export{default as ChevronIcon}from'@shopgate/pwa-ui-shared/icons/ChevronIcon';export{default as CreditCardIcon}from'@shopgate/pwa-ui-shared/icons/CreditCardIcon';export{default as CrossIcon}from'@shopgate/pwa-ui-shared/icons/CrossIcon';export{default as DescriptionIcon}from'@shopgate/pwa-ui-shared/icons/DescriptionIcon';export{default as FilterIcon}from'@shopgate/pwa-ui-shared/icons/FilterIcon';export{default as FlashEnabledIcon}from'@shopgate/pwa-ui-shared/icons/FlashEnabledIcon';export{default as FlashDisabledIcon}from'@shopgate/pwa-ui-shared/icons/FlashDisabledIcon';export{default as GridIcon}from'@shopgate/pwa-ui-shared/icons/GridIcon';export{default as HeartIcon}from'@shopgate/pwa-ui-shared/icons/HeartIcon';export{default as HeartOutlineIcon}from'@shopgate/pwa-ui-shared/icons/HeartOutlineIcon';export{default as HomeIcon}from'@shopgate/pwa-ui-shared/icons/HomeIcon';export{default as InfoIcon}from'@shopgate/pwa-ui-shared/icons/InfoIcon';export{default as InfoOutlineIcon}from'@shopgate/pwa-ui-shared/icons/InfoOutlineIcon';export{default as ListIcon}from'@shopgate/pwa-ui-shared/icons/ListIcon';export{default as LocalShippingIcon}from'@shopgate/pwa-ui-shared/icons/LocalShippingIcon';export{default as LockIcon}from'@shopgate/pwa-ui-shared/icons/LockIcon';export{default as LogoutIcon}from'@shopgate/pwa-ui-shared/icons/LogoutIcon';export{default as MagnifierIcon}from'@shopgate/pwa-ui-shared/icons/MagnifierIcon';export{default as MoreIcon}from'@shopgate/pwa-ui-shared/icons/MoreIcon';export{default as MoreVertIcon}from'@shopgate/pwa-ui-shared/icons/MoreVertIcon';export{default as PlaceholderIcon}from'@shopgate/pwa-ui-shared/icons/PlaceholderIcon';export{default as RadioCheckedIcon}from'@shopgate/pwa-ui-shared/icons/RadioCheckedIcon';export{default as RadioUncheckedIcon}from'@shopgate/pwa-ui-shared/icons/RadioUncheckedIcon';export{default as SecurityIcon}from'@shopgate/pwa-ui-shared/icons/SecurityIcon';export{default as ShoppingCartIcon}from'@shopgate/pwa-ui-shared/icons/ShoppingCartIcon';export{default as SortIcon}from'@shopgate/pwa-ui-shared/icons/SortIcon';export{default as StarHalfIcon}from'@shopgate/pwa-ui-shared/icons/StarHalfIcon';export{default as StarIcon}from'@shopgate/pwa-ui-shared/icons/StarIcon';export{default as StarOutlineIcon}from'@shopgate/pwa-ui-shared/icons/StarOutlineIcon';export{default as TickIcon}from'@shopgate/pwa-ui-shared/icons/TickIcon';export{default as TrashIcon}from'@shopgate/pwa-ui-shared/icons/TrashIcon';export{default as UncheckedIcon}from'@shopgate/pwa-ui-shared/icons/UncheckedIcon';export{default as ViewListIcon}from'@shopgate/pwa-ui-shared/icons/ViewListIcon';export{default as VisibilityIcon}from'@shopgate/pwa-ui-shared/icons/VisibilityIcon';export{default as VisibilityOffIcon}from'@shopgate/pwa-ui-shared/icons/VisibilityOffIcon';// LOCAL
|
|
11
|
+
export{default as AccountBoxIcon}from'@shopgate/pwa-ui-shared/icons/AccountBoxIcon';export{default as AddMoreIcon}from'@shopgate/pwa-ui-shared/icons/AddMoreIcon';export{default as ArrowDropIcon}from'@shopgate/pwa-ui-shared/icons/ArrowDropIcon';export{default as ArrowIcon}from'@shopgate/pwa-ui-shared/icons/ArrowIcon';export{default as BarcodeScannerIcon}from'@shopgate/pwa-ui-shared/icons/BarcodeScannerIcon';export{default as BoxIcon}from'@shopgate/pwa-ui-shared/icons/BoxIcon';export{default as BrowseIcon}from'@shopgate/pwa-ui-shared/icons/BrowseIcon';export{default as BurgerIcon}from'@shopgate/pwa-ui-shared/icons/BurgerIcon';export{default as CartIcon}from'@shopgate/pwa-ui-shared/icons/CartIcon';export{default as CartPlusIcon}from'@shopgate/pwa-ui-shared/icons/CartPlusIcon';export{default as CartCouponIcon}from'@shopgate/pwa-ui-shared/icons/CartCouponIcon';export{default as CheckedIcon}from'@shopgate/pwa-ui-shared/icons/CheckedIcon';export{default as CheckIcon}from'@shopgate/pwa-ui-shared/icons/CheckIcon';export{default as ChevronIcon}from'@shopgate/pwa-ui-shared/icons/ChevronIcon';export{default as CreditCardIcon}from'@shopgate/pwa-ui-shared/icons/CreditCardIcon';export{default as CrossIcon}from'@shopgate/pwa-ui-shared/icons/CrossIcon';export{default as DescriptionIcon}from'@shopgate/pwa-ui-shared/icons/DescriptionIcon';export{default as FilterIcon}from'@shopgate/pwa-ui-shared/icons/FilterIcon';export{default as FlashEnabledIcon}from'@shopgate/pwa-ui-shared/icons/FlashEnabledIcon';export{default as FlashDisabledIcon}from'@shopgate/pwa-ui-shared/icons/FlashDisabledIcon';export{default as GridIcon}from'@shopgate/pwa-ui-shared/icons/GridIcon';export{default as HeartIcon}from'@shopgate/pwa-ui-shared/icons/HeartIcon';export{default as HeartOutlineIcon}from'@shopgate/pwa-ui-shared/icons/HeartOutlineIcon';export{default as HomeIcon}from'@shopgate/pwa-ui-shared/icons/HomeIcon';export{default as InfoIcon}from'@shopgate/pwa-ui-shared/icons/InfoIcon';export{default as InfoOutlineIcon}from'@shopgate/pwa-ui-shared/icons/InfoOutlineIcon';export{default as ListIcon}from'@shopgate/pwa-ui-shared/icons/ListIcon';export{default as LocalShippingIcon}from'@shopgate/pwa-ui-shared/icons/LocalShippingIcon';export{default as LockIcon}from'@shopgate/pwa-ui-shared/icons/LockIcon';export{default as LogoutIcon}from'@shopgate/pwa-ui-shared/icons/LogoutIcon';export{default as MagnifierIcon}from'@shopgate/pwa-ui-shared/icons/MagnifierIcon';export{default as MoreIcon}from'@shopgate/pwa-ui-shared/icons/MoreIcon';export{default as MoreVertIcon}from'@shopgate/pwa-ui-shared/icons/MoreVertIcon';export{default as PlaceholderIcon}from'@shopgate/pwa-ui-shared/icons/PlaceholderIcon';export{default as RadioCheckedIcon}from'@shopgate/pwa-ui-shared/icons/RadioCheckedIcon';export{default as RadioUncheckedIcon}from'@shopgate/pwa-ui-shared/icons/RadioUncheckedIcon';export{default as SecurityIcon}from'@shopgate/pwa-ui-shared/icons/SecurityIcon';export{default as ShoppingCartIcon}from'@shopgate/pwa-ui-shared/icons/ShoppingCartIcon';export{default as SortIcon}from'@shopgate/pwa-ui-shared/icons/SortIcon';export{default as StarHalfIcon}from'@shopgate/pwa-ui-shared/icons/StarHalfIcon';export{default as StarIcon}from'@shopgate/pwa-ui-shared/icons/StarIcon';export{default as StarOutlineIcon}from'@shopgate/pwa-ui-shared/icons/StarOutlineIcon';export{default as TickIcon}from'@shopgate/pwa-ui-shared/icons/TickIcon';export{default as TrashIcon}from'@shopgate/pwa-ui-shared/icons/TrashIcon';export{default as UncheckedIcon}from'@shopgate/pwa-ui-shared/icons/UncheckedIcon';export{default as ViewListIcon}from'@shopgate/pwa-ui-shared/icons/ViewListIcon';export{default as VisibilityIcon}from'@shopgate/pwa-ui-shared/icons/VisibilityIcon';export{default as VisibilityOffIcon}from'@shopgate/pwa-ui-shared/icons/VisibilityOffIcon';export{default as NotificationIcon}from'@shopgate/pwa-ui-shared/icons/NotificationIcon';// LOCAL
|
|
12
12
|
export{default as NavigationHandler}from"./NavigationHandler";export{default as TimeBoundary}from"./TimeBoundary";export{default as IntersectionVisibility}from"./IntersectionVisibility";export{default as VideoPlayer}from"./VideoPlayer";export{default as SheetDrawer}from"./SheetDrawer";export{default as SheetList}from"./SheetList";export{default as NullComponent}from"./NullComponent";export{default as View,ViewContext}from"./View";export{Form}from"./Form";export{FormBuilder}from"./Form";export{Footer}from"./Footer";export{default as ScrollHeader}from"./ScrollHeader";export{default as ChipLayout}from"./ChipLayout";export{default as Logo}from"./Logo";export{default as SnackBarContainer}from"./SnackBarContainer";export{default as PickerUtilize}from"./PickerUtilize";export{default as QuantityInput}from"./QuantityInput";export{default as ConditionalWrapper}from"./ConditionalWrapper";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
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 _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 event from'@shopgate/pwa-core/classes/Event';import{APP_EVENT_APPLICATION_WILL_ENTER_FOREGROUND}from'@shopgate/pwa-core/constants/AppEvents';import openAppSettings from'@shopgate/pwa-core/commands/openAppSettings';import showModal from'@shopgate/pwa-common/actions/modal/showModal';import{
|
|
1
|
+
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 _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 event from'@shopgate/pwa-core/classes/Event';import{APP_EVENT_APPLICATION_WILL_ENTER_FOREGROUND}from'@shopgate/pwa-core/constants/AppEvents';import openAppSettings from'@shopgate/pwa-core/commands/openAppSettings';import showModal from'@shopgate/pwa-common/actions/modal/showModal';import{PERMISSION_STATUS_DENIED,PERMISSION_STATUS_GRANTED,PERMISSION_STATUS_NOT_DETERMINED,PERMISSION_STATUS_NOT_SUPPORTED,PERMISSION_ID_CAMERA}from'@shopgate/pwa-core/constants/AppPermissions';import{getAppPermissions,requestAppPermissions}from'@shopgate/pwa-core/commands/appPermissions';import{logger}from'@shopgate/pwa-core/helpers';import grantPermissions from"../grantPermissions";jest.mock('@shopgate/pwa-core/classes/Event');jest.mock('@shopgate/pwa-core/commands/openAppSettings');jest.mock('@shopgate/pwa-core/commands/appPermissions',function(){return{getAppPermissions:jest.fn(),requestAppPermissions:jest.fn()};});jest.mock('@shopgate/pwa-common/actions/modal/showModal',function(){return jest.fn();});jest.mock('@shopgate/pwa-core/helpers',function(){return{logger:{error:jest.fn()}};});/**
|
|
2
2
|
* @param {string} status The desired permission status.
|
|
3
3
|
* @returns {Array}
|
|
4
|
-
*/var getPermissionsResponse=function getPermissionsResponse(){var status=arguments.length>0&&arguments[0]!==undefined?arguments[0]:
|
|
4
|
+
*/var getPermissionsResponse=function getPermissionsResponse(){var status=arguments.length>0&&arguments[0]!==undefined?arguments[0]:PERMISSION_STATUS_GRANTED;return[{status:status}];};/**
|
|
5
5
|
* Flushes the promise queue.
|
|
6
6
|
* @returns {Promise}
|
|
7
|
-
*/var flushPromises=function flushPromises(){return new Promise(function(resolve){return setImmediate(resolve);});};var customModalOptions={message:'Modal message',confirm:'Confirm label',dismiss:'Dismiss label',params:{param:'one'}};describe('engage > core > actions > grantPermissions',function(){var dispatch=jest.fn(function(action){return action;});jest.useFakeTimers();beforeAll(function(){getAppPermissions.mockResolvedValue(getPermissionsResponse(
|
|
8
|
-
flushPromises().then(function(){event.call(APP_EVENT_APPLICATION_WILL_ENTER_FOREGROUND);jest.runAllTimers();});});it('should resolve with TRUE when the user opened the settings, and granted permissions',function(done){getAppPermissions.mockResolvedValueOnce(getPermissionsResponse(
|
|
7
|
+
*/var flushPromises=function flushPromises(){return new Promise(function(resolve){return setImmediate(resolve);});};var customModalOptions={message:'Modal message',confirm:'Confirm label',dismiss:'Dismiss label',params:{param:'one'}};describe('engage > core > actions > grantPermissions',function(){var dispatch=jest.fn(function(action){return action;});jest.useFakeTimers();beforeAll(function(){getAppPermissions.mockResolvedValue(getPermissionsResponse(PERMISSION_STATUS_GRANTED));requestAppPermissions.mockResolvedValue(getPermissionsResponse(PERMISSION_STATUS_GRANTED));showModal.mockResolvedValue(true);});beforeEach(function(){jest.clearAllMocks();event.removeAllListeners();});var permissionId=PERMISSION_ID_CAMERA;it('should resolve with TRUE when the permissions are granted',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(){var granted;return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:_context.next=2;return grantPermissions({permissionId:permissionId})(dispatch);case 2:granted=_context.sent;expect(granted).toBe(true);expect(getAppPermissions).toHaveBeenCalledWith([permissionId]);expect(requestAppPermissions).not.toHaveBeenCalled();expect(dispatch).not.toHaveBeenCalled();expect(openAppSettings).not.toHaveBeenCalled();expect(event.addCallbackSpy).not.toHaveBeenCalled();case 9:case"end":return _context.stop();}}},_callee);})));it('should resolve with FALSE when called with an invalid permissionId',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(){var granted;return _regeneratorRuntime.wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:_context2.next=2;return grantPermissions({permissionId:'unknownId'})(dispatch);case 2:granted=_context2.sent;expect(granted).toBe(false);expect(getAppPermissions).not.toHaveBeenCalled();expect(requestAppPermissions).not.toHaveBeenCalled();expect(dispatch).not.toHaveBeenCalled();expect(openAppSettings).not.toHaveBeenCalled();expect(event.addCallbackSpy).not.toHaveBeenCalled();expect(logger.error).toHaveBeenCalledTimes(1);case 10:case"end":return _context2.stop();}}},_callee2);})));it('should resolve with FALSE when the permissions are not supported',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(){var granted;return _regeneratorRuntime.wrap(function _callee3$(_context3){while(1){switch(_context3.prev=_context3.next){case 0:getAppPermissions.mockResolvedValueOnce(getPermissionsResponse(PERMISSION_STATUS_NOT_SUPPORTED));_context3.next=3;return grantPermissions({permissionId:permissionId})(dispatch);case 3:granted=_context3.sent;expect(granted).toBe(false);expect(getAppPermissions).toHaveBeenCalledWith([permissionId]);expect(requestAppPermissions).not.toHaveBeenCalled();expect(dispatch).not.toHaveBeenCalled();expect(openAppSettings).not.toHaveBeenCalled();expect(event.addCallbackSpy).not.toHaveBeenCalled();expect(logger.error).not.toHaveBeenCalled();case 11:case"end":return _context3.stop();}}},_callee3);})));it('should resolve with TRUE when the permissions where not determined, but the user granted them',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(){var granted;return _regeneratorRuntime.wrap(function _callee4$(_context4){while(1){switch(_context4.prev=_context4.next){case 0:getAppPermissions.mockResolvedValueOnce(getPermissionsResponse(PERMISSION_STATUS_NOT_DETERMINED));_context4.next=3;return grantPermissions({permissionId:permissionId})(dispatch);case 3:granted=_context4.sent;expect(granted).toBe(true);expect(getAppPermissions).toHaveBeenCalledWith([permissionId]);expect(requestAppPermissions).toHaveBeenCalledWith([{permissionId:permissionId}]);expect(dispatch).not.toHaveBeenCalled();expect(openAppSettings).not.toHaveBeenCalled();expect(event.addCallbackSpy).not.toHaveBeenCalled();expect(logger.error).not.toHaveBeenCalled();case 11:case"end":return _context4.stop();}}},_callee4);})));it('should resolve with FALSE when the permissions where not determined, and the user denied them',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5(){var granted;return _regeneratorRuntime.wrap(function _callee5$(_context5){while(1){switch(_context5.prev=_context5.next){case 0:getAppPermissions.mockResolvedValueOnce(getPermissionsResponse(PERMISSION_STATUS_NOT_DETERMINED));requestAppPermissions.mockResolvedValue(getPermissionsResponse(PERMISSION_STATUS_DENIED));_context5.next=4;return grantPermissions({permissionId:permissionId})(dispatch);case 4:granted=_context5.sent;expect(granted).toBe(false);expect(dispatch).not.toHaveBeenCalled();expect(openAppSettings).not.toHaveBeenCalled();expect(event.addCallbackSpy).not.toHaveBeenCalled();expect(logger.error).not.toHaveBeenCalled();case 10:case"end":return _context5.stop();}}},_callee5);})));it('should resolve with FALSE when the permissions where not determined, and the user denied them temporary',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6(){var granted;return _regeneratorRuntime.wrap(function _callee6$(_context6){while(1){switch(_context6.prev=_context6.next){case 0:getAppPermissions.mockResolvedValueOnce(getPermissionsResponse(PERMISSION_STATUS_NOT_DETERMINED));requestAppPermissions.mockResolvedValue(getPermissionsResponse(PERMISSION_STATUS_NOT_DETERMINED));_context6.next=4;return grantPermissions({permissionId:permissionId})(dispatch);case 4:granted=_context6.sent;expect(granted).toBe(false);expect(dispatch).not.toHaveBeenCalled();expect(openAppSettings).not.toHaveBeenCalled();expect(event.addCallbackSpy).not.toHaveBeenCalled();expect(logger.error).not.toHaveBeenCalled();case 10:case"end":return _context6.stop();}}},_callee6);})));it('should resolve with FALSE when the permissions are denied, and no settings modal is about to be shown',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee7(){var granted;return _regeneratorRuntime.wrap(function _callee7$(_context7){while(1){switch(_context7.prev=_context7.next){case 0:getAppPermissions.mockResolvedValueOnce(getPermissionsResponse(PERMISSION_STATUS_DENIED));_context7.next=3;return grantPermissions({permissionId:permissionId})(dispatch);case 3:granted=_context7.sent;expect(granted).toBe(false);expect(dispatch).not.toHaveBeenCalled();expect(openAppSettings).not.toHaveBeenCalled();expect(event.addCallbackSpy).not.toHaveBeenCalled();expect(logger.error).not.toHaveBeenCalled();case 9:case"end":return _context7.stop();}}},_callee7);})));it('should resolve with FALSE when the user denied to open the app settings',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee8(){var granted;return _regeneratorRuntime.wrap(function _callee8$(_context8){while(1){switch(_context8.prev=_context8.next){case 0:getAppPermissions.mockResolvedValueOnce(getPermissionsResponse(PERMISSION_STATUS_DENIED));showModal.mockResolvedValueOnce(false);_context8.next=4;return grantPermissions({permissionId:permissionId,useSettingsModal:true,modal:customModalOptions})(dispatch);case 4:granted=_context8.sent;expect(granted).toBe(false);expect(dispatch).toHaveBeenCalledTimes(1);expect(showModal).toHaveBeenCalledWith(_extends({title:null},customModalOptions));expect(openAppSettings).not.toHaveBeenCalled();expect(event.addCallbackSpy).not.toHaveBeenCalled();case 10:case"end":return _context8.stop();}}},_callee8);})));it('should resolve with FALSE when the user opened the settings, but did not grant permissions',function(done){getAppPermissions.mockResolvedValueOnce(getPermissionsResponse(PERMISSION_STATUS_DENIED));getAppPermissions.mockResolvedValueOnce(getPermissionsResponse(PERMISSION_STATUS_DENIED));grantPermissions({permissionId:permissionId,useSettingsModal:true})(dispatch).then(function(granted){expect(granted).toBe(false);expect(dispatch).toHaveBeenCalledTimes(1);expect(openAppSettings).toHaveBeenCalledTimes(1);expect(event.removeCallbackSpy).toHaveBeenCalledWith(APP_EVENT_APPLICATION_WILL_ENTER_FOREGROUND,expect.any(Function));done();});// Flush the promise queue, so that the code inside of promise from the action is executed.
|
|
8
|
+
flushPromises().then(function(){event.call(APP_EVENT_APPLICATION_WILL_ENTER_FOREGROUND);jest.runAllTimers();});});it('should resolve with TRUE when the user opened the settings, and granted permissions',function(done){getAppPermissions.mockResolvedValueOnce(getPermissionsResponse(PERMISSION_STATUS_DENIED));getAppPermissions.mockResolvedValueOnce(getPermissionsResponse(PERMISSION_STATUS_GRANTED));grantPermissions({permissionId:permissionId,useSettingsModal:true})(dispatch).then(function(granted){expect(granted).toBe(true);expect(dispatch).toHaveBeenCalledTimes(1);expect(openAppSettings).toHaveBeenCalledTimes(1);expect(event.removeCallbackSpy).toHaveBeenCalledWith(APP_EVENT_APPLICATION_WILL_ENTER_FOREGROUND,expect.any(Function));done();});// Flush the promise queue, so that the code inside of promise from the action is executed.
|
|
9
9
|
flushPromises().then(function(){event.call(APP_EVENT_APPLICATION_WILL_ENTER_FOREGROUND);jest.runAllTimers();});});});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import _regeneratorRuntime from"@babel/runtime/regenerator";function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_unsupportedIterableToArray(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}function _unsupportedIterableToArray(o,minLen){if(!o)return;if(typeof o==="string")return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(o);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(o,minLen);}function _arrayLikeToArray(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++){arr2[i]=arr[i];}return arr2;}function _iterableToArrayLimit(arr,i){var _i=arr==null?null:typeof Symbol!=="undefined"&&arr[Symbol.iterator]||arr["@@iterator"];if(_i==null)return;var _arr=[];var _n=true;var _d=false;var _s,_e;try{for(_i=_i.call(arr);!(_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;}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 event from'@shopgate/pwa-core/classes/Event';import{APP_EVENT_APPLICATION_WILL_ENTER_FOREGROUND}from'@shopgate/pwa-core/constants/AppEvents';import openAppSettings from'@shopgate/pwa-core/commands/openAppSettings';import
|
|
1
|
+
import _regeneratorRuntime from"@babel/runtime/regenerator";function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_unsupportedIterableToArray(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}function _unsupportedIterableToArray(o,minLen){if(!o)return;if(typeof o==="string")return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(o);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(o,minLen);}function _arrayLikeToArray(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++){arr2[i]=arr[i];}return arr2;}function _iterableToArrayLimit(arr,i){var _i=arr==null?null:typeof Symbol!=="undefined"&&arr[Symbol.iterator]||arr["@@iterator"];if(_i==null)return;var _arr=[];var _n=true;var _d=false;var _s,_e;try{for(_i=_i.call(arr);!(_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;}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 event from'@shopgate/pwa-core/classes/Event';import{APP_EVENT_APPLICATION_WILL_ENTER_FOREGROUND}from'@shopgate/pwa-core/constants/AppEvents';import openAppSettings from'@shopgate/pwa-core/commands/openAppSettings';import{showModal}from'@shopgate/engage/core';import{PERMISSION_STATUS_DENIED,PERMISSION_STATUS_GRANTED,PERMISSION_STATUS_NOT_DETERMINED,PERMISSION_STATUS_NOT_SUPPORTED,availablePermissionsIds}from'@shopgate/pwa-core/constants/AppPermissions';import{getAppPermissions,requestAppPermissions}from'@shopgate/pwa-core/commands/appPermissions';import{logger}from'@shopgate/pwa-core/helpers';/**
|
|
2
2
|
* Determines the current state of a specific permission for an app feature. If not already
|
|
3
3
|
* happened, the user will be prompted to grant permissions.
|
|
4
4
|
* The action returns a promise which resolves with a boolean value, that indicates the state.
|
|
@@ -6,6 +6,13 @@ import _regeneratorRuntime from"@babel/runtime/regenerator";function _slicedToAr
|
|
|
6
6
|
* @param {string} options.permissionId The id of the permission to request.
|
|
7
7
|
* @param {boolean} [options.useSettingsModal=false] Whether in case of declined permissions a modal
|
|
8
8
|
* shall be presented, which redirects to the app settings.
|
|
9
|
+
* @param {boolean} [options.useRationaleModal=false] Whether a rational modal should be shown
|
|
10
|
+
* @param {Object} [options.rationaleModal={}] Options for the rationale modal.
|
|
11
|
+
* @param {string} options.rationaleModal.title Modal title.
|
|
12
|
+
* @param {string} options.rationaleModal.message Modal message.
|
|
13
|
+
* @param {string} options.rationaleModal.confirm Label for the confirm button.
|
|
14
|
+
* @param {string} options.rationaleModal.dismiss Label for the dismiss button.
|
|
15
|
+
* @param {Object} options.rationaleModal.params Additional parameters for i18n strings.
|
|
9
16
|
* @param {Object} [options.modal={}] Options for the settings modal.
|
|
10
17
|
* @param {string} options.modal.title Modal title.
|
|
11
18
|
* @param {string} options.modal.message Modal message.
|
|
@@ -13,10 +20,10 @@ import _regeneratorRuntime from"@babel/runtime/regenerator";function _slicedToAr
|
|
|
13
20
|
* @param {string} options.modal.dismiss Label for the dismiss button.
|
|
14
21
|
* @param {Object} options.modal.params Additional parameters for i18n strings.
|
|
15
22
|
* @return { Function } A redux thunk.
|
|
16
|
-
*/var grantPermissions=function grantPermissions(){var options=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};return function(dispatch){return new Promise(/*#__PURE__*/function(){var _ref=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(resolve){var permissionId,_options$useSettingsM,useSettingsModal,_options$modal,modalOptions,status,_yield$getAppPermissi,_yield$getAppPermissi2,_yield$requestAppPerm,_yield$requestAppPerm2,openSettings,handler;return _regeneratorRuntime.wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:permissionId=options.permissionId,_options$useSettingsM=options.useSettingsModal,useSettingsModal=_options$useSettingsM===void 0?false:_options$useSettingsM,_options$modal=options.modal,modalOptions=_options$modal===void 0?{}:_options$modal;if(availablePermissionsIds.includes(permissionId)){_context2.next=5;break;}logger.error('grandPermissions: %s is no valid permission id',permissionId);resolve(false);return _context2.abrupt("return");case 5:_context2.next=7;return getAppPermissions([permissionId]);case 7:_yield$getAppPermissi=_context2.sent;_yield$getAppPermissi2=_slicedToArray(_yield$getAppPermissi,1);status=_yield$getAppPermissi2[0].status;if(!(status===
|
|
23
|
+
*/var grantPermissions=function grantPermissions(){var options=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};return function(dispatch){return new Promise(/*#__PURE__*/function(){var _ref=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(resolve){var permissionId,_options$useSettingsM,useSettingsModal,_options$useRationale,useRationaleModal,_options$rationaleMod,rationaleModalOptions,_options$modal,modalOptions,status,_yield$getAppPermissi,_yield$getAppPermissi2,requestAllowed,_yield$requestAppPerm,_yield$requestAppPerm2,openSettings,handler;return _regeneratorRuntime.wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:permissionId=options.permissionId,_options$useSettingsM=options.useSettingsModal,useSettingsModal=_options$useSettingsM===void 0?false:_options$useSettingsM,_options$useRationale=options.useRationaleModal,useRationaleModal=_options$useRationale===void 0?false:_options$useRationale,_options$rationaleMod=options.rationaleModal,rationaleModalOptions=_options$rationaleMod===void 0?{}:_options$rationaleMod,_options$modal=options.modal,modalOptions=_options$modal===void 0?{}:_options$modal;if(availablePermissionsIds.includes(permissionId)){_context2.next=5;break;}logger.error('grandPermissions: %s is no valid permission id',permissionId);resolve(false);return _context2.abrupt("return");case 5:_context2.next=7;return getAppPermissions([permissionId]);case 7:_yield$getAppPermissi=_context2.sent;_yield$getAppPermissi2=_slicedToArray(_yield$getAppPermissi,1);status=_yield$getAppPermissi2[0].status;if(!(status===PERMISSION_STATUS_NOT_SUPPORTED)){_context2.next=13;break;}resolve(false);return _context2.abrupt("return");case 13:if(!(status===PERMISSION_STATUS_NOT_DETERMINED)){_context2.next=29;break;}if(!useRationaleModal){_context2.next=21;break;}_context2.next=17;return dispatch(showModal({message:rationaleModalOptions.message||'',confirm:rationaleModalOptions.confirm||'',dismiss:rationaleModalOptions.dismiss||'',params:rationaleModalOptions.params||''}));case 17:requestAllowed=_context2.sent;if(!(requestAllowed===false)){_context2.next=21;break;}resolve(false);return _context2.abrupt("return");case 21:_context2.next=23;return requestAppPermissions([{permissionId:permissionId}]);case 23:_yield$requestAppPerm=_context2.sent;_yield$requestAppPerm2=_slicedToArray(_yield$requestAppPerm,1);status=_yield$requestAppPerm2[0].status;if(![PERMISSION_STATUS_DENIED,PERMISSION_STATUS_NOT_DETERMINED].includes(status)){_context2.next=29;break;}resolve(false);return _context2.abrupt("return");case 29:if(!(status===PERMISSION_STATUS_GRANTED)){_context2.next=32;break;}resolve(true);return _context2.abrupt("return");case 32:if(!(status===PERMISSION_STATUS_DENIED)){_context2.next=45;break;}if(useSettingsModal){_context2.next=36;break;}resolve(false);return _context2.abrupt("return");case 36:_context2.next=38;return dispatch(showModal({title:modalOptions.title||null,message:modalOptions.message,confirm:modalOptions.confirm,dismiss:modalOptions.dismiss,params:modalOptions.params}));case 38:openSettings=_context2.sent;if(openSettings){_context2.next=42;break;}resolve(false);return _context2.abrupt("return");case 42:/**
|
|
17
24
|
* Handler for the app event.
|
|
18
|
-
*/handler=/*#__PURE__*/function(){var _ref2=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(){var _yield$getAppPermissi3,_yield$getAppPermissi4;return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:event.removeCallback(APP_EVENT_APPLICATION_WILL_ENTER_FOREGROUND,handler);_context.next=3;return getAppPermissions([permissionId]);case 3:_yield$getAppPermissi3=_context.sent;_yield$getAppPermissi4=_slicedToArray(_yield$getAppPermissi3,1);status=_yield$getAppPermissi4[0].status;resolve(status===
|
|
25
|
+
*/handler=/*#__PURE__*/function(){var _ref2=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(){var _yield$getAppPermissi3,_yield$getAppPermissi4;return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:event.removeCallback(APP_EVENT_APPLICATION_WILL_ENTER_FOREGROUND,handler);_context.next=3;return getAppPermissions([permissionId]);case 3:_yield$getAppPermissi3=_context.sent;_yield$getAppPermissi4=_slicedToArray(_yield$getAppPermissi3,1);status=_yield$getAppPermissi4[0].status;resolve(status===PERMISSION_STATUS_GRANTED);case 7:case"end":return _context.stop();}}},_callee);}));return function handler(){return _ref2.apply(this,arguments);};}();/**
|
|
19
26
|
* Register an event handler, so that we can perform the permissions check again,
|
|
20
27
|
* when the user comes back from the settings.
|
|
21
28
|
*/event.addCallback(APP_EVENT_APPLICATION_WILL_ENTER_FOREGROUND,handler);// Open the settings (protected by a timeout, so that the modal closes before the app is left).
|
|
22
|
-
setTimeout(function(){openAppSettings();},0);case
|
|
29
|
+
setTimeout(function(){openAppSettings();},0);case 45:case"end":return _context2.stop();}}},_callee2);}));return function(_x){return _ref.apply(this,arguments);};}());};};export default grantPermissions;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
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{PERMISSION_ID_PUSH}from'@shopgate/pwa-core/constants/AppPermissions';import grantPermissions from"./grantPermissions";/**
|
|
2
|
+
* Determines the current state of the push permissions.
|
|
3
|
+
* If not already happened, the user will be prompted to grant permissions.
|
|
4
|
+
* The action returns a promise which resolves with a boolean value, that indicates the state.
|
|
5
|
+
* @param {Object} options Action options.
|
|
6
|
+
* @param {boolean} [options.useSettingsModal=false] Whether in case of declined permissions a modal
|
|
7
|
+
* shall be presented, which redirects to the app settings.
|
|
8
|
+
* @param {boolean} [options.useRationaleModal=true] Whether a rational modal should be shown
|
|
9
|
+
* @param {Object} [options.rationaleModal={}] Options for the rationale modal.
|
|
10
|
+
* @param {string} options.rationaleModal.title Modal title.
|
|
11
|
+
* @param {string} options.rationaleModal.message Modal message.
|
|
12
|
+
* @param {string} options.rationaleModal.confirm Label for the confirm button.
|
|
13
|
+
* @param {string} options.rationaleModal.dismiss Label for the dismiss button.
|
|
14
|
+
* @param {Object} options.rationaleModal.params Additional parameters for i18n strings.
|
|
15
|
+
* @param {Object} [options.modal={}] Options for the settings modal.
|
|
16
|
+
* @param {string} options.modal.title Modal title.
|
|
17
|
+
* @param {string} options.modal.message Modal message.
|
|
18
|
+
* @param {string} options.modal.confirm Label for the confirm button.
|
|
19
|
+
* @param {string} options.modal.dismiss Label for the dismiss button.
|
|
20
|
+
* @param {Object} options.modal.params Additional parameters for i18n strings.
|
|
21
|
+
* @return { Function } A redux thunk.
|
|
22
|
+
*/var grantPushPermissions=function grantPushPermissions(){var options=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};return function(dispatch){var _options$useSettingsM=options.useSettingsModal,useSettingsModal=_options$useSettingsM===void 0?true:_options$useSettingsM,_options$useRationale=options.useRationaleModal,useRationaleModal=_options$useRationale===void 0?true:_options$useRationale,_options$modal=options.modal,modal=_options$modal===void 0?{}:_options$modal,_options$rationaleMod=options.rationaleModal,rationaleModal=_options$rationaleMod===void 0?{}:_options$rationaleMod;return dispatch(grantPermissions({permissionId:PERMISSION_ID_PUSH,useSettingsModal:useSettingsModal,useRationaleModal:useRationaleModal,modal:_extends({title:null,message:'permissions.access_denied.push_message',confirm:'permissions.access_denied.settings_button'},modal),rationaleModal:rationaleModal}));};};export default grantPushPermissions;
|
package/core/index.js
CHANGED
|
@@ -16,7 +16,7 @@ export { default as routePortals } from '@shopgate/pwa-common/helpers/portals/ro
|
|
|
16
16
|
*/export*from'@shopgate/pwa-common/helpers/redux';export*from'@shopgate/pwa-common/helpers/style';export*from'@shopgate/pwa-common/helpers/tracking';export*from'@shopgate/pwa-common/helpers/validation';// STREAMS
|
|
17
17
|
export*from'@shopgate/pwa-common/streams/main';export*from'@shopgate/pwa-common/streams/error';// --------------- APP --------------- //
|
|
18
18
|
// ACTIONS
|
|
19
|
-
export{default as handleDeepLink}from'@shopgate/pwa-common/actions/app/handleDeepLink';export{default as handleUniversalLink}from'@shopgate/pwa-common/actions/app/handleUniversalLink';export{default as handleLink}from'@shopgate/pwa-common/actions/app/handleLink';export{default as handlePushNotification}from'@shopgate/pwa-common/actions/app/handlePushNotification';export{default as registerLinkEvents}from'@shopgate/pwa-common/actions/app/registerLinkEvents';export{default as updateStatusBarBackground}from"./actions/updateStatusBarBackground";export{default as grantPermissions}from"./actions/grantPermissions";export{default as grantCameraPermissions}from"./actions/grantCameraPermissions";export{default as grantGeolocationPermissions}from"./actions/grantGeolocationPermissions";export{default as getGeolocation}from"./actions/getGeolocation";// STREAMS
|
|
19
|
+
export{default as handleDeepLink}from'@shopgate/pwa-common/actions/app/handleDeepLink';export{default as handleUniversalLink}from'@shopgate/pwa-common/actions/app/handleUniversalLink';export{default as handleLink}from'@shopgate/pwa-common/actions/app/handleLink';export{default as handlePushNotification}from'@shopgate/pwa-common/actions/app/handlePushNotification';export{default as registerLinkEvents}from'@shopgate/pwa-common/actions/app/registerLinkEvents';export{default as updateStatusBarBackground}from"./actions/updateStatusBarBackground";export{default as grantPermissions}from"./actions/grantPermissions";export{default as grantCameraPermissions}from"./actions/grantCameraPermissions";export{default as grantPushPermissions}from"./actions/grantPushPermissions";export{default as grantGeolocationPermissions}from"./actions/grantGeolocationPermissions";export{default as getGeolocation}from"./actions/getGeolocation";// STREAMS
|
|
20
20
|
export*from'@shopgate/pwa-common/streams/app';// --------------- STORE --------------- //
|
|
21
21
|
export*from'@shopgate/pwa-common/store';// --------------- CLIENT --------------- //
|
|
22
22
|
// ACTIONS
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shopgate/engage",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.22.0-beta.2",
|
|
4
4
|
"description": "Shopgate's ENGAGE library.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Shopgate <support@shopgate.com>",
|
|
@@ -15,12 +15,12 @@
|
|
|
15
15
|
"connect"
|
|
16
16
|
],
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@shopgate/pwa-common": "6.
|
|
19
|
-
"@shopgate/pwa-common-commerce": "6.
|
|
20
|
-
"@shopgate/pwa-core": "6.
|
|
21
|
-
"@shopgate/pwa-ui-ios": "6.
|
|
22
|
-
"@shopgate/pwa-ui-material": "6.
|
|
23
|
-
"@shopgate/pwa-ui-shared": "6.
|
|
18
|
+
"@shopgate/pwa-common": "6.22.0-beta.2",
|
|
19
|
+
"@shopgate/pwa-common-commerce": "6.22.0-beta.2",
|
|
20
|
+
"@shopgate/pwa-core": "6.22.0-beta.2",
|
|
21
|
+
"@shopgate/pwa-ui-ios": "6.22.0-beta.2",
|
|
22
|
+
"@shopgate/pwa-ui-material": "6.22.0-beta.2",
|
|
23
|
+
"@shopgate/pwa-ui-shared": "6.22.0-beta.2",
|
|
24
24
|
"@virtuous/conductor": "~2.4.0",
|
|
25
25
|
"babel-plugin-transform-es3-member-expression-literals": "^6.8.0",
|
|
26
26
|
"babel-plugin-transform-es3-property-literals": "^6.8.0",
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
function _typeof(obj){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj;}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;},_typeof(obj);}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 _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);Object.defineProperty(Constructor,"prototype",{writable:false});return Constructor;}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});Object.defineProperty(subClass,"prototype",{writable:false});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}function _createSuper(Derived){var hasNativeReflectConstruct=_isNativeReflectConstruct();return function _createSuperInternal(){var Super=_getPrototypeOf(Derived),result;if(hasNativeReflectConstruct){var NewTarget=_getPrototypeOf(this).constructor;result=Reflect.construct(Super,arguments,NewTarget);}else{result=Super.apply(this,arguments);}return _possibleConstructorReturn(this,result);};}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}else if(call!==void 0){throw new TypeError("Derived constructors may only return object or undefined");}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));return true;}catch(e){return false;}}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}import React,{PureComponent}from'react';import PropTypes from'prop-types';import{SheetDrawer,SheetList}from'@shopgate/engage/components';import{VariantContext,ProductContext}from'@shopgate/engage/product';import{ViewContext}from'@shopgate/engage/components/View';import Item from"../SheetItem";import VariantAvailability from"../VariantAvailability";/**
|
|
2
2
|
* The CharacteristicSheet component.
|
|
3
|
-
*/var CharacteristicSheet=/*#__PURE__*/function(_PureComponent){_inherits(CharacteristicSheet,_PureComponent);var _super=_createSuper(CharacteristicSheet);function CharacteristicSheet(){var _this;_classCallCheck(this,CharacteristicSheet);for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key];}_this=_super.call.apply(_super,[this].concat(args));_defineProperty(_assertThisInitialized(_this),"firstSelectableItemRef",/*#__PURE__*/React.createRef());_defineProperty(_assertThisInitialized(_this),"onDidOpen",function(){if(_this.firstSelectableItemRef.current){_this.firstSelectableItemRef.current.focus();}_this.props.setViewAriaHidden(true);});_defineProperty(_assertThisInitialized(_this),"onClose",function(e){_this.props.onClose(e);_this.props.setViewAriaHidden(false);});_defineProperty(_assertThisInitialized(_this),"handleItemClick",function(event){event.stopPropagation();_this.props.onSelect(
|
|
3
|
+
*/var CharacteristicSheet=/*#__PURE__*/function(_PureComponent){_inherits(CharacteristicSheet,_PureComponent);var _super=_createSuper(CharacteristicSheet);function CharacteristicSheet(){var _this;_classCallCheck(this,CharacteristicSheet);for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key];}_this=_super.call.apply(_super,[this].concat(args));_defineProperty(_assertThisInitialized(_this),"firstSelectableItemRef",/*#__PURE__*/React.createRef());_defineProperty(_assertThisInitialized(_this),"onDidOpen",function(){if(_this.firstSelectableItemRef.current){_this.firstSelectableItemRef.current.focus();}_this.props.setViewAriaHidden(true);});_defineProperty(_assertThisInitialized(_this),"onClose",function(e){_this.props.onClose(e);_this.props.setViewAriaHidden(false);});_defineProperty(_assertThisInitialized(_this),"handleItemClick",function(event,itemId){event.stopPropagation();_this.props.onSelect(itemId);});_defineProperty(_assertThisInitialized(_this),"renderAvailability",function(value){var selection=_extends({},_this.props.selection,_defineProperty({},_this.props.charId,value));return/*#__PURE__*/React.createElement(VariantAvailability,{characteristics:selection,productId:_this.props.productId});});return _this;}_createClass(CharacteristicSheet,[{key:"render",value:/**
|
|
4
4
|
* @return {JSX}
|
|
5
|
-
*/function render(){var _this2=this;var _this$props=this.props,items=_this$props.items,label=_this$props.label,open=_this$props.open,selectedValue=_this$props.selectedValue;var selectedIndex;if(selectedValue){selectedIndex=items.findIndex(function(item){return item.id===selectedValue;});}else{selectedIndex=items.findIndex(function(item){return item.selectable;});}return/*#__PURE__*/React.createElement(SheetDrawer,{title:label,isOpen:open,onClose:this.onClose,onDidOpen:this.onDidOpen},/*#__PURE__*/React.createElement(SheetList,{className:"theme__product__characteristic__sheet"},items.map(function(item,index){return/*#__PURE__*/React.createElement(Item,{item:item,key:item.id,onClick:_this2.handleItemClick,rightComponent:function rightComponent(){return _this2.renderAvailability(item.id);},selected:item.id===selectedValue,ref:index===selectedIndex?_this2.firstSelectableItemRef:null});})));}}]);return CharacteristicSheet;}(PureComponent);/**
|
|
5
|
+
*/function render(){var _this2=this;var _this$props=this.props,items=_this$props.items,label=_this$props.label,open=_this$props.open,selectedValue=_this$props.selectedValue;var selectedIndex;if(selectedValue){selectedIndex=items.findIndex(function(item){return item.id===selectedValue;});}else{selectedIndex=items.findIndex(function(item){return item.selectable;});}return/*#__PURE__*/React.createElement(SheetDrawer,{title:label,isOpen:open,onClose:this.onClose,onDidOpen:this.onDidOpen},/*#__PURE__*/React.createElement(SheetList,{className:"theme__product__characteristic__sheet"},items.map(function(item,index){return/*#__PURE__*/React.createElement(Item,{item:item,key:item.id,onClick:_this2.handleItemClick,rightComponent:function rightComponent(){return _this2.renderAvailability(item.id);},selected:item.id===selectedValue,ref:index===selectedIndex?_this2.firstSelectableItemRef:null,characteristics:_extends({},_this2.props.selection,_defineProperty({},_this2.props.charId,item.id))});})));}}]);return CharacteristicSheet;}(PureComponent);/**
|
|
6
6
|
* @param {Object} props The original component props.
|
|
7
7
|
* @returns {JSX}
|
|
8
8
|
*/_defineProperty(CharacteristicSheet,"defaultProps",{onClose:function onClose(){},onSelect:function onSelect(){},productId:null,selectedValue:null,selection:null});var SheetComponent=function SheetComponent(props){return/*#__PURE__*/React.createElement(ViewContext.Consumer,null,function(_ref){var setAriaHidden=_ref.setAriaHidden;return/*#__PURE__*/React.createElement(ProductContext.Consumer,null,function(_ref2){var productId=_ref2.productId;return/*#__PURE__*/React.createElement(VariantContext.Consumer,null,function(_ref3){var characteristics=_ref3.characteristics;return/*#__PURE__*/React.createElement(CharacteristicSheet,_extends({productId:productId,selection:characteristics,setViewAriaHidden:setAriaHidden},props));});});});};export default SheetComponent;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
function _typeof(obj){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj;}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;},_typeof(obj);}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 _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);Object.defineProperty(Constructor,"prototype",{writable:false});return Constructor;}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});Object.defineProperty(subClass,"prototype",{writable:false});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}function _createSuper(Derived){var hasNativeReflectConstruct=_isNativeReflectConstruct();return function _createSuperInternal(){var Super=_getPrototypeOf(Derived),result;if(hasNativeReflectConstruct){var NewTarget=_getPrototypeOf(this).constructor;result=Reflect.construct(Super,arguments,NewTarget);}else{result=Super.apply(this,arguments);}return _possibleConstructorReturn(this,result);};}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}else if(call!==void 0){throw new TypeError("Derived constructors may only return object or undefined");}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));return true;}catch(e){return false;}}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}import React,{PureComponent}from'react';import PropTypes from'prop-types';import{withForwardedRef}from'@shopgate/engage/core';import styles from"./style";/**
|
|
1
|
+
function _typeof(obj){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj;}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;},_typeof(obj);}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 _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);Object.defineProperty(Constructor,"prototype",{writable:false});return Constructor;}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});Object.defineProperty(subClass,"prototype",{writable:false});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}function _createSuper(Derived){var hasNativeReflectConstruct=_isNativeReflectConstruct();return function _createSuperInternal(){var Super=_getPrototypeOf(Derived),result;if(hasNativeReflectConstruct){var NewTarget=_getPrototypeOf(this).constructor;result=Reflect.construct(Super,arguments,NewTarget);}else{result=Super.apply(this,arguments);}return _possibleConstructorReturn(this,result);};}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}else if(call!==void 0){throw new TypeError("Derived constructors may only return object or undefined");}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));return true;}catch(e){return false;}}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}import React,{PureComponent}from'react';import PropTypes from'prop-types';import{withForwardedRef}from'@shopgate/engage/core';import{CharacteristicsButton}from'@shopgate/engage/back-in-stock/components';import styles from"./style";/**
|
|
2
2
|
* The SheetItem component.
|
|
3
|
-
*/var SheetItem=/*#__PURE__*/function(_PureComponent){_inherits(SheetItem,_PureComponent);var _super=_createSuper(SheetItem);function SheetItem(){var _this;_classCallCheck(this,SheetItem);for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key];}_this=_super.call.apply(_super,[this].concat(args));_defineProperty(_assertThisInitialized(_this),"getStyle",function(selectable){var selected=_this.props.selected;if(selected){return styles.buttonSelected;}if(!selectable){return styles.buttonDisabled;}return styles.button;});_defineProperty(_assertThisInitialized(_this),"buildProps",function(){var _this$props=_this.props,item=_this$props.item,
|
|
3
|
+
*/var SheetItem=/*#__PURE__*/function(_PureComponent){_inherits(SheetItem,_PureComponent);var _super=_createSuper(SheetItem);function SheetItem(){var _this;_classCallCheck(this,SheetItem);for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key];}_this=_super.call.apply(_super,[this].concat(args));_defineProperty(_assertThisInitialized(_this),"getStyle",function(selectable){var selected=_this.props.selected;if(selected){return styles.buttonSelected;}if(!selectable){return styles.buttonDisabled;}return styles.button;});_defineProperty(_assertThisInitialized(_this),"buildProps",function(){var _this$props=_this.props,item=_this$props.item,_onClick=_this$props.onClick,forwardedRef=_this$props.forwardedRef;return _extends({className:"".concat(_this.getStyle(item.selectable).toString()," theme__product__characteristic__option"),key:item.id,ref:forwardedRef,value:item.id,'aria-hidden':!item.selectable},item.selectable&&{onClick:function onClick(event){return _onClick(event,item.id);}});});return _this;}_createClass(SheetItem,[{key:"render",value:/**
|
|
4
4
|
* @returns {JSX}
|
|
5
|
-
*/function render(){var _this$props2=this.props,item=_this$props2.item,Right=_this$props2.rightComponent,selected=_this$props2.selected;return/*#__PURE__*/React.createElement("button",_extends({},
|
|
5
|
+
*/function render(){var _this$props2=this.props,item=_this$props2.item,Right=_this$props2.rightComponent,selected=_this$props2.selected,characteristics=_this$props2.characteristics;var buildProps=this.buildProps();return/*#__PURE__*/React.createElement("button",_extends({},buildProps,{"data-test-id":item.label,"aria-selected":selected,role:"option",type:"button"}),item.label,item.selectable&&/*#__PURE__*/React.createElement(Right,null),item.selectable&&/*#__PURE__*/React.createElement(CharacteristicsButton,{characteristics:characteristics}));}}]);return SheetItem;}(PureComponent);_defineProperty(SheetItem,"defaultProps",{forwardedRef:null,onClick:function onClick(){},rightComponent:null,selected:false});export default withForwardedRef(SheetItem);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{css}from'glamor';import{themeConfig}from'@shopgate/pwa-common/helpers/config';var colors=themeConfig.colors,variables=themeConfig.variables;var button=css({outline:0,padding:'16px
|
|
1
|
+
import{css}from'glamor';import{themeConfig}from'@shopgate/pwa-common/helpers/config';var colors=themeConfig.colors,variables=themeConfig.variables;var button=css({outline:0,padding:'16px 0 16px 0',textAlign:'left',width:'100%'});var buttonDisabled=css(button,{color:colors.shade4});var bgColor=colors.darkGray;var boxShadowOffset=variables.gap.bigger;var buttonSelected=css(button,{background:bgColor,boxShadow:"-".concat(boxShadowOffset,"px 0 0 ").concat(bgColor,", ").concat(boxShadowOffset,"px 0 0 ").concat(bgColor),margin:'-1px 0',paddingTop:17,paddingBottom:17});export default{button:button,buttonDisabled:buttonDisabled,buttonSelected:buttonSelected};
|
package/product/index.js
CHANGED
|
@@ -4,7 +4,7 @@ export{default as changeSortOrder}from'@shopgate/pwa-common-commerce/product/act
|
|
|
4
4
|
export{default as productImageFormats}from'@shopgate/pwa-common-commerce/product/collections/ProductImageFormats';// CONSTANTS
|
|
5
5
|
export*from'@shopgate/pwa-common-commerce/product/constants/index';export*from'@shopgate/pwa-common-commerce/product/constants/Pipelines';export*from'@shopgate/pwa-common-commerce/product/constants/Portals';export*from"./constants";// HELPERS
|
|
6
6
|
export*from'@shopgate/pwa-common-commerce/product/helpers';export*from"./helpers/index";export*from"./helpers/redirects";export*from"./components/Media/helpers";// SELECTORS
|
|
7
|
-
export*from'@shopgate/pwa-common-commerce/product/selectors/options';export*from'@shopgate/pwa-common-commerce/product/selectors/page';export*from'@shopgate/pwa-common-commerce/product/selectors/price';export*from'@shopgate/pwa-common-commerce/product/selectors/product';export*from'@shopgate/pwa-common-commerce/product/selectors/relations';export*from'@shopgate/pwa-common-commerce/product/selectors/variants';export*from"./selectors/media";export{makeGetProductProperties,makeGetProductEffectivityDates,makeGetProductCharacteristics,makeGetProductFeaturedMedia,makeIsProductActive,makeIsBaseProductActive}from"./selectors/product";export*from"./selectors/price";export*from"./selectors/variants";export*from"./selectors/relations";// STREAMS
|
|
7
|
+
export*from'@shopgate/pwa-common-commerce/product/selectors/options';export*from'@shopgate/pwa-common-commerce/product/selectors/page';export*from'@shopgate/pwa-common-commerce/product/selectors/price';export*from'@shopgate/pwa-common-commerce/product/selectors/product';export*from'@shopgate/pwa-common-commerce/product/selectors/relations';export*from'@shopgate/pwa-common-commerce/product/selectors/variants';export*from"./selectors/media";export{makeGetProductProperties,makeGetProductEffectivityDates,makeGetProductCharacteristics,makeGetProductFeaturedMedia,makeIsProductActive,makeIsBaseProductActive,makeGetProductType}from"./selectors/product";export*from"./selectors/price";export*from"./selectors/variants";export*from"./selectors/relations";// STREAMS
|
|
8
8
|
export*from'@shopgate/pwa-common-commerce/product/streams';// COMPONENTS
|
|
9
9
|
export{default as ProductProperties}from"./components/ProductProperties/ProductProperties";export{default as MapPriceHint}from"./components/MapPriceHint";export{default as OrderQuantityHint}from"./components/OrderQuantityHint";export{default as ProductImage}from"./components/ProductImage";export{default as MediaSlider}from"./components/MediaSlider";export{default as QuantityPicker}from"./components/QuantityPicker";export{default as EffectivityDates}from"./components/EffectivityDates";export{default as PriceDifference}from"./components/PriceDifference";export{FeaturedMedia,MediaImage}from"./components/Media";export{VariantSwatch}from"./components/Swatch";export{Swatches}from"./components/Swatches";export{RelationsSlider}from"./components/RelationsSlider";export{default as ProductCard}from"./components/ProductCard";export{default as ProductGridPrice}from"./components/ProductGridPrice";export{default as ProductCharacteristics}from"./components/ProductCharacteristics";export{default as Description}from"./components/Description";export{default as ProductList}from"./components/ProductList";export{default as ProductSlider}from"./components/ProductSlider";export{default as Options}from"./components/Options";export{default as Characteristics}from"./components/Characteristics";export{default as Rating}from"./components/Rating";export{default as ProductProvider}from"./components/ProductProvider";export{default as ProductBadges}from"./components/ProductBadges";// HOCs
|
|
10
10
|
export{default as withPriceCalculation}from"./hocs/withPriceCalculation";export{default as withProductStock}from"./hocs/withProductStock";export{default as withProductListType}from"./hocs/withProductListType";export{default as withProductListEntry}from"./hocs/withProductListEntry";// HOOKs
|
|
@@ -19,4 +19,8 @@ import{createSelector}from'reselect';import{getProductPropertiesState,getProduct
|
|
|
19
19
|
*/export var makeIsBaseProductActive=function makeIsBaseProductActive(){return createSelector(getBaseProduct,function(baseProduct){if(!baseProduct){return false;}return baseProduct.active||false;});};/**
|
|
20
20
|
* Creates a selector to get the property of a product based on a given label
|
|
21
21
|
* @returns {Function}
|
|
22
|
-
*/export var getCurrentProductPropertyByLabel=createSelector(getProductPropertiesUnfiltered,function(state,props){return props.widgetSettings;},function(currentProductProperties,widgetSettings){if(!currentProductProperties||!widgetSettings||!widgetSettings.propertyLabel){return null;}return currentProductProperties.find(function(_ref){var label=_ref.label;return label===widgetSettings.propertyLabel;});})
|
|
22
|
+
*/export var getCurrentProductPropertyByLabel=createSelector(getProductPropertiesUnfiltered,function(state,props){return props.widgetSettings;},function(currentProductProperties,widgetSettings){if(!currentProductProperties||!widgetSettings||!widgetSettings.propertyLabel){return null;}return currentProductProperties.find(function(_ref){var label=_ref.label;return label===widgetSettings.propertyLabel;});});/**
|
|
23
|
+
* Create a selector to retrieve the product type.
|
|
24
|
+
* @returns {Function}
|
|
25
|
+
*
|
|
26
|
+
*/export var makeGetProductType=function makeGetProductType(){return createSelector(getProduct,function(product){return product===null||product===void 0?void 0:product.type;});};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import{createSelector}from'reselect';import find from'lodash/find';import{getProductVariants}from'@shopgate/pwa-common-commerce/product';/**
|
|
1
|
+
import{createSelector}from'reselect';import find from'lodash/find';import{getProductVariants}from'@shopgate/pwa-common-commerce/product';import isEqual from'lodash/isEqual';/**
|
|
2
2
|
* Creates a selector that retrieves a product by a characteristic.
|
|
3
3
|
* @returns {Function}
|
|
4
|
-
*/export function makeGetProductByCharacteristics(){return createSelector(function(_,props){return props.characteristics;},getProductVariants,function(characteristics,variants){if(!characteristics||!variants||!variants.products||variants.products.length===0){return null;}var product=find(variants.products,{characteristics:characteristics});if(!product){return null;}return product;});}/**
|
|
4
|
+
*/export function makeGetProductByCharacteristics(){var _ref=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{},strict=_ref.strict;return createSelector(function(_,props){return props.characteristics;},getProductVariants,function(characteristics,variants){if(!characteristics||!variants||!variants.products||variants.products.length===0){return null;}var product;if(strict){product=variants.products.find(function(_product){return isEqual(_product.characteristics,characteristics);});}else{product=find(variants.products,{characteristics:characteristics});}if(!product){return null;}return product;});}/**
|
|
5
5
|
* Creates a selector that retrieves the featured image URL for a selected characteristic.
|
|
6
6
|
* @returns {Function}
|
|
7
7
|
*/export function makeGetCharacteristicsFeaturedImage(){var getProductByCharacteristics=makeGetProductByCharacteristics();return createSelector(getProductByCharacteristics,function(product){if(!product||!product.featuredImageBaseUrl){return null;}return product.featuredImageBaseUrl;});}/**
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export*from"./optInTrigger";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import{PUSH_OPT_IN_INCREASE_APP_START_COUNT,PUSH_OPT_IN_RESET_APP_START_COUNT,PUSH_OPT_IN_INCREASE_ORDERS_PLACED_COUNT,PUSH_OPT_IN_RESET_ORDERS_PLACED_COUNT,PUSH_OPT_IN_INCREASE_REJECTION_COUNT,PUSH_OPT_IN_SET_LAST_POPUP_TIMESTAMP,PUSH_OPT_IN_OPT_IN_POSTPONED}from"../constants";/**
|
|
2
|
+
* Increment the app start count
|
|
3
|
+
* @return {Object} The dispatched action object.
|
|
4
|
+
*/export var increaseAppStartCount=function increaseAppStartCount(){return{type:PUSH_OPT_IN_INCREASE_APP_START_COUNT};};/**
|
|
5
|
+
* Reset the app start count, and increment reset counts
|
|
6
|
+
* @return {Object} The dispatched action object.
|
|
7
|
+
*/export var resetAppStartCount=function resetAppStartCount(){return{type:PUSH_OPT_IN_RESET_APP_START_COUNT};};/**
|
|
8
|
+
* Increment the orders placed count
|
|
9
|
+
* @return {Object} The dispatched action object.
|
|
10
|
+
*/export var increaseOrdersPlacedCount=function increaseOrdersPlacedCount(){return{type:PUSH_OPT_IN_INCREASE_ORDERS_PLACED_COUNT};};/**
|
|
11
|
+
* Reset the orders placed count, and increment reset counts
|
|
12
|
+
* @return {Object} The dispatched action object.
|
|
13
|
+
*/export var resetOrdersPlacedCount=function resetOrdersPlacedCount(){return{type:PUSH_OPT_IN_RESET_ORDERS_PLACED_COUNT};};/**
|
|
14
|
+
* Sets the last opt-in timestamp
|
|
15
|
+
* @return {Object} The dispatched action object.
|
|
16
|
+
*/export var setLastPopupTimestamp=function setLastPopupTimestamp(){return{type:PUSH_OPT_IN_SET_LAST_POPUP_TIMESTAMP};};/**
|
|
17
|
+
* Increased the opt-in rejection / postponement count
|
|
18
|
+
* @return {Object} The dispatched action object.
|
|
19
|
+
*/export var increaseRejectionCount=function increaseRejectionCount(){return{type:PUSH_OPT_IN_INCREASE_REJECTION_COUNT};};/**
|
|
20
|
+
* Action to be dispatched when push opt in was postponed e.g. Opt In Modal was closed without
|
|
21
|
+
* taking a decision about permissions.
|
|
22
|
+
* @return {Object} The dispatched action object.
|
|
23
|
+
*/export var optInPostponed=function optInPostponed(){return{type:PUSH_OPT_IN_OPT_IN_POSTPONED};};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export*from"./optInTrigger";
|
|
@@ -0,0 +1,6 @@
|
|
|
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);});};}/**
|
|
2
|
+
* Redux thunk to the dispatched when the push opt in is supposed to be shown
|
|
3
|
+
* (Modal or native Dialog)
|
|
4
|
+
* @returns {Function}
|
|
5
|
+
*/export var showOptIn=function showOptIn(){return/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(){return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:// TODO implement logic
|
|
6
|
+
console.warn('SHOW_PUSH_OPT_IN');case 1:case"end":return _context.stop();}}},_callee);}));};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export*from"./optInTrigger";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export var PUSH_OPT_IN_INCREASE_APP_START_COUNT='PUSH_OPT_IN_INCREASE_APP_START_COUNT';export var PUSH_OPT_IN_RESET_APP_START_COUNT='PUSH_OPT_IN_RESET_APP_START_COUNT';export var PUSH_OPT_IN_RESET_APP_START_STATE='PUSH_OPT_IN_RESET_APP_START_STATE';export var PUSH_OPT_IN_INCREASE_ORDERS_PLACED_COUNT='PUSH_OPT_IN_INCREASE_ORDERS_PLACED_COUNT';export var PUSH_OPT_IN_RESET_ORDERS_PLACED_COUNT='PUSH_OPT_IN_RESET_ORDERS_PLACED_COUNT';export var PUSH_OPT_IN_RESET_ORDERS_PLACED_STATE='PUSH_OPT_IN_RESET_ORDERS_PLACED_STATE';export var PUSH_OPT_IN_SET_LAST_POPUP_TIMESTAMP='PUSH_OPT_IN_SET_LAST_POPUP_TIMESTAMP';export var PUSH_OPT_IN_INCREASE_REJECTION_COUNT='PUSH_OPT_IN_INCREASE_REJECTION_COUNT';export var PUSH_OPT_IN_OPT_IN_POSTPONED='PUSH_OPT_IN_OPT_IN_POSTPONED';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{combineReducers}from'redux';import optInTrigger from"./optInTrigger";export default combineReducers({optInTrigger:optInTrigger});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
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{PUSH_OPT_IN_INCREASE_APP_START_COUNT,PUSH_OPT_IN_RESET_APP_START_STATE,PUSH_OPT_IN_RESET_APP_START_COUNT,PUSH_OPT_IN_INCREASE_ORDERS_PLACED_COUNT,PUSH_OPT_IN_RESET_ORDERS_PLACED_COUNT,PUSH_OPT_IN_RESET_ORDERS_PLACED_STATE,PUSH_OPT_IN_SET_LAST_POPUP_TIMESTAMP,PUSH_OPT_IN_INCREASE_REJECTION_COUNT}from"../constants";var defaultState={appStartCount:0,appStartResetCount:0,ordersPlacedCount:0,ordersPlacedResetCount:0,lastPopupAt:null,rejectionCount:0};/**
|
|
2
|
+
* Stores all the states related to the pushOptInTrigger functionality.
|
|
3
|
+
* @param {Object} [state] The current state.
|
|
4
|
+
* @param {Object} action The action object.
|
|
5
|
+
* @return {Object} The new state.
|
|
6
|
+
*/var pushOptInReducer=function pushOptInReducer(){var state=arguments.length>0&&arguments[0]!==undefined?arguments[0]:defaultState;var action=arguments.length>1?arguments[1]:undefined;switch(action.type){case PUSH_OPT_IN_INCREASE_APP_START_COUNT:{return _extends({},state,{appStartCount:state.appStartCount+1});}case PUSH_OPT_IN_RESET_APP_START_COUNT:{return _extends({},state,{appStartCount:0,appStartResetCount:state.appStartResetCount+1});}case PUSH_OPT_IN_RESET_APP_START_STATE:{return _extends({},state,{appStartCount:0,appStartResetCount:0});}case PUSH_OPT_IN_INCREASE_ORDERS_PLACED_COUNT:{return _extends({},state,{ordersPlacedCount:state.ordersPlacedCount+1});}case PUSH_OPT_IN_RESET_ORDERS_PLACED_COUNT:{return _extends({},state,{ordersPlacedCount:0,ordersPlacedResetCount:state.ordersPlacedResetCount+1});}case PUSH_OPT_IN_RESET_ORDERS_PLACED_STATE:{return _extends({},state,{ordersPlacedCount:0,ordersPlacedResetCount:0});}case PUSH_OPT_IN_SET_LAST_POPUP_TIMESTAMP:{return _extends({},state,{lastPopupAt:Date.now()});}case PUSH_OPT_IN_INCREASE_REJECTION_COUNT:{return _extends({},state,{rejectionCount:state.rejectionCount+1});}default:return state;}};export default pushOptInReducer;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export*from"./optInTrigger";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Selects the push opt in information.
|
|
3
|
+
* @param {Object} state The current state.
|
|
4
|
+
* @returns {Object} The push opt in information.
|
|
5
|
+
*/export var getPushOptInTriggerState=function getPushOptInTriggerState(state){var _state$pushOptIn;return(state===null||state===void 0?void 0:(_state$pushOptIn=state.pushOptIn)===null||_state$pushOptIn===void 0?void 0:_state$pushOptIn.optInTrigger)||{};};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import optInTrigger from"./optInTrigger";export default(function(subscribe){optInTrigger(subscribe);});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import _regeneratorRuntime from"@babel/runtime/regenerator";function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_unsupportedIterableToArray(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}function _unsupportedIterableToArray(o,minLen){if(!o)return;if(typeof o==="string")return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(o);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(o,minLen);}function _arrayLikeToArray(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++){arr2[i]=arr[i];}return arr2;}function _iterableToArrayLimit(arr,i){var _i=arr==null?null:typeof Symbol!=="undefined"&&arr[Symbol.iterator]||arr["@@iterator"];if(_i==null)return;var _arr=[];var _n=true;var _d=false;var _s,_e;try{for(_i=_i.call(arr);!(_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;}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{appConfig}from'@shopgate/engage';import{main$,event,appDidStart$,getAppPermissions,PERMISSION_ID_PUSH,PERMISSION_STATUS_NOT_DETERMINED}from'@shopgate/engage/core';import{increaseAppStartCount,resetAppStartCount,increaseOrdersPlacedCount,resetOrdersPlacedCount,setLastPopupTimestamp,increaseRejectionCount}from"../action-creators";import{PUSH_OPT_IN_OPT_IN_POSTPONED}from"../constants";import{getPushOptInTriggerState}from"../selectors";import{showOptIn}from"../actions";var DAY_IN_MS=1000*60*60*24;var increaseRejectionCount$=main$.filter(function(_ref){var action=_ref.action;return action.type===PUSH_OPT_IN_OPT_IN_POSTPONED;});/**
|
|
2
|
+
* Push opt in subscriptions
|
|
3
|
+
* @param {Function} subscribe The subscribe function
|
|
4
|
+
*/export default function pushOptIn(subscribe){/**
|
|
5
|
+
* @param {Object} subscriptionParams Params from the subscription callback
|
|
6
|
+
* @param {string} configKey The "pushOptIn" key to be used
|
|
7
|
+
* @param {Function} increaseCountAction Action to increase the count in Redux for the configKey
|
|
8
|
+
* @returns {void}
|
|
9
|
+
*/var showOptInAfterChecks=/*#__PURE__*/function(){var _ref3=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref2,configKey,increaseCountAction){var dispatch,getState,_appConfig$pushOptIn,appStarts,ordersPlaced,rejectionMaxCount,minDaysBetweenOptIns,_yield$getAppPermissi,_yield$getAppPermissi2,pushStatus,state,configValue,resetAction,resetCountState,configCountState,mustShowModal,hasRepeats,minDaysElapsed;return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:dispatch=_ref2.dispatch,getState=_ref2.getState;_appConfig$pushOptIn=appConfig.pushOptIn,appStarts=_appConfig$pushOptIn.appStarts,ordersPlaced=_appConfig$pushOptIn.ordersPlaced,rejectionMaxCount=_appConfig$pushOptIn.rejectionMaxCount,minDaysBetweenOptIns=_appConfig$pushOptIn.minDaysBetweenOptIns;// TODO add check to determine if the app supports push-opt-in
|
|
10
|
+
_context.next=4;return getAppPermissions([PERMISSION_ID_PUSH]);case 4:_yield$getAppPermissi=_context.sent;_yield$getAppPermissi2=_slicedToArray(_yield$getAppPermissi,1);pushStatus=_yield$getAppPermissi2[0].status;if(!(pushStatus!==PERMISSION_STATUS_NOT_DETERMINED)){_context.next=9;break;}return _context.abrupt("return");case 9:dispatch(increaseCountAction());state=getPushOptInTriggerState(getState());configValue=appStarts;resetAction=resetAppStartCount;resetCountState=state.appStartResetCount;configCountState=state.appStartCount;if(configKey==='ordersPlaced'){configValue=ordersPlaced;resetAction=resetOrdersPlacedCount;resetCountState=state.ordersPlacedResetCount;configCountState=state.ordersPlacedCount;}if(!(state.rejectionCount>=rejectionMaxCount)){_context.next=18;break;}return _context.abrupt("return");case 18:mustShowModal=Number(configValue.value)>0&&configCountState>=configValue.value;hasRepeats=configValue.repeats===null||resetCountState<=configValue.repeats;minDaysElapsed=Date.now()-state.lastPopupAt>=minDaysBetweenOptIns*DAY_IN_MS;if(mustShowModal&&hasRepeats&&minDaysElapsed){dispatch(setLastPopupTimestamp());dispatch(resetAction());dispatch(showOptIn());}case 22:case"end":return _context.stop();}}},_callee);}));return function showOptInAfterChecks(_x,_x2,_x3){return _ref3.apply(this,arguments);};}();// event subscriber to handle app start based push opt in
|
|
11
|
+
subscribe(appDidStart$,/*#__PURE__*/function(){var _ref5=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref4){var dispatch,getState;return _regeneratorRuntime.wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:dispatch=_ref4.dispatch,getState=_ref4.getState;_context2.next=3;return showOptInAfterChecks({dispatch:dispatch,getState:getState},'appStarts',increaseAppStartCount);case 3:case"end":return _context2.stop();}}},_callee2);}));return function(_x4){return _ref5.apply(this,arguments);};}());// event subscriber to handle order based push opt in
|
|
12
|
+
subscribe(appDidStart$,function(_ref6){var dispatch=_ref6.dispatch,getState=_ref6.getState;event.addCallback('checkoutSuccess',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(){return _regeneratorRuntime.wrap(function _callee3$(_context3){while(1){switch(_context3.prev=_context3.next){case 0:_context3.next=2;return showOptInAfterChecks({dispatch:dispatch,getState:getState},'ordersPlaced',increaseOrdersPlacedCount);case 2:case"end":return _context3.stop();}}},_callee3);})));});subscribe(increaseRejectionCount$,function(_ref8){var dispatch=_ref8.dispatch;dispatch(increaseRejectionCount());});}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}import _regeneratorRuntime from"@babel/runtime/regenerator";function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_unsupportedIterableToArray(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}function _unsupportedIterableToArray(o,minLen){if(!o)return;if(typeof o==="string")return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(o);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(o,minLen);}function _arrayLikeToArray(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++){arr2[i]=arr[i];}return arr2;}function _iterableToArrayLimit(arr,i){var _i=arr==null?null:typeof Symbol!=="undefined"&&arr[Symbol.iterator]||arr["@@iterator"];if(_i==null)return;var _arr=[];var _n=true;var _d=false;var _s,_e;try{for(_i=_i.call(arr);!(_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;}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{combineReducers}from'redux';import merge from'lodash/merge';import{createMockStore}from'@shopgate/pwa-common/store';import{event,getAppPermissions,PERMISSION_ID_PUSH,PERMISSION_STATUS_DENIED,APP_DID_START}from'@shopgate/engage/core';import{increaseAppStartCount,setLastPopupTimestamp,resetAppStartCount,increaseRejectionCount,increaseOrdersPlacedCount,resetOrdersPlacedCount,optInPostponed}from"../action-creators";import{showOptIn}from"../actions";import pushReducers from"../reducers";import subscriptions from"./optInTrigger";/**
|
|
2
|
+
* @typedef {Object} MockedConfigSetting
|
|
3
|
+
* @property {number} value
|
|
4
|
+
* @property {number|null} repeats
|
|
5
|
+
*/ /**
|
|
6
|
+
* @typedef {Object} MockedConfig
|
|
7
|
+
* @property {MockedConfigSetting} appStarts
|
|
8
|
+
* @property {MockedConfigSetting} ordersPlaced
|
|
9
|
+
* @property {number} rejectionMaxCount
|
|
10
|
+
* @property {number} minDaysBetweenOptIns
|
|
11
|
+
*/var mockedPushOptInConfig;/**
|
|
12
|
+
* Updates the mocked pushOptIn config with custom values.
|
|
13
|
+
* @param {MockedConfig} update The custom config values
|
|
14
|
+
*/var setMockedConfig=function setMockedConfig(){var update=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};mockedPushOptInConfig=merge({appStarts:{value:1,repeats:null},ordersPlaced:{value:1,repeats:null},rejectionMaxCount:2,minDaysBetweenOptIns:1},update);};jest.mock("../actions/optInTrigger.js",function(){return{showOptIn:jest.fn()};});jest.mock('@shopgate/engage',function(){return{appConfig:{get pushOptIn(){return mockedPushOptInConfig;}}};});jest.mock('@shopgate/engage/core',function(){/* eslint-disable no-shadow */var _jest$requireActual=jest.requireActual('@shopgate/engage/core'),appDidStart$=_jest$requireActual.appDidStart$,main$=_jest$requireActual.main$,PERMISSION_ID_PUSH=_jest$requireActual.PERMISSION_ID_PUSH,PERMISSION_STATUS_NOT_DETERMINED=_jest$requireActual.PERMISSION_STATUS_NOT_DETERMINED,PERMISSION_STATUS_GRANTED=_jest$requireActual.PERMISSION_STATUS_GRANTED,PERMISSION_STATUS_DENIED=_jest$requireActual.PERMISSION_STATUS_DENIED,APP_DID_START=_jest$requireActual.APP_DID_START;/* eslint-enable no-shadow */return{main$:main$,appDidStart$:appDidStart$,PERMISSION_ID_PUSH:PERMISSION_ID_PUSH,PERMISSION_STATUS_NOT_DETERMINED:PERMISSION_STATUS_NOT_DETERMINED,PERMISSION_STATUS_GRANTED:PERMISSION_STATUS_GRANTED,PERMISSION_STATUS_DENIED:PERMISSION_STATUS_DENIED,APP_DID_START:APP_DID_START,getAppPermissions:jest.fn().mockResolvedValue([{status:PERMISSION_STATUS_NOT_DETERMINED}]),event:{addCallback:jest.fn()}};});describe('Push OptIn Subscriptions',function(){var subscribe=jest.fn();var dispatch;var getState;var callbackParams;var mockedTS=new Date('2024-01-31T12:00:00.000Z').getTime();var dateMock;beforeEach(function(){setMockedConfig();jest.clearAllMocks();var store=createMockStore(combineReducers({pushOptIn:pushReducers}),subscriptions);jest.spyOn(store,'dispatch');jest.spyOn(store,'getState');dateMock=jest.spyOn(Date,'now').mockImplementation(function(){return mockedTS;});dispatch=store.dispatch;getState=store.getState;callbackParams={dispatch:dispatch,getState:getState};subscriptions(subscribe);// By default dispatching the showOptIn action results into dispatching the optInPostponed
|
|
15
|
+
// action
|
|
16
|
+
showOptIn.mockImplementation(function(){return function(thunkDispatch){thunkDispatch(optInPostponed());};});});/**
|
|
17
|
+
* Since subscriptions for handling appStarts and ordersPlaced settings share the same logic and
|
|
18
|
+
* just operate on different properties of the related app config, both test blocks are equal
|
|
19
|
+
* can can be executed in a loop.
|
|
20
|
+
*/describe.each(['appStarts','ordersPlaced'])('Counter tests',function(configType){describe("Logic for ".concat(configType),function(){var callback;var eventName;var increaseCountAction;var resetCountAction;beforeEach(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(){var _subscribe$mock$calls,_subscribe$mock$calls2,_subscribe$mock$calls3,_subscribe$mock$calls4,subscribeCallback,_event$addCallback$mo,_event$addCallback$mo2;return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:if(!(configType==='appStarts')){_context.next=8;break;}// Pick the callback of the subscriptions for handling of the appStarts setting
|
|
21
|
+
_subscribe$mock$calls=_slicedToArray(subscribe.mock.calls,1);_subscribe$mock$calls2=_slicedToArray(_subscribe$mock$calls[0],2);callback=_subscribe$mock$calls2[1];increaseCountAction=increaseAppStartCount;resetCountAction=resetAppStartCount;_context.next=18;break;case 8:if(!(configType==='ordersPlaced')){_context.next=18;break;}// Pick the callback of the subscriptions for handling of the ordersPlaced setting
|
|
22
|
+
_subscribe$mock$calls3=_slicedToArray(subscribe.mock.calls,2),_subscribe$mock$calls4=_slicedToArray(_subscribe$mock$calls3[1],2),subscribeCallback=_subscribe$mock$calls4[1];// Invoke the callback, so that an event handler for "checkoutSuccess" is registered
|
|
23
|
+
_context.next=12;return subscribeCallback(callbackParams);case 12:_event$addCallback$mo=_slicedToArray(event.addCallback.mock.calls,1);_event$addCallback$mo2=_slicedToArray(_event$addCallback$mo[0],2);eventName=_event$addCallback$mo2[0];callback=_event$addCallback$mo2[1];increaseCountAction=increaseOrdersPlacedCount;resetCountAction=resetOrdersPlacedCount;case 18:case"end":return _context.stop();}}},_callee);})));if(configType==='ordersPlaced'){it('should register for the expected event',function(){expect(eventName).toBe('checkoutSuccess');});}it('should not trigger opt-in when push permission has not status "notDetermined" anymore',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(){return _regeneratorRuntime.wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:setMockedConfig(_defineProperty({},configType,{value:1}));getAppPermissions.mockResolvedValueOnce([{status:PERMISSION_STATUS_DENIED}]);_context2.next=4;return callback(callbackParams);case 4:expect(getAppPermissions).toHaveBeenCalled();expect(getAppPermissions).toHaveBeenCalledWith([PERMISSION_ID_PUSH]);expect(dispatch).not.toHaveBeenCalled();case 7:case"end":return _context2.stop();}}},_callee2);})));it('should not trigger opt-in when config key is set to 0',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(){return _regeneratorRuntime.wrap(function _callee3$(_context3){while(1){switch(_context3.prev=_context3.next){case 0:setMockedConfig(_defineProperty({},configType,{value:0}));_context3.next=3;return callback(callbackParams);case 3:expect(getAppPermissions).toHaveBeenCalled();expect(getAppPermissions).toHaveBeenCalledWith([PERMISSION_ID_PUSH]);expect(dispatch).toHaveBeenCalledTimes(1);expect(dispatch).toHaveBeenCalledWith(increaseCountAction());expect(showOptIn).not.toHaveBeenCalled();case 8:case"end":return _context3.stop();}}},_callee3);})));it('should trigger opt-in at the first counter increase',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(){return _regeneratorRuntime.wrap(function _callee4$(_context4){while(1){switch(_context4.prev=_context4.next){case 0:setMockedConfig(_defineProperty({},configType,{value:1}));_context4.next=3;return callback(callbackParams);case 3:expect(getAppPermissions).toHaveBeenCalled();expect(getAppPermissions).toHaveBeenCalledWith([PERMISSION_ID_PUSH]);expect(dispatch).toHaveBeenCalledTimes(4);expect(dispatch).toHaveBeenCalledWith(increaseCountAction());expect(dispatch).toHaveBeenCalledWith(setLastPopupTimestamp());expect(dispatch).toHaveBeenCalledWith(resetCountAction());expect(showOptIn).toHaveBeenCalledTimes(1);case 10:case"end":return _context4.stop();}}},_callee4);})));it('should trigger opt-in at the 3rd counter increase',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5(){return _regeneratorRuntime.wrap(function _callee5$(_context5){while(1){switch(_context5.prev=_context5.next){case 0:setMockedConfig(_defineProperty({},configType,{value:3}));// 1st counter increase -> do not show opt-in
|
|
24
|
+
_context5.next=3;return callback(callbackParams);case 3:expect(dispatch).toHaveBeenCalledTimes(1);expect(showOptIn).not.toHaveBeenCalled();// 2nd counter increase -> do not show opt-in
|
|
25
|
+
_context5.next=7;return callback(callbackParams);case 7:expect(dispatch).toHaveBeenCalledTimes(2);expect(showOptIn).not.toHaveBeenCalled();// 3rd counter increase -> show opt-in
|
|
26
|
+
_context5.next=11;return callback(callbackParams);case 11:expect(dispatch).toHaveBeenCalledTimes(6);expect(showOptIn).toHaveBeenCalledTimes(1);case 13:case"end":return _context5.stop();}}},_callee5);})));it('should not trigger opt-in again till "minDaysBetweenOptIns" elapsed',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6(){var _setMockedConfig5;return _regeneratorRuntime.wrap(function _callee6$(_context6){while(1){switch(_context6.prev=_context6.next){case 0:setMockedConfig((_setMockedConfig5={},_defineProperty(_setMockedConfig5,configType,{value:1}),_defineProperty(_setMockedConfig5,"minDaysBetweenOptIns",1),_setMockedConfig5));// 1st counter increase -> show opt-in
|
|
27
|
+
_context6.next=3;return callback(callbackParams);case 3:expect(showOptIn).toHaveBeenCalledTimes(1);// fast forward time by 1/2 day
|
|
28
|
+
dateMock.mockImplementation(function(){return mockedTS+1000*60*60*12;});// 2nd counter increase -> do not show opt due to min days setting
|
|
29
|
+
_context6.next=7;return callback(callbackParams);case 7:expect(showOptIn).toHaveBeenCalledTimes(1);// 3rd counter increase -> do not show opt due to min days setting
|
|
30
|
+
_context6.next=10;return callback(callbackParams);case 10:expect(showOptIn).toHaveBeenCalledTimes(1);// fast forward time by 1 day
|
|
31
|
+
dateMock.mockImplementation(function(){return mockedTS+1000*60*60*24;});// 4th counter increase -> show opt-in again
|
|
32
|
+
_context6.next=14;return callback(callbackParams);case 14:expect(showOptIn).toHaveBeenCalledTimes(2);case 15:case"end":return _context6.stop();}}},_callee6);})));it('should not trigger opt-in when max rejection count is reached',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee7(){var _setMockedConfig6;return _regeneratorRuntime.wrap(function _callee7$(_context7){while(1){switch(_context7.prev=_context7.next){case 0:setMockedConfig((_setMockedConfig6={},_defineProperty(_setMockedConfig6,configType,{value:1}),_defineProperty(_setMockedConfig6,"minDaysBetweenOptIns",0),_defineProperty(_setMockedConfig6,"rejectionMaxCount",2),_setMockedConfig6));// 1st counter increase -> show opt-in
|
|
33
|
+
_context7.next=3;return callback(callbackParams);case 3:expect(showOptIn).toHaveBeenCalledTimes(1);// 2nd counter increase -> show opt-in
|
|
34
|
+
_context7.next=6;return callback(callbackParams);case 6:expect(showOptIn).toHaveBeenCalledTimes(2);// 3rd counter increase -> no opt-in due to rejection count
|
|
35
|
+
_context7.next=9;return callback(callbackParams);case 9:expect(showOptIn).toHaveBeenCalledTimes(2);case 10:case"end":return _context7.stop();}}},_callee7);})));it('should not trigger opt-in when max repeats are reached',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee8(){var _setMockedConfig7;return _regeneratorRuntime.wrap(function _callee8$(_context8){while(1){switch(_context8.prev=_context8.next){case 0:setMockedConfig((_setMockedConfig7={},_defineProperty(_setMockedConfig7,configType,{value:2,repeats:2}),_defineProperty(_setMockedConfig7,"minDaysBetweenOptIns",0),_defineProperty(_setMockedConfig7,"rejectionMaxCount",4),_setMockedConfig7));_context8.next=3;return callback(callbackParams);case 3:_context8.next=5;return callback(callbackParams);case 5:expect(showOptIn).toHaveBeenCalledTimes(1);_context8.next=8;return callback(callbackParams);case 8:_context8.next=10;return callback(callbackParams);case 10:expect(showOptIn).toHaveBeenCalledTimes(2);_context8.next=13;return callback(callbackParams);case 13:_context8.next=15;return callback(callbackParams);case 15:expect(showOptIn).toHaveBeenCalledTimes(3);_context8.next=18;return callback(callbackParams);case 18:_context8.next=20;return callback(callbackParams);case 20:expect(showOptIn).toHaveBeenCalledTimes(3);case 21:case"end":return _context8.stop();}}},_callee8);})));});});describe('Combined counter tests',function(){var appStartsSubscriberCallback;var ordersPlacedSubscriberCallback;beforeEach(function(){var _subscribe$mock$calls5=_slicedToArray(subscribe.mock.calls,2);var _subscribe$mock$calls6=_slicedToArray(_subscribe$mock$calls5[0],2);appStartsSubscriberCallback=_subscribe$mock$calls6[1];var _subscribe$mock$calls7=_slicedToArray(_subscribe$mock$calls5[1],2);ordersPlacedSubscriberCallback=_subscribe$mock$calls7[1];});it('should trigger opt-in for ordersPlaced when max views for appStarts already exceeded',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee9(){var _event$addCallback$mo3,_event$addCallback$mo4,checkoutSuccessCallback;return _regeneratorRuntime.wrap(function _callee9$(_context9){while(1){switch(_context9.prev=_context9.next){case 0:setMockedConfig({appStarts:{value:1,repeats:2},ordersPlaced:{value:1,repeats:1},minDaysBetweenOptIns:0,rejectionMaxCount:4});// 3 opt-ins can be triggered before opt-in by appStart is exceeded (initial + 2 repeats)
|
|
36
|
+
_context9.next=3;return appStartsSubscriberCallback(callbackParams);case 3:expect(showOptIn).toHaveBeenCalledTimes(1);_context9.next=6;return appStartsSubscriberCallback(callbackParams);case 6:expect(showOptIn).toHaveBeenCalledTimes(2);_context9.next=9;return appStartsSubscriberCallback(callbackParams);case 9:expect(showOptIn).toHaveBeenCalledTimes(3);// Opt-in does't show anymore for 4th app start since repeats exceeded
|
|
37
|
+
_context9.next=12;return appStartsSubscriberCallback(callbackParams);case 12:expect(showOptIn).toHaveBeenCalledTimes(3);ordersPlacedSubscriberCallback(callbackParams);_event$addCallback$mo3=_slicedToArray(event.addCallback.mock.calls,1),_event$addCallback$mo4=_slicedToArray(_event$addCallback$mo3[0],2),checkoutSuccessCallback=_event$addCallback$mo4[1];// Opt-in shows again since max rejection count is not reached yet
|
|
38
|
+
_context9.next=17;return checkoutSuccessCallback();case 17:expect(showOptIn).toHaveBeenCalledTimes(4);// Opt-in doesn't show anymore for the 2nd order placement, since max rejection count exceeded
|
|
39
|
+
_context9.next=20;return checkoutSuccessCallback();case 20:expect(showOptIn).toHaveBeenCalledTimes(4);case 21:case"end":return _context9.stop();}}},_callee9);})));});describe('appDidStart$',function(){it('should run expected logic when appDidStart$ stream emits',function(){setMockedConfig({appStarts:{value:1,repeats:1},ordersPlaced:{value:1,repeats:1},minDaysBetweenOptIns:0});dispatch({type:APP_DID_START});// getAppPermissions should have been called 1st time for appDidStart
|
|
40
|
+
expect(getAppPermissions).toHaveBeenCalledTimes(1);var _event$addCallback$mo5=_slicedToArray(event.addCallback.mock.calls,1),_event$addCallback$mo6=_slicedToArray(_event$addCallback$mo5[0],2),eventName=_event$addCallback$mo6[0],eventCallback=_event$addCallback$mo6[1];expect(eventName).toBe('checkoutSuccess');eventCallback();// getAppPermissions should have been called 2nd time for checkoutSuccess event
|
|
41
|
+
expect(getAppPermissions).toHaveBeenCalledTimes(2);});});describe('increaseRejectionCount$',function(){var callback;beforeEach(function(){var _subscribe$mock$calls8=_slicedToArray(subscribe.mock.calls,3);var _subscribe$mock$calls9=_slicedToArray(_subscribe$mock$calls8[2],2);callback=_subscribe$mock$calls9[1];});it('should dispatch the increaseRejectionCount action when subscription emits',function(){callback(callbackParams);expect(dispatch).toHaveBeenCalledTimes(1);expect(dispatch).toHaveBeenCalledWith(increaseRejectionCount());});});});
|