@ikas/loyalty-widget-renderer 1.0.0-alpha.36 → 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.
@@ -1 +1 @@
1
- import{__assign as e}from'./../ext/tslib/tslib.es6.mjs.js';import{makeObservable as t,observable as i,computed as s}from"mobx";import{LoyaltyWidget as r}from"./loyalty-widget/index.js";import{WidgetMode as o,LoyaltyWidgetScreenTypeEnum as n}from"./types/index.js";import{LoyaltyProgramSpendingMethod as d}from"./loyalty-program-spending-method/index.js";import{LoyaltyProgramEarningMethod as h}from"./loyalty-program-earning-method/index.js";import{LoyaltyCustomerInfo as c}from"./loyalty-customer-info/index.js";var a=function(){function a(a,l,g,p,u,M,y,m){void 0===a&&(a={}),this.userRefreshTrigger=0,this.cartRefreshTrigger=0,this.selectedScreen=a.selectedScreen||n.MAIN_SCREEN,this.currentWidgetMode=y?o.WIDGET_MODE:o.MINI_MODE,this.isMiniModeDescriptionClosed=a.isMiniModeDescriptionClosed||!1,this.isLoading=a.isLoading||!1,this.loyaltyWidget=a.loyaltyWidget instanceof r?a.loyaltyWidget:new r(a.loyaltyWidget),this.cdnURL=l,this.merchantId=g,this.storeUrl=M||a.storeUrl||"",this.currency=p,this.locale=u,this.isPreviewMode=y||!1,this.cartId=a.cartId||null,this.cartId=a.cartId||null,this.ikasEventUser=a.ikasEventUser||null,this.user=a.user?new c(a.user):null,this.earningMethods=a.earningMethods?a.earningMethods.map(function(e){return new h(e)}):[],this.spendingMethods=a.spendingMethods?a.spendingMethods.map(function(e){return new d(e)}):[],this.tiers=a.tiers?a.tiers:[],this.categories=a.categories?a.categories:[],this.products=a.products?a.products:[],this.brands=a.brands?a.brands:[],this.tags=a.tags?a.tags:[],this.pointHistory=a.pointHistory?a.pointHistory:[],this.callbacks=m||void 0,t(this,e(e({cartId:i},y?{}:{loyaltyWidget:i}),{isLoading:i,cdnURL:i,merchantId:i,storeUrl:i,currency:i,locale:i,selectedScreen:i,currentWidgetMode:i,isMiniModeDescriptionClosed:i,user:i,earningMethods:i,spendingMethods:i,tiers:i,categories:i,products:i,brands:i,tags:i,pointHistory:i,ikasEventUser:i,userRefreshTrigger:i,cartRefreshTrigger:i,shouldShowSpendingMethods:s}))}return Object.defineProperty(a.prototype,"shouldShowSpendingMethods",{get:function(){return!!this.user&&(!!this.user.customerTierId&&(!(this.user.totalPoint<=0)&&0!==this.spendingMethods.length))},enumerable:!1,configurable:!0}),a.prototype.setWidgetMode=function(e){this.currentWidgetMode=e,e!==o.WIDGET_MODE||this.isPreviewMode||(this.isMiniModeDescriptionClosed=!0)},a.prototype.closeMiniModeDescription=function(){this.isMiniModeDescriptionClosed=!0},a}();export{a as LoyaltyWidgetViewModel};
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};
@@ -1 +1 @@
1
- import e,{useState as t}from"react";import{observer as n}from"mobx-react";import l from"../button/index.js";import{CheckCircleFill as i}from"../../../assets/icons/check-circle-fill.js";import{ChevronLeft as r}from"../../../assets/icons/chevron-left.js";import{Container as o,Header as c,IconWrapper as a,Content as m,Title as s,Description as d,ArrowButton as p,AccordionWrapper as u,AccordionInner as f}from"./style.js";var E=n(function(n){var E=n.title,x=n.description,g=n.icon,$=n.action,b=n.isCompleted,v=n.mode,y=n.children,C=n.padding,k=n.settings,j=t(!1),h=j[0],O=j[1],S=!b&&(null==$?void 0:$.text)&&(null==$?void 0:$.onClick);return e.createElement(o,{$borderRadius:k.borderRadius,$isCompleted:b,$padding:C},e.createElement(c,{onClick:function(){"accordion"===v&&O(!h)},style:{cursor:"accordion"===v?"pointer":"default"}},e.createElement(a,{$iconType:k.widgetIconType},g),e.createElement(m,null,e.createElement(s,null,E),e.createElement(d,null,x)),"card"===v?e.createElement("div",{style:{display:"flex",alignItems:"center",gap:"8px"}},b&&e.createElement(i,null),S&&e.createElement(l,{button:k.button,paddingSize:"small",fontSize:"textSMMedium",onClick:$.onClick},$.text)):e.createElement(p,{$isOpen:h},e.createElement(r,null))),"accordion"===v&&e.createElement(u,{$isOpen:h},e.createElement(f,{$isOpen:h},y)))});export{E as default};
1
+ import e,{useState as t}from"react";import{observer as n}from"mobx-react";import{WidgetIconTypeEnum as i}from"../../../models/loyalty-widget/types/index.js";import l from"../button/index.js";import{CheckCircleFill as o}from"../../../assets/icons/check-circle-fill.js";import{ChevronLeft as r}from"../../../assets/icons/chevron-left.js";import{Container as c,Header as a,IconWrapper as m,Content as s,Title as d,Description as p,ArrowButton as u,AccordionWrapper as f,AccordionInner as E}from"./style.js";var y=n(function(n){var y=n.title,g=n.description,x=n.icon,$=n.action,b=n.isCompleted,v=n.mode,C=n.children,j=n.padding,k=n.settings,O=t(!1),h=O[0],w=O[1],I=!b&&(null==$?void 0:$.text)&&(null==$?void 0:$.onClick);return e.createElement(c,{$borderRadius:k.borderRadius,$isCompleted:b,$padding:j},e.createElement(a,{onClick:function(){"accordion"===v&&w(!h)},style:{cursor:"accordion"===v?"pointer":"default"}},k.widgetIconType!==i.NONE&&e.createElement(m,{$iconType:k.widgetIconType},x),e.createElement(s,null,e.createElement(d,null,y),e.createElement(p,null,g)),"card"===v?e.createElement("div",{style:{display:"flex",alignItems:"center",gap:"8px"}},b&&e.createElement(o,null),I&&e.createElement(l,{button:k.button,paddingSize:"small",fontSize:"textSMMedium",onClick:$.onClick},$.text)):e.createElement(u,{$isOpen:h},e.createElement(r,null))),"accordion"===v&&e.createElement(f,{$isOpen:h},e.createElement(E,{$isOpen:h},C)))});export{y as default};
@@ -1 +1 @@
1
- import{__awaiter as e,__generator as t,__spreadArray as n}from'./../ext/tslib/tslib.es6.mjs.js';import o,{useState as r,useRef as i,useEffect as s}from"react";import{observer as c}from"mobx-react";import'./../ext/react-i18next/dist/es/context.js';import{I18nextProvider as l}from'./../ext/react-i18next/dist/es/I18nextProvider.js';import a 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 g}from"../models/loyalty-widget/types/index.js";import y from"./screens/main-screen/index.js";import p from"./screens/credit-spending-methods-screen/index.js";import T from"./screens/credit-earning-methods-screen/index.js";import h from"./screens/credit-history-screen/index.js";import R from"./screens/loyalty-level-screen/index.js";import C from"./components/mini-mode-button/index.js";import I from"./components/mini-mode-description/index.js";import{LoyaltyWidgetViewModel as M}from"../models/index.js";import{LoyaltyWidget as w}from"../models/loyalty-widget/index.js";import{LoyaltyProgramSpendingMethod as _}from"../models/loyalty-program-spending-method/index.js";import{LoyaltyCustomerInfo as b}from"../models/loyalty-customer-info/index.js";import{LoyaltyProgramEarningMethod as A}from"../models/loyalty-program-earning-method/index.js";import{LoyaltyProgramPointHistory as k}from"../models/loyalty-program-point-history/index.js";import{Container as S,MiniModeWrapper as O,Panel as N,ScreenWrapper as D}from"./style.js";var L=c(function(c){var L,P,x=c.config,j=r(function(){var e=x||window.ikasLoyaltyWidgetConfig;return new M({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=i(!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,o,r,i,s;return t(this,function(t){switch(t.label){case 0:return j.callbacks?(e=new Set,o=new Set,r=new Set,i=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 o.add(e)}):t.type===m.PRODUCT_BRAND?t.idList.forEach(function(e){return r.add(e)}):t.type===m.PRODUCT_TAG&&t.idList.forEach(function(e){return i.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 o.add(e)}):t.type===m.PRODUCT_BRAND?t.idList.forEach(function(e){return r.add(e)}):t.type===m.PRODUCT_TAG&&t.idList.forEach(function(e){return i.add(e)})})}),s=[],e.size>0&&j.callbacks.getProducts&&s.push(j.callbacks.getProducts(Array.from(e)).then(function(e){return j.products=e})),o.size>0&&j.callbacks.getCategories&&s.push(j.callbacks.getCategories(Array.from(o)).then(function(e){return j.categories=e})),r.size>0&&j.callbacks.getBrands&&s.push(j.callbacks.getBrands(Array.from(r)).then(function(e){return j.brands=e})),i.size>0&&j.callbacks.getTags&&s.push(j.callbacks.getTags(Array.from(i)).then(function(e){return j.tags=e})),[4,Promise.all(s)]):[2];case 1:return t.sent(),[2]}})})};s(function(){console.log("*******INITIAL FETCH*******");e(void 0,void 0,void 0,function(){var e,n,o,r,i,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(),o=n[0],r=n[1],i=n[2],console.log(" loyaltyWidget instanceof LoyaltyWidget",o instanceof w),j.loyaltyWidget=o instanceof w?o:new w(o||{}),j.earningMethods=r.map(function(e){return new A(e)}),j.tiers=i||[],[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(console.log("******IKAS EVENTS EFFECT *******"),window.IkasEvents){var e="ikas-loyalty-widget-subscriber";try{window.IkasEvents.subscribe({id:e,callback:function(e){var t,n,o,r=e.type;if(console.log("Listening for Ikas Storefront Events",e),"CUSTOMER_LOGIN"===r){var i=null===(t=e.data)||void 0===t?void 0:t.customer;i&&(j.ikasEventUser=i)}else"CUSTOMER_LOGOUT"===r&&(j.ikasEventUser=null);if("ADD_TO_CART"===r||"REMOVE_FROM_CART"===r){var s=null===(o=null===(n=e.data)||void 0===n?void 0:n.cart)||void 0===o?void 0:o.id;s&&(j.cartId=s),["CUSTOMER_LOGIN","CUSTOMER_LOGOUT"].includes(r)?(j.userRefreshTrigger++,j.cartRefreshTrigger++):["ADD_TO_CART","REMOVE_FROM_CART"].includes(r)&&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(){console.log("*******USER DATA FETCH EFFECT*******");e(void 0,void 0,void 0,function(){var e,n,o,r,i;return t(this,function(t){switch(t.label){case 0:if(!j.callbacks||!(null===(i=j.ikasEventUser)||void 0===i?void 0:i.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],o=e[1],j.user=n?new b(n):null,j.pointHistory=o?o.map(function(e){return new k(e)}):[],[3,4];case 3:return r=t.sent(),console.error("Failed to fetch user data",r),[3,4];case 4:return[2]}})})},[null===(L=j.ikasEventUser)||void 0===L?void 0:L.id,j.userRefreshTrigger]),s(function(){console.log("*******CART DATA FETCH EFFECT*******");e(void 0,void 0,void 0,function(){var e,n;return t(this,function(t){switch(t.label){case 0:if(console.log("fetchCartData",j.cartId),!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 _(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 F=function(e){j.selectedScreen=e},G=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 $=j.selectedScreen===u.MAIN_SCREEN,B=r(null),H=B[0],V=B[1];s(function(){j.selectedScreen!==u.MAIN_SCREEN&&V(j.selectedScreen)},[j.selectedScreen]);var z=$?H:j.selectedScreen,Y=j.loyaltyWidget.settings.position||v.RIGHT,K=j.loyaltyWidget.settings.type||g.DRAWER;return o.createElement(l,{i18n:a},o.createElement(S,{$layoutType:K,$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&&G()}},o.createElement(O,{$isVisible:j.currentWidgetMode===d.MINI_MODE,$widgetPosition:Y},o.createElement(I,{viewModel:j}),o.createElement(C,{viewModel:j})),o.createElement(N,{$layoutType:K,$isOpen:j.currentWidgetMode===d.WIDGET_MODE,$widgetPosition:Y,onClick:function(e){return e.stopPropagation()}},o.createElement(D,{$isActive:$,$isMain:!0},o.createElement(y,{viewModel:j,onClose:G,onNavigate:F})),o.createElement(D,{$isActive:!$,$isMain:!1},function(){switch(z){case u.CREDIT_SPENDING_METHODS_SCREEN:return o.createElement(p,{viewModel:j,onBack:function(){return F(u.MAIN_SCREEN)},onClose:G});case u.CREDIT_EARNING_METHODS_SCREEN:return o.createElement(T,{viewModel:j,onBack:function(){return F(u.MAIN_SCREEN)},onClose:G});case u.CREDIT_HISTORY_SCREEN:return o.createElement(h,{viewModel:j,onBack:function(){return F(u.MAIN_SCREEN)},onClose:G});case u.LOYALTY_LEVEL_SCREEN:return o.createElement(R,{viewModel:j,onBack:function(){return F(u.MAIN_SCREEN)},onClose:G});default:return null}}()))))});export{L as default};
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};
@@ -1 +1 @@
1
- import e from"react";import'./../../../../ext/react-i18next/dist/es/context.js';import{useTranslation as t}from'./../../../../ext/react-i18next/dist/es/useTranslation.js';import{observer as n}from"mobx-react";import{LoyaltyWidgetScreenTypeEnum as r}from"../../../../models/types/index.js";import{WidgetIconTypeEnum as l}from"../../../../models/loyalty-widget/types/index.js";import{Container as o,GridContainer as i,SmallCard as a,SmallCardIconWrapper as s,SmallCardBottom as c,Title as m,ArrowWrapper as u,RowCard as E}from"./style.js";import{getScreenIcon as d}from"../../../../utils.js";var R=function(){return e.createElement("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg"},e.createElement("path",{d:"M7.5 15L12.5 10L7.5 5",stroke:"currentColor",strokeWidth:"1.66667",strokeLinecap:"round",strokeLinejoin:"round"}))},_=n(function(n){var _=n.viewModel,g=n.onNavigate,y=t().t,T=_.user,p=!!T,C=_.loyaltyWidget.settings.widgetIconType;return e.createElement(o,null,e.createElement(i,null,e.createElement(a,{$borderRadius:_.loyaltyWidget.settings.cartBorderRadius,onClick:function(){return null==g?void 0:g(r.CREDIT_EARNING_METHODS_SCREEN)}},e.createElement(s,{$hasBgColor:C===l.ILLUSTRATION,$iconType:C},d(r.CREDIT_EARNING_METHODS_SCREEN,C)),e.createElement(c,null,e.createElement(m,null,y("main_screen.earnPoints")),e.createElement(u,null,e.createElement(R,null)))),e.createElement(a,{$borderRadius:_.loyaltyWidget.settings.cartBorderRadius,onClick:function(){return null==g?void 0:g(r.CREDIT_SPENDING_METHODS_SCREEN)}},e.createElement(s,{$hasBgColor:C===l.ILLUSTRATION,$iconType:C},d(r.CREDIT_SPENDING_METHODS_SCREEN,C)),e.createElement(c,null,e.createElement(m,null,y("main_screen.allRewards")),e.createElement(u,null,e.createElement(R,null))))),p&&e.createElement(e.Fragment,null,(null==T?void 0:T.customerTierId)&&e.createElement(E,{$borderRadius:_.loyaltyWidget.settings.cartBorderRadius,onClick:function(){return null==g?void 0:g(r.LOYALTY_LEVEL_SCREEN)}},e.createElement(m,null,y("main_screen.tiers")),e.createElement(u,null,e.createElement(R,null))),_.pointHistory.length>0&&e.createElement(E,{$borderRadius:_.loyaltyWidget.settings.cartBorderRadius,onClick:function(){return null==g?void 0:g(r.CREDIT_HISTORY_SCREEN)}},e.createElement(m,null,y("main_screen.pointHistory")),e.createElement(u,null,e.createElement(R,null)))))});export{_ as default};
1
+ import e from"react";import'./../../../../ext/react-i18next/dist/es/context.js';import{useTranslation as t}from'./../../../../ext/react-i18next/dist/es/useTranslation.js';import{observer as n}from"mobx-react";import{LoyaltyWidgetScreenTypeEnum as r}from"../../../../models/types/index.js";import{WidgetIconTypeEnum as l}from"../../../../models/loyalty-widget/types/index.js";import{Container as o,GridContainer as i,SmallCard as a,SmallCardIconWrapper as s,SmallCardBottom as c,Title as E,ArrowWrapper as m,RowCard as u}from"./style.js";import{getScreenIcon as d}from"../../../../utils.js";var R=function(){return e.createElement("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg"},e.createElement("path",{d:"M7.5 15L12.5 10L7.5 5",stroke:"currentColor",strokeWidth:"1.66667",strokeLinecap:"round",strokeLinejoin:"round"}))},_=n(function(n){var _=n.viewModel,g=n.onNavigate,N=t().t,y=_.user,T=!!y,p=_.loyaltyWidget.settings.widgetIconType;return e.createElement(o,null,e.createElement(i,null,e.createElement(a,{$borderRadius:_.loyaltyWidget.settings.cartBorderRadius,onClick:function(){return null==g?void 0:g(r.CREDIT_EARNING_METHODS_SCREEN)}},p!==l.NONE&&e.createElement(s,{$hasBgColor:p===l.ILLUSTRATION,$iconType:p},d(r.CREDIT_EARNING_METHODS_SCREEN,p)),e.createElement(c,null,e.createElement(E,null,N("main_screen.earnPoints")),e.createElement(m,null,e.createElement(R,null)))),e.createElement(a,{$borderRadius:_.loyaltyWidget.settings.cartBorderRadius,onClick:function(){return null==g?void 0:g(r.CREDIT_SPENDING_METHODS_SCREEN)}},p!==l.NONE&&e.createElement(s,{$hasBgColor:p===l.ILLUSTRATION,$iconType:p},d(r.CREDIT_SPENDING_METHODS_SCREEN,p)),e.createElement(c,null,e.createElement(E,null,N("main_screen.allRewards")),e.createElement(m,null,e.createElement(R,null))))),T&&e.createElement(e.Fragment,null,(null==y?void 0:y.customerTierId)&&e.createElement(u,{$borderRadius:_.loyaltyWidget.settings.cartBorderRadius,onClick:function(){return null==g?void 0:g(r.LOYALTY_LEVEL_SCREEN)}},e.createElement(E,null,N("main_screen.tiers")),e.createElement(m,null,e.createElement(R,null))),_.pointHistory.length>0&&e.createElement(u,{$borderRadius:_.loyaltyWidget.settings.cartBorderRadius,onClick:function(){return null==g?void 0:g(r.CREDIT_HISTORY_SCREEN)}},e.createElement(E,null,N("main_screen.pointHistory")),e.createElement(m,null,e.createElement(R,null)))))});export{_ as default};