@shopgate/engage 6.17.0-beta.2 → 6.17.0-rc.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,11 @@
1
- import{INCREASE_REJECTION_COUNT,SET_LAST_POPUP_TIMESTAMP}from"../constants";/**
1
+ import{INCREASE_REJECTION_COUNT,SET_ALREADY_RATED,SET_LAST_POPUP_TIMESTAMP}from"../constants";/**
2
2
  * Sets the last popup timestamp
3
3
  * @return {Object} The dispatched action object.
4
4
  */export var setLastPopupTimestamp=function setLastPopupTimestamp(){return{type: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:INCREASE_REJECTION_COUNT};};
7
+ */export var increaseRejectionCount=function increaseRejectionCount(){return{type:INCREASE_REJECTION_COUNT};};/**
8
+ * Sets the last popup timestamp
9
+ * @param {boolean} to the value to set the rated status
10
+ * @return {Object} The dispatched action object.
11
+ */export var setAlreadyRated=function setAlreadyRated(to){return{type:SET_ALREADY_RATED,to:to};};
@@ -1,11 +1,14 @@
1
- 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{increaseRejectionCount,setLastPopupTimestamp}from"../action-creators/popup";import{generateReviewLink}from"../helpers";import{TIMER_TIMESPAN}from"../constants";import{getAppRatingState}from"../selectors/appRating";var _appConfig$appRating=appConfig.appRating,bId=_appConfig$appRating.bundleId,rejectionLink=_appConfig$appRating.rejectionLink,minTimeBetweenPopups=_appConfig$appRating.minTimeBetweenPopups;/**
1
+ 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{increaseRejectionCount,setAlreadyRated,setLastPopupTimestamp}from"../action-creators/popup";import{generateReviewLink}from"../helpers";import{TIMER_TIMESPAN}from"../constants";import{getAppRatingState}from"../selectors/appRating";var _appConfig$appRating=appConfig.appRating,bId=_appConfig$appRating.bundleId,rejectionLink=_appConfig$appRating.rejectionLink,minDaysBetweenPopups=_appConfig$appRating.minDaysBetweenPopups;/**
2
2
  * shows the actual modal
3
3
  * @param {Function} resetAction the reset action function
4
4
  * @param {Function} increaseAction the function to increase the appropriate counter
5
5
  * @param {boolean} mustShow if the modal must be shown
6
6
  * @param {boolean} hasRepeats if the counters has repeats
7
7
  * @return {(function(*, *): void)|*}
8
- */export function showModal(resetAction,increaseAction,mustShow,hasRepeats){return function(dispatch,getState){if(!mustShow&&hasRepeats&&increaseAction){dispatch(increaseAction());}if(!(mustShow&&hasRepeats)){return;}var state=getAppRatingState(getState());var isMinTimeBetweenPopupsElapsed=Date.now()-state.lastPopupAt>=minTimeBetweenPopups*TIMER_TIMESPAN;if(!isMinTimeBetweenPopupsElapsed){return;}dispatch(resetAction());dispatch(setLastPopupTimestamp());dispatch(showModalAction({confirm:'appRating.yes',dismiss:'appRating.no',title:'appRating.title',message:'appRating.message'})).then(function(confirmed){// user touched yes and we
8
+ */export function showModal(resetAction,increaseAction,mustShow,hasRepeats){return function(dispatch,getState){if(!mustShow&&hasRepeats&&increaseAction){// @INDICATOR
9
+ dispatch(showModalAction({confirm:'appRating.yes',dismiss:'appRating.no',title:'Testing',message:JSON.stringify({mustShow:mustShow,hasRepeats:hasRepeats,increaseAction:increaseAction})}));dispatch(increaseAction());}if(!(mustShow&&hasRepeats)){// @INDICATOR
10
+ dispatch(showModalAction({confirm:'appRating.yes',dismiss:'appRating.no',title:'Testing',message:JSON.stringify({mustShow:mustShow,hasRepeats:hasRepeats})}));return;}var state=getAppRatingState(getState());var isMinDaysBetweenPopupsElapsed=Date.now()-state.lastPopupAt>=minDaysBetweenPopups*TIMER_TIMESPAN;if(!isMinDaysBetweenPopupsElapsed){// @INDICATOR
11
+ dispatch(showModalAction({confirm:'appRating.yes',dismiss:'appRating.no',title:'Testing',message:JSON.stringify({isMinDaysBetweenPopupsElapsed:isMinDaysBetweenPopupsElapsed})}));return;}dispatch(resetAction());dispatch(setLastPopupTimestamp());dispatch(showModalAction({confirm:'appRating.yes',dismiss:'appRating.no',title:'appRating.title',message:'appRating.message'})).then(function(confirmed){// user touched yes and we
9
12
  // redirect to store
10
- if(confirmed){var platform=getPlatform(getState());var link=generateReviewLink(bId[platform],platform);if(!link){return;}historyPush({pathname:link});return;}// user doesn't want to rate
11
- dispatch(increaseRejectionCount());if(rejectionLink){historyPush({pathname:rejectionLink});}});};}
13
+ if(confirmed){var platform=getPlatform(getState());var link=generateReviewLink(bId[platform],platform);if(!link){return;}dispatch(setAlreadyRated(true));dispatch(showModalAction({confirm:'appRating.yes',dismiss:'appRating.no',title:'Testing',message:'set already rated to true'}));dispatch(historyPush({pathname:link}));return;}// user doesn't want to rate
14
+ dispatch(increaseRejectionCount());dispatch(showModalAction({confirm:'appRating.yes',dismiss:'appRating.no',title:'Testing',message:'rejecting'}));if(rejectionLink){dispatch(showModalAction({confirm:'appRating.yes',dismiss:'appRating.no',title:'Testing',message:"rejecting with link ".concat(rejectionLink)}));dispatch(historyPush({pathname:rejectionLink}));}});};}
@@ -1,2 +1,2 @@
1
- export var INCREASE_APP_START_COUNT='INCREASE_APP_START_COUNT';export var RESET_APP_START_COUNT='RESET_APP_START_COUNT';export var RESET_APP_START_STATE='RESET_APP_START_STATE';export var INCREASE_ORDERS_PLACED_COUNT='INCREASE_ORDERS_PLACED_COUNT';export var RESET_ORDERS_PLACED_COUNT='RESET_ORDERS_PLACED_COUNT';export var RESET_ORDERS_PLACED_STATE='RESET_ORDERS_PLACED_STATE';export var INCREASE_TIMER_REPEATS='INCREASE_TIMER_REPEATS';export var SET_TIMER_START_TIME='SET_TIMER_START_TIME';export var SET_LAST_POPUP_TIMESTAMP='SET_LAST_POPUP_TIMESTAMP';export var INCREASE_REJECTION_COUNT='INCREASE_REJECTION_COUNT';// currently the timespan is set to a hour
1
+ export var INCREASE_APP_START_COUNT='INCREASE_APP_START_COUNT';export var RESET_APP_START_COUNT='RESET_APP_START_COUNT';export var RESET_APP_START_STATE='RESET_APP_START_STATE';export var INCREASE_ORDERS_PLACED_COUNT='INCREASE_ORDERS_PLACED_COUNT';export var RESET_ORDERS_PLACED_COUNT='RESET_ORDERS_PLACED_COUNT';export var RESET_ORDERS_PLACED_STATE='RESET_ORDERS_PLACED_STATE';export var INCREASE_TIMER_REPEATS='INCREASE_TIMER_REPEATS';export var SET_TIMER_START_TIME='SET_TIMER_START_TIME';export var SET_LAST_POPUP_TIMESTAMP='SET_LAST_POPUP_TIMESTAMP';export var INCREASE_REJECTION_COUNT='INCREASE_REJECTION_COUNT';export var SET_ALREADY_RATED='SET_ALREADY_RATED';// currently the timespan is set to a minute
2
2
  export var TIMER_TIMESPAN=1000*60;
@@ -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{INCREASE_APP_START_COUNT,RESET_APP_START_STATE,RESET_APP_START_COUNT,INCREASE_ORDERS_PLACED_COUNT,RESET_ORDERS_PLACED_COUNT,RESET_ORDERS_PLACED_STATE,INCREASE_TIMER_REPEATS,SET_TIMER_START_TIME,SET_LAST_POPUP_TIMESTAMP,INCREASE_REJECTION_COUNT}from"../constants";var defaultState={appStartCount:0,appStartResetCount:0,ordersPlacedCount:0,ordersPlacedResetCount:0,timerRepeatsCount:0,timerStartTimestamp:null,lastPopupAt:null,rejectionCount:0};/**
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{INCREASE_APP_START_COUNT,RESET_APP_START_STATE,RESET_APP_START_COUNT,INCREASE_ORDERS_PLACED_COUNT,RESET_ORDERS_PLACED_COUNT,RESET_ORDERS_PLACED_STATE,INCREASE_TIMER_REPEATS,SET_TIMER_START_TIME,SET_LAST_POPUP_TIMESTAMP,INCREASE_REJECTION_COUNT,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 INCREASE_APP_START_COUNT:{return _extends({},state,{appStartCount:state.appStartCount+1});}case RESET_APP_START_COUNT:{return _extends({},state,{appStartCount:0,appStartResetCount:state.appStartResetCount+1});}case RESET_APP_START_STATE:{return _extends({},state,{appStartCount:0,appStartResetCount:0});}case INCREASE_ORDERS_PLACED_COUNT:{return _extends({},state,{ordersPlacedCount:state.ordersPlacedCount+1});}case RESET_ORDERS_PLACED_COUNT:{return _extends({},state,{ordersPlacedCount:0,ordersPlacedResetCount:state.ordersPlacedResetCount+1});}case RESET_ORDERS_PLACED_STATE:{return _extends({},state,{ordersPlacedCount:0,ordersPlacedResetCount:0});}case INCREASE_TIMER_REPEATS:{return _extends({},state,{timerRepeatsCount:state.timerRepeatsCount+1});}case SET_TIMER_START_TIME:{return _extends({},state,{timerStartTimestamp:Date.now()});}case SET_LAST_POPUP_TIMESTAMP:{return _extends({},state,{lastPopupAt:Date.now()});}case INCREASE_REJECTION_COUNT:{return _extends({},state,{rejectionCount:state.rejectionCount+1});}default:return 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 INCREASE_APP_START_COUNT:{return _extends({},state,{appStartCount:state.appStartCount+1});}case RESET_APP_START_COUNT:{return _extends({},state,{appStartCount:0,appStartResetCount:state.appStartResetCount+1});}case RESET_APP_START_STATE:{return _extends({},state,{appStartCount:0,appStartResetCount:0});}case INCREASE_ORDERS_PLACED_COUNT:{return _extends({},state,{ordersPlacedCount:state.ordersPlacedCount+1});}case RESET_ORDERS_PLACED_COUNT:{return _extends({},state,{ordersPlacedCount:0,ordersPlacedResetCount:state.ordersPlacedResetCount+1});}case RESET_ORDERS_PLACED_STATE:{return _extends({},state,{ordersPlacedCount:0,ordersPlacedResetCount:0});}case INCREASE_TIMER_REPEATS:{return _extends({},state,{timerRepeatsCount:state.timerRepeatsCount+1});}case SET_TIMER_START_TIME:{return _extends({},state,{timerStartTimestamp:Date.now()});}case SET_LAST_POPUP_TIMESTAMP:{return _extends({},state,{lastPopupAt:Date.now()});}case INCREASE_REJECTION_COUNT:{return _extends({},state,{rejectionCount:state.rejectionCount+1});}case SET_ALREADY_RATED:{return _extends({},state,{alreadyRated:action.to});}default:return state;}});
@@ -1,20 +1,26 @@
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{TIMER_TIMESPAN}from"../constants";import{getAppRatingState}from"../selectors/appRating";import{showModal}from"../actions/showModal";/**
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 showModalAction from'@shopgate/pwa-common/actions/modal/showModal';import{increaseAppStartCount,resetAppStartCount}from"../action-creators/appStart";import{increaseOrdersPlacedCount,resetOrdersPlacedCount}from"../action-creators/ordersPlaced";import{resetTimerState,setTimerStartTime}from"../action-creators/timer";import{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;// even subscriber to handle app start ratings
5
5
  // and also time interval ratings
6
6
  subscribe(appDidStart$,/*#__PURE__*/function(){var _ref2=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref){var dispatch,getState,state,mustShowModal,hasRepeats,resetAction,increaseAction;return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:dispatch=_ref.dispatch,getState=_ref.getState;// every time the app starts
7
7
  // we increase the start count
8
- dispatch(increaseAppStartCount());state=getAppRatingState(getState());// cancel the process if user has
9
- // already rejected rating the app
10
- // many times before
11
- if(!(state.rejectionCount>=rejectionMaxCount)){_context.next=5;break;}return _context.abrupt("return");case 5:// initiate the first start time
12
- if(state.timerStartTimestamp===null){dispatch(setTimerStartTime());}if(Number(state.timerStartTimestamp)>0&&Date.now()-state.timerStartTimestamp>=timeInterval.value*TIMER_TIMESPAN){mustShowModal=true;hasRepeats=timeInterval.repeats===null||state.timerRepeatsCount<timeInterval.repeats;resetAction=resetTimerState;// since the time is elapsed
8
+ dispatch(increaseAppStartCount());state=getAppRatingState(getState());dispatch(showModalAction({confirm:'Yes',dismiss:'Maybe',title:'Testing',message:JSON.stringify(state)}));// if the user has already rated the app
9
+ // we'll cancel the operations as we
10
+ // don't have to show the modal once more
11
+ if(!state.alreadyRated){_context.next=7;break;}// @INDICATOR
12
+ dispatch(showModalAction({confirm:'Yes',dismiss:'Maybe',title:'Testing',message:JSON.stringify({msg:'already rated'})}));return _context.abrupt("return");case 7:if(!(state.rejectionCount>=rejectionMaxCount)){_context.next=10;break;}// @INDICATOR
13
+ dispatch(showModalAction({confirm:'Yes',dismiss:'Maybe',title:'Testing',message:JSON.stringify({rejectionCount:state.rejectionCount,rejectionMaxCount:rejectionMaxCount})}));return _context.abrupt("return");case 10:// initiate the first start time
14
+ 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*TIMER_TIMESPAN){mustShowModal=true;hasRepeats=timeInterval.repeats===null||state.timerRepeatsCount<=timeInterval.repeats;resetAction=resetTimerState;// since the time is elapsed
13
15
  // we reset the starting time
14
- increaseAction=setTimerStartTime;}else{mustShowModal=state.appStartCount>=appStarts.value;hasRepeats=appStarts.repeats===null||state.appStartResetCount<appStarts.repeats;resetAction=resetAppStartCount;increaseAction=null;}// the actual show modal logic
15
- dispatch(showModal(resetAction,increaseAction,mustShowModal,hasRepeats));case 8:case"end":return _context.stop();}}},_callee);}));return function(_x){return _ref2.apply(this,arguments);};}());// event subscriber to handle order placed ratings
16
- subscribe(appDidStart$,function(_ref3){var dispatch=_ref3.dispatch,getState=_ref3.getState;event.addCallback('checkoutSuccess',function(){var state=getAppRatingState(getState());// cancel the process if user has
16
+ 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;}// @INDICATOR
17
+ dispatch(showModalAction({confirm:'Yes',dismiss:'Maybe',title:'Testing',message:JSON.stringify({resetAction:resetAction,increaseAction:increaseAction})}));// the actual show modal logic
18
+ dispatch(showModal(resetAction,increaseAction,mustShowModal,hasRepeats));case 18:case"end":return _context.stop();}}},_callee);}));return function(_x){return _ref2.apply(this,arguments);};}());// event subscriber to handle order placed ratings
19
+ subscribe(appDidStart$,function(_ref3){var dispatch=_ref3.dispatch,getState=_ref3.getState;event.addCallback('checkoutSuccess',function(){var state=getAppRatingState(getState());// if the user has already rated the app
20
+ // we'll cancel the operations as we
21
+ // don't have to show the modal once more
22
+ if(state.alreadyRated){dispatch(showModalAction({confirm:'Yes',dismiss:'Maybe',title:'Testing',message:JSON.stringify({msg:'already rated'})}));return;}// cancel the process if user has
17
23
  // already rejected rating the app
18
24
  // many times before
19
- if(state.rejectionCount>=rejectionMaxCount){return;}// orders placed count starts from 0
25
+ if(state.rejectionCount>=rejectionMaxCount){dispatch(showModalAction({confirm:'Yes',dismiss:'Maybe',title:'Testing',message:JSON.stringify({rejectionCount:state.rejectionCount,rejectionMaxCount:rejectionMaxCount})}));return;}// orders placed count starts from 0
20
26
  var mustShowModal=state.ordersPlacedCount===ordersPlaced.value-1;var hasRepeats=ordersPlaced.repeats===null||state.ordersPlacedResetCount<ordersPlaced.repeats;dispatch(showModal(resetOrdersPlacedCount,increaseOrdersPlacedCount,mustShowModal,hasRepeats));});});}
@@ -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);}function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance");}function _iterableToArrayLimit(arr,i){var _arr=[];var _n=true;var _d=false;var _e=undefined;try{for(var _i=arr[Symbol.iterator](),_s;!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break;}}catch(err){_d=true;_e=err;}finally{try{if(!_n&&_i["return"]!=null)_i["return"]();}finally{if(_d)throw _e;}}return _arr;}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr;}import React,{useState,useCallback,useEffect}from'react';import PropTypes from'prop-types';import{viewScroll$}from'@shopgate/pwa-common/streams/view';import{scrolledIn,scrolledOut}from"./style";/**
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);}function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance");}function _iterableToArrayLimit(arr,i){var _arr=[];var _n=true;var _d=false;var _e=undefined;try{for(var _i=arr[Symbol.iterator](),_s;!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break;}}catch(err){_d=true;_e=err;}finally{try{if(!_n&&_i["return"]!=null)_i["return"]();}finally{if(_d)throw _e;}}return _arr;}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr;}import React,{useState,useCallback,useEffect}from'react';import PropTypes from'prop-types';import{viewScroll$}from'@shopgate/pwa-common/streams/view';import{scrolledIn,scrolledOut,transition}from"./style";/**
2
2
  * Scroll Header component
3
3
  * @param {Object} props props
4
4
  * @returns {JSX}
5
5
  *
6
- */function ScrollHeader(_ref){var children=_ref.children,hideOnScroll=_ref.hideOnScroll,scrollOffset=_ref.scrollOffset;var _useState=useState(false),_useState2=_slicedToArray(_useState,2),shouldHideHeader=_useState2[0],setShouldHideHeader=_useState2[1];var onScroll=useCallback(function(scrollEvent){var scrollTop=scrollEvent.scrollTop,scrolled=scrollEvent.scrolled,scrollOut=scrollEvent.scrollOut,scrollIn=scrollEvent.scrollIn;if(scrolled){if(!shouldHideHeader&&scrollOut&&scrollTop>=scrollOffset){setShouldHideHeader(true);}if(shouldHideHeader&&scrollIn){setShouldHideHeader(false);}}},[scrollOffset,shouldHideHeader]);useEffect(function(){if(hideOnScroll){var subscription=viewScroll$.subscribe(onScroll);return function(){return subscription.unsubscribe();};}return undefined;});var className=shouldHideHeader?scrolledOut:scrolledIn;return React.cloneElement(children,_extends({},children.props,{className:"".concat(children.props.className.toString()," ").concat(className)}));}ScrollHeader.defaultProps={hideOnScroll:true,scrollOffset:100};export default ScrollHeader;
6
+ */function ScrollHeader(_ref){var children=_ref.children,hideOnScroll=_ref.hideOnScroll,scrollOffset=_ref.scrollOffset;var _useState=useState(false),_useState2=_slicedToArray(_useState,2),shouldHideHeader=_useState2[0],setShouldHideHeader=_useState2[1];var onScroll=useCallback(function(scrollEvent){var scrollTop=scrollEvent.scrollTop,scrolled=scrollEvent.scrolled,scrollOut=scrollEvent.scrollOut,scrollIn=scrollEvent.scrollIn;if(scrolled){if(!shouldHideHeader&&scrollOut&&scrollTop>=scrollOffset){setShouldHideHeader(true);}if(shouldHideHeader&&scrollIn){setShouldHideHeader(false);}}},[scrollOffset,shouldHideHeader]);useEffect(function(){if(hideOnScroll){var subscription=viewScroll$.subscribe(onScroll);return function(){return subscription.unsubscribe();};}return undefined;});var className=shouldHideHeader?scrolledOut:scrolledIn;return React.cloneElement(children,_extends({},children.props,{className:"".concat(children.props.className.toString()," ").concat(className," ").concat(transition)}));}ScrollHeader.defaultProps={hideOnScroll:true,scrollOffset:100};export default ScrollHeader;
@@ -1 +1 @@
1
- import{css}from'glamor';var fadeOut=css.keyframes({'0%':{opacity:1},'99%':{opacity:0.01,top:0},'100%':{opacity:0,top:'-20%'}});var fadeIn=css.keyframes({'0%':{opacity:0,top:'-20%'},'1%':{opacity:0.01,top:0},'100%':{opacity:1,top:0}});export var scrolledIn=css({'&&':{animation:"".concat(fadeIn," .2s"),animationFillMode:'forwards'}}).toString();export var scrolledOut=css({'&&':{animation:"".concat(fadeOut," .2s"),animationFillMode:'forwards'}}).toString();
1
+ import{css}from'glamor';export var scrolledIn=css({'&&':{transform:'translateY(0%)'}}).toString();export var scrolledOut=css({'&&':{transform:'translateY(-250%)'}}).toString();export var transition=css({transition:'transform 0.2s ease,transform 0.2s'});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopgate/engage",
3
- "version": "6.17.0-beta.2",
3
+ "version": "6.17.0-rc.4",
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.17.0-beta.2",
19
- "@shopgate/pwa-common-commerce": "6.17.0-beta.2",
20
- "@shopgate/pwa-core": "6.17.0-beta.2",
21
- "@shopgate/pwa-ui-ios": "6.17.0-beta.2",
22
- "@shopgate/pwa-ui-material": "6.17.0-beta.2",
23
- "@shopgate/pwa-ui-shared": "6.17.0-beta.2",
18
+ "@shopgate/pwa-common": "6.17.0-rc.4",
19
+ "@shopgate/pwa-common-commerce": "6.17.0-rc.4",
20
+ "@shopgate/pwa-core": "6.17.0-rc.4",
21
+ "@shopgate/pwa-ui-ios": "6.17.0-rc.4",
22
+ "@shopgate/pwa-ui-material": "6.17.0-rc.4",
23
+ "@shopgate/pwa-ui-shared": "6.17.0-rc.4",
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,5 +1,9 @@
1
- import React,{useContext,useMemo}from'react';import PropTypes from'prop-types';import{css}from'glamor';import classNames from'classnames';import{SurroundPortals}from'@shopgate/engage/components';import{themeConfig}from'@shopgate/engage';import{PRODUCT_UNIT_QUANTITY_PICKER,ProductContext}from'@shopgate/engage/product';import{withCurrentProduct,useWidgetSettings}from'@shopgate/engage/core';import UnitQuantityPicker from"./UnitQuantityPicker";import connect from"./ProductUnitQuantityPicker.connector";var variables=themeConfig.variables;var styles={root:css({marginBottom:variables.gap.small,marginTop:'0px',justifyContent:'space-evenly'}).toString(),qtyContainer:css({marginBottom:variables.gap.small}).toString(),qtyWrapper:css({width:'100%',padding:'0'}).toString()};/**
1
+ import React,{useContext,useEffect,useMemo}from'react';import PropTypes from'prop-types';import{css}from'glamor';import classNames from'classnames';import{SurroundPortals}from'@shopgate/engage/components';import{themeConfig}from'@shopgate/engage';import{PRODUCT_UNIT_QUANTITY_PICKER,ProductContext}from'@shopgate/engage/product';import{withCurrentProduct,useWidgetSettings}from'@shopgate/engage/core';import UnitQuantityPicker from"./UnitQuantityPicker";import connect from"./ProductUnitQuantityPicker.connector";var variables=themeConfig.variables;var styles={root:css({marginBottom:variables.gap.small,marginTop:'0px',justifyContent:'space-evenly'}).toString(),qtyContainer:css({marginBottom:variables.gap.small}).toString(),qtyWrapper:css({width:'100%',padding:'0'}).toString()};/**
2
2
  * Renders the quantity picker enriched with current product data.
3
3
  * @param {Object} props Props
4
4
  * @returns {JSX}
5
- */var ProductUnitQuantityPicker=function ProductUnitQuantityPicker(_ref){var children=_ref.children,className=_ref.className,product=_ref.product,disabled=_ref.disabled,stockInfo=_ref.stockInfo;var _ref2=useWidgetSettings('@shopgate/engage/product/components/UnitQuantityPicker')||{},_ref2$show=_ref2.show,show=_ref2$show===void 0?false:_ref2$show;if(!show){return null;}var _useContext=useContext(ProductContext),quantity=_useContext.quantity,setQuantity=_useContext.setQuantity;var _useMemo=useMemo(function(){var min;var max;if(stockInfo){if(stockInfo.minOrderQuantity>0){min=stockInfo.minOrderQuantity;}if(stockInfo.maxOrderQuantity>0){max=stockInfo.maxOrderQuantity;}}return{minValue:min,maxValue:max};},[stockInfo]),minValue=_useMemo.minValue,maxValue=_useMemo.maxValue;if(!product){return null;}var unit=product.unit,hasCatchWeight=product.hasCatchWeight;var hasUnitWithDecimals=unit&&hasCatchWeight||false;return React.createElement(SurroundPortals,{portalName:PRODUCT_UNIT_QUANTITY_PICKER},React.createElement("div",{className:classNames(styles.root,className)},React.createElement("div",{className:styles.qtyWrapper},React.createElement(UnitQuantityPicker,{className:styles.qtyContainer,unit:hasUnitWithDecimals?unit:null,maxDecimals:hasUnitWithDecimals?2:0,incrementStep:hasUnitWithDecimals?0.25:1,decrementStep:hasUnitWithDecimals?0.25:1,onChange:setQuantity,value:quantity,disabled:disabled,minValue:minValue,maxValue:maxValue})),children&&React.createElement("div",null,children)));};ProductUnitQuantityPicker.defaultProps={disabled:false,product:null,stockInfo:null,children:null,className:null};export default withCurrentProduct(connect(ProductUnitQuantityPicker));
5
+ */var ProductUnitQuantityPicker=function ProductUnitQuantityPicker(_ref){var children=_ref.children,className=_ref.className,product=_ref.product,disabled=_ref.disabled,stockInfo=_ref.stockInfo;var _ref2=useWidgetSettings('@shopgate/engage/product/components/UnitQuantityPicker')||{},_ref2$show=_ref2.show,show=_ref2$show===void 0?false:_ref2$show;if(!show){return null;}var _useContext=useContext(ProductContext),quantity=_useContext.quantity,setQuantity=_useContext.setQuantity;var _useMemo=useMemo(function(){var min;var max;if(stockInfo){if(stockInfo.minOrderQuantity>0){min=stockInfo.minOrderQuantity;}if(stockInfo.maxOrderQuantity>0){max=stockInfo.maxOrderQuantity;}}return{minValue:min,maxValue:max};},[stockInfo]),minValue=_useMemo.minValue,maxValue=_useMemo.maxValue;/**
6
+ * Validates an value based on minValue & maxValue and corrects it if necessary
7
+ * @param {number} val The value to be tested / adjusted
8
+ * @returns {number}
9
+ */var validateQuantity=function validateQuantity(val){if(minValue&&val<minValue)return minValue;if(maxValue&&val>maxValue)return maxValue;return val;};useEffect(function(){var validatedQuantity=validateQuantity(quantity);if(validatedQuantity!==quantity){setQuantity(validatedQuantity);}},[quantity,minValue,maxValue,validateQuantity,setQuantity]);if(!product){return null;}var unit=product.unit,hasCatchWeight=product.hasCatchWeight;var hasUnitWithDecimals=unit&&hasCatchWeight||false;return React.createElement(SurroundPortals,{portalName:PRODUCT_UNIT_QUANTITY_PICKER},React.createElement("div",{className:classNames(styles.root,className)},React.createElement("div",{className:styles.qtyWrapper},React.createElement(UnitQuantityPicker,{className:styles.qtyContainer,unit:hasUnitWithDecimals?unit:null,maxDecimals:hasUnitWithDecimals?2:0,incrementStep:hasUnitWithDecimals?0.25:1,decrementStep:hasUnitWithDecimals?0.25:1,onChange:setQuantity,value:quantity,disabled:disabled,minValue:minValue,maxValue:maxValue})),children&&React.createElement("div",null,children)));};ProductUnitQuantityPicker.defaultProps={disabled:false,product:null,stockInfo:null,children:null,className:null};export default withCurrentProduct(connect(ProductUnitQuantityPicker));