@ikas/loyalty-widget-renderer 1.0.0-alpha.37 → 1.0.0-alpha.38
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/build/models/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{makeObservable as e,observable as t,computed as i}from"mobx";import{LoyaltyWidget as s}from"./loyalty-widget/index.js";import{WidgetMode as r,LoyaltyWidgetScreenTypeEnum as o}from"./types/index.js";import{LoyaltyProgramSpendingMethod as n}from"./loyalty-program-spending-method/index.js";import{LoyaltyProgramEarningMethod as d}from"./loyalty-program-earning-method/index.js";import{LoyaltyCustomerInfo as h}from"./loyalty-customer-info/index.js";var c=function(){function c(c,a,l,g,p,u,M,y){void 0===c&&(c={}),this.userRefreshTrigger=0,this.cartRefreshTrigger=0,this.selectedScreen=c.selectedScreen||o.MAIN_SCREEN,this.currentWidgetMode=M?r.WIDGET_MODE:r.MINI_MODE,this.isMiniModeDescriptionClosed=c.isMiniModeDescriptionClosed||!1,this.isLoading=c.isLoading||!1,this.loyaltyWidget=new s(c.loyaltyWidget),this.cdnURL=a,this.merchantId=l,this.storeUrl=u||c.storeUrl||"",this.currency=g,this.locale=p,this.isPreviewMode=M||!1,this.cartId=c.cartId||null,this.cartId=c.cartId||null,this.ikasEventUser=c.ikasEventUser||null,this.user=c.user?new h(c.user):null,this.earningMethods=c.earningMethods?c.earningMethods.map(function(e){return new d(e)}):[],this.spendingMethods=c.spendingMethods?c.spendingMethods.map(function(e){return new n(e)}):[],this.tiers=c.tiers?c.tiers:[],this.categories=c.categories?c.categories:[],this.products=c.products?c.products:[],this.brands=c.brands?c.brands:[],this.tags=c.tags?c.tags:[],this.pointHistory=c.pointHistory?c.pointHistory:[],this.callbacks=y||void 0,e(this,{cartId:t,loyaltyWidget:t,isLoading:t,cdnURL:t,merchantId:t,storeUrl:t,currency:t,locale:t,selectedScreen:t,currentWidgetMode:t,isMiniModeDescriptionClosed:t,user:t,earningMethods:t,spendingMethods:t,tiers:t,categories:t,products:t,brands:t,tags:t,pointHistory:t,ikasEventUser:t,userRefreshTrigger:t,cartRefreshTrigger:t,shouldShowSpendingMethods:i})}return Object.defineProperty(c.prototype,"shouldShowSpendingMethods",{get:function(){return!!this.user&&(!!this.user.customerTierId&&(!(this.user.totalPoint<=0)&&0!==this.spendingMethods.length))},enumerable:!1,configurable:!0}),c.prototype.setWidgetMode=function(e){this.currentWidgetMode=e,e!==r.WIDGET_MODE||this.isPreviewMode||(this.isMiniModeDescriptionClosed=!0)},c.prototype.closeMiniModeDescription=function(){this.isMiniModeDescriptionClosed=!0},c}();export{c as LoyaltyWidgetViewModel};
|
package/build/renderer/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__awaiter as e,__generator as t,__spreadArray as n}from'./../ext/tslib/tslib.es6.mjs.js';import
|
|
1
|
+
import{__awaiter as e,__generator as t,__spreadArray as n}from'./../ext/tslib/tslib.es6.mjs.js';import r,{useState as i,useRef as o,useEffect as s}from"react";import{observer as c}from"mobx-react";import'./../ext/react-i18next/dist/es/context.js';import{I18nextProvider as a}from'./../ext/react-i18next/dist/es/I18nextProvider.js';import l from"./utils/i18n.js";import{WidgetMode as d,LoyaltyWidgetScreenTypeEnum as u,EarningMethodTypeEnum as f,LoyaltyProgramFilterTypeEnum as m,LoyaltyProgramMethodSpendingTypeEnum as E}from"../models/types/index.js";import{WidgetPositionEnum as v,LoyaltyWidgetLayoutTypeEnum as y}from"../models/loyalty-widget/types/index.js";import g from"./screens/main-screen/index.js";import p from"./screens/credit-spending-methods-screen/index.js";import h from"./screens/credit-earning-methods-screen/index.js";import R from"./screens/credit-history-screen/index.js";import M from"./screens/loyalty-level-screen/index.js";import w from"./components/mini-mode-button/index.js";import T from"./components/mini-mode-description/index.js";import{LoyaltyWidgetViewModel as _}from"../models/index.js";import{LoyaltyWidget as b}from"../models/loyalty-widget/index.js";import{LoyaltyProgramSpendingMethod as C}from"../models/loyalty-program-spending-method/index.js";import{LoyaltyCustomerInfo as I}from"../models/loyalty-customer-info/index.js";import{LoyaltyProgramEarningMethod as k}from"../models/loyalty-program-earning-method/index.js";import{LoyaltyProgramPointHistory as O}from"../models/loyalty-program-point-history/index.js";import{Container as A,MiniModeWrapper as S,Panel as N,ScreenWrapper as D}from"./style.js";var L=c(function(c){var L,P,x=c.config,j=i(function(){var e=x||window.ikasLoyaltyWidgetConfig;return new _({cartId:(null==e?void 0:e.cartId)||null,ikasEventUser:(null==e?void 0:e.userId)?{id:e.userId}:null},(null==e?void 0:e.cdnURL)||"",(null==e?void 0:e.merchantId)||"",(null==e?void 0:e.currency)||"",(null==e?void 0:e.locale)||"",(null==e?void 0:e.storeURL)||null,null==e?void 0:e.isPreviewMode,null==e?void 0:e.callbacks)})[0],U=o(!0);s(function(){var e=x||window.ikasLoyaltyWidgetConfig;(null==e?void 0:e.onViewModelInitialized)&&e.onViewModelInitialized(j)},[j,x]);var W=function(){return e(void 0,void 0,void 0,function(){var e,r,i,o,s;return t(this,function(t){switch(t.label){case 0:return j.callbacks?(e=new Set,r=new Set,i=new Set,o=new Set,j.earningMethods.forEach(function(t){var s,c;t.methodType===f.ORDER_CREATE&&n(n([],(null===(s=t.orderSettings)||void 0===s?void 0:s.productFilters)||[],!0),(null===(c=t.productSettings)||void 0===c?void 0:c.productFilters)||[],!0).forEach(function(t){t.type===m.PRODUCT_AND_VARIANT?t.idList.forEach(function(t){return e.add(t)}):t.type===m.CATEGORY?t.idList.forEach(function(e){return r.add(e)}):t.type===m.PRODUCT_BRAND?t.idList.forEach(function(e){return i.add(e)}):t.type===m.PRODUCT_TAG&&t.idList.forEach(function(e){return o.add(e)})})}),j.spendingMethods&&j.spendingMethods.forEach(function(t){var n,s;t.type===E.FREE_PRODUCT&&(null===(n=t.discountSettings)||void 0===n?void 0:n.freeProductId)&&e.add(t.discountSettings.freeProductId),null===(s=t.productFilters)||void 0===s||s.forEach(function(t){t.type===m.PRODUCT_AND_VARIANT?t.idList.forEach(function(t){return e.add(t)}):t.type===m.CATEGORY?t.idList.forEach(function(e){return r.add(e)}):t.type===m.PRODUCT_BRAND?t.idList.forEach(function(e){return i.add(e)}):t.type===m.PRODUCT_TAG&&t.idList.forEach(function(e){return o.add(e)})})}),s=[],e.size>0&&j.callbacks.getProducts&&s.push(j.callbacks.getProducts(Array.from(e)).then(function(e){return j.products=e})),r.size>0&&j.callbacks.getCategories&&s.push(j.callbacks.getCategories(Array.from(r)).then(function(e){return j.categories=e})),i.size>0&&j.callbacks.getBrands&&s.push(j.callbacks.getBrands(Array.from(i)).then(function(e){return j.brands=e})),o.size>0&&j.callbacks.getTags&&s.push(j.callbacks.getTags(Array.from(o)).then(function(e){return j.tags=e})),[4,Promise.all(s)]):[2];case 1:return t.sent(),[2]}})})};s(function(){e(void 0,void 0,void 0,function(){var e,n,r,i,o,s;return t(this,function(t){switch(t.label){case 0:if(!j.callbacks)return[3,6];t.label=1;case 1:return t.trys.push([1,4,5,6]),e=[j.callbacks.getLoyaltyWidget(),j.callbacks.listEarningMethods(),j.callbacks.listLoyaltyProgramTier({})],[4,Promise.all(e)];case 2:return n=t.sent(),r=n[0],i=n[1],o=n[2],j.loyaltyWidget=r instanceof b?r:new b(r||{}),j.earningMethods=i.map(function(e){return new k(e)}),j.tiers=o||[],[4,W()];case 3:return t.sent(),[3,6];case 4:return s=t.sent(),console.error("Failed to initialize loyalty data",s),[3,6];case 5:return U.current=!1,[7];case 6:return[2]}})})},[]),s(function(){if(window.IkasEvents){var e="ikas-loyalty-widget-subscriber";try{window.IkasEvents.subscribe({id:e,callback:function(e){var t,n,r,i=e.type;if("CUSTOMER_LOGIN"===i){var o=null===(t=e.data)||void 0===t?void 0:t.customer;o&&(j.ikasEventUser=o)}else"CUSTOMER_LOGOUT"===i&&(j.ikasEventUser=null);if("ADD_TO_CART"===i||"REMOVE_FROM_CART"===i){var s=null===(r=null===(n=e.data)||void 0===n?void 0:n.cart)||void 0===r?void 0:r.id;s&&(j.cartId=s),["CUSTOMER_LOGIN","CUSTOMER_LOGOUT"].includes(i)?(j.userRefreshTrigger++,j.cartRefreshTrigger++):["ADD_TO_CART","REMOVE_FROM_CART"].includes(i)&&j.cartRefreshTrigger++}}})}catch(e){console.error("Failed to subscribe to IkasEvents",e)}return function(){var t;(null===(t=window.IkasEvents)||void 0===t?void 0:t.unsubscribe)&&window.IkasEvents.unsubscribe(e)}}},[j]),s(function(){e(void 0,void 0,void 0,function(){var e,n,r,i,o;return t(this,function(t){switch(t.label){case 0:if(!j.callbacks||!(null===(o=j.ikasEventUser)||void 0===o?void 0:o.id))return[3,4];t.label=1;case 1:return t.trys.push([1,3,,4]),[4,Promise.all([j.callbacks.getLoyaltyCustomerInfo(),j.callbacks.listLoyaltyProgramPointHistory({})])];case 2:return e=t.sent(),n=e[0],r=e[1],j.user=n?new I(n):null,j.pointHistory=r?r.map(function(e){return new O(e)}):[],[3,4];case 3:return i=t.sent(),console.error("Failed to fetch user data",i),[3,4];case 4:return[2]}})})},[null===(L=j.ikasEventUser)||void 0===L?void 0:L.id,j.userRefreshTrigger]),s(function(){e(void 0,void 0,void 0,function(){var e,n;return t(this,function(t){switch(t.label){case 0:if(!j.callbacks)return[3,5];t.label=1;case 1:return t.trys.push([1,4,,5]),[4,j.callbacks.listSpendingMethodsByCartId(j.cartId)];case 2:return e=t.sent(),j.spendingMethods=e.map(function(e){return new C(e)}),[4,W()];case 3:return t.sent(),[3,5];case 4:return n=t.sent(),console.error("Failed to fetch cart data",n),[3,5];case 5:return[2]}})})},[j.cartId,j.cartRefreshTrigger]);var G=function(e){j.selectedScreen=e},$=function(){j.setWidgetMode(d.MINI_MODE),setTimeout(function(){j.selectedScreen=u.MAIN_SCREEN},300)};s(function(){return j.currentWidgetMode===d.WIDGET_MODE?document.body.style.overflow="hidden":document.body.style.overflow="",function(){document.body.style.overflow=""}},[j.currentWidgetMode]);var F=j.selectedScreen===u.MAIN_SCREEN,B=i(null),V=B[0],z=B[1];s(function(){j.selectedScreen!==u.MAIN_SCREEN&&z(j.selectedScreen)},[j.selectedScreen]);var H=F?V:j.selectedScreen,Y=j.loyaltyWidget.settings.position||v.RIGHT,q=j.loyaltyWidget.settings.type||y.DRAWER;return r.createElement(a,{i18n:l},r.createElement(A,{$layoutType:q,$widgetPosition:Y,$widgetMode:j.currentWidgetMode,$position:(null==x?void 0:x.position)||(null===(P=window.ikasLoyaltyWidgetConfig)||void 0===P?void 0:P.position)||"fixed",onClick:function(){j.currentWidgetMode===d.WIDGET_MODE&&$()}},r.createElement(S,{$isVisible:j.currentWidgetMode===d.MINI_MODE,$widgetPosition:Y},r.createElement(T,{viewModel:j}),r.createElement(w,{viewModel:j})),r.createElement(N,{$layoutType:q,$isOpen:j.currentWidgetMode===d.WIDGET_MODE,$widgetPosition:Y,onClick:function(e){return e.stopPropagation()}},r.createElement(D,{$isActive:F,$isMain:!0},r.createElement(g,{viewModel:j,onClose:$,onNavigate:G})),r.createElement(D,{$isActive:!F,$isMain:!1},function(){switch(H){case u.CREDIT_SPENDING_METHODS_SCREEN:return r.createElement(p,{viewModel:j,onBack:function(){return G(u.MAIN_SCREEN)},onClose:$});case u.CREDIT_EARNING_METHODS_SCREEN:return r.createElement(h,{viewModel:j,onBack:function(){return G(u.MAIN_SCREEN)},onClose:$});case u.CREDIT_HISTORY_SCREEN:return r.createElement(R,{viewModel:j,onBack:function(){return G(u.MAIN_SCREEN)},onClose:$});case u.LOYALTY_LEVEL_SCREEN:return r.createElement(M,{viewModel:j,onBack:function(){return G(u.MAIN_SCREEN)},onClose:$});default:return null}}()))))});export{L as default};
|