@ikas/loyalty-widget-renderer 1.0.0-alpha.16 → 1.0.0-alpha.17
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 +1 -1
- package/build/renderer/index.js +1 -1
- package/package.json +1 -1
package/build/models/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{makeObservable as t,observable as
|
|
1
|
+
import{makeObservable as t,observable as s}from'./../ext/mobx/dist/mobx.esm.js';import{LoyaltyWidget as e}from"./loyalty-widget/index.js";import{LoyaltyWidgetScreenTypeEnum as i}from"./types/index.js";import{LoyaltyProgramSpendingMethod as r}from"./loyalty-program-spending-method/index.js";import{LoyaltyProgramEarningMethod as o}from"./loyalty-program-earning-method/index.js";import{LoyaltyCustomerInfo as n}from"./loyalty-customer-info/index.js";var d=function(d,a,c,h,l,g){void 0===d&&(d={}),this.selectedScreen=d.selectedScreen||i.MAIN_SCREEN,this.isLoading=d.isLoading||!1,this.loyaltyWidget=d.loyaltyWidget?d.loyaltyWidget:new e,this.cdnURL=a,this.merchantId=c,this.storeUrl=d.storeUrl||"",this.currency=h,this.locale=l,this.cartId=d.cartId||null,this.user=d.user?new n(d.user):null,this.earningMethods=d.earningMethods?d.earningMethods.map(function(t){return new o(t)}):[],this.spendingMethods=d.spendingMethods?d.spendingMethods.map(function(t){return new r(t)}):[],this.tiers=d.tiers?d.tiers:[],this.categories=d.categories?d.categories:[],this.products=d.products?d.products:[],this.brands=d.brands?d.brands:[],this.tags=d.tags?d.tags:[],this.pointHistory=d.pointHistory?d.pointHistory:[],this.callbacks=g||void 0,t(this,{cartId:s,isLoading:s,cdnURL:s,merchantId:s,storeUrl:s,currency:s,locale:s,selectedScreen:s,user:s,earningMethods:s,spendingMethods:s,tiers:s,categories:s,products:s,brands:s,tags:s,pointHistory:s})};export{d 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 r,{useState as o,useRef as i,useEffect as
|
|
1
|
+
import{__awaiter as e,__generator as t,__spreadArray as n}from'./../ext/tslib/tslib.es6.mjs.js';import r,{useState as o,useRef as i,useEffect as c}from"react";import{observer as s}from'./../ext/mobx-react/dist/mobxreact.esm.js';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{LoyaltyWidgetScreenTypeEnum as d,EarningMethodTypeEnum as u,LoyaltyProgramFilterTypeEnum as m,LoyaltyProgramMethodSpendingTypeEnum as f}from"../models/types/index.js";import p from"./screens/main-screen/index.js";import y from"./screens/credit-spending-methods-screen/index.js";import E from"./screens/credit-earning-methods-screen/index.js";import g from"./screens/credit-history-screen/index.js";import h from"./screens/loyalty-level-screen/index.js";import{LoyaltyWidgetViewModel as v}from"../models/index.js";import{LoyaltyWidget as C}from"../models/loyalty-widget/index.js";import{LoyaltyProgramSpendingMethod as b}from"../models/loyalty-program-spending-method/index.js";import{LoyaltyCustomerInfo as R}from"../models/loyalty-customer-info/index.js";import{LoyaltyProgramEarningMethod as I}from"../models/loyalty-program-earning-method/index.js";import{LoyaltyProgramPointHistory as k}from"../models/loyalty-program-point-history/index.js";import{Container as S,Drawer as _,ScreenWrapper as w}from"./style.js";var A=s(function(s){var A,N=s.config,L=o(function(){var e=N||window.ikasLoyaltyWidgetConfig;return new v({cartId:(null==e?void 0:e.cartId)||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.callbacks)})[0],T=i(!0);c(function(){e(void 0,void 0,void 0,function(){var e,r,o,i,c,s,a,l,d,p,y,E,g,h;return t(this,function(t){switch(t.label){case 0:if(!L.callbacks)return[3,6];t.label=1;case 1:return t.trys.push([1,4,5,6]),e=[L.callbacks.getLoyaltyWidget(),L.callbacks.listEarningMethods(),L.callbacks.listLoyaltyProgramTier({includeDeleted:!1})],L.cartId&&(e.push(L.callbacks.listSpendingMethodsByCartId(L.cartId)),e.push(L.callbacks.getLoyaltyCustomerInfo()),e.push(L.callbacks.listLoyaltyProgramPointHistory({}))),[4,Promise.all(e)];case 2:return r=t.sent(),o=r[0],i=r[1],c=r[2],s=[],a=null,l=[],L.cartId&&(s=r[3],a=r[4],l=r[5]),L.loyaltyWidget=new C(o),L.earningMethods=i.map(function(e){return new I(e)}),L.tiers=c||[],L.cartId&&(L.spendingMethods=s.map(function(e){return new b(e)}),L.user=a?new R(a):null,L.pointHistory=l?l.map(function(e){return new k(e)}):[]),d=new Set,p=new Set,y=new Set,E=new Set,L.earningMethods.forEach(function(e){var t,r;e.methodType===u.ORDER_CREATE&&n(n([],(null===(t=e.orderSettings)||void 0===t?void 0:t.productFilters)||[],!0),(null===(r=e.productSettings)||void 0===r?void 0:r.productFilters)||[],!0).forEach(function(e){e.type===m.PRODUCT_AND_VARIANT?e.idList.forEach(function(e){return d.add(e)}):e.type===m.CATEGORY?e.idList.forEach(function(e){return p.add(e)}):e.type===m.PRODUCT_BRAND?e.idList.forEach(function(e){return y.add(e)}):e.type===m.PRODUCT_TAG&&e.idList.forEach(function(e){return E.add(e)})})}),L.spendingMethods&&L.spendingMethods.forEach(function(e){var t,n;e.type===f.FREE_PRODUCT&&(null===(t=e.discountSettings)||void 0===t?void 0:t.freeProductId)&&d.add(e.discountSettings.freeProductId),null===(n=e.productFilters)||void 0===n||n.forEach(function(e){e.type===m.PRODUCT_AND_VARIANT?e.idList.forEach(function(e){return d.add(e)}):e.type===m.CATEGORY?e.idList.forEach(function(e){return p.add(e)}):e.type===m.PRODUCT_BRAND?e.idList.forEach(function(e){return y.add(e)}):e.type===m.PRODUCT_TAG&&e.idList.forEach(function(e){return E.add(e)})})}),g=[],d.size>0&&L.callbacks.getProducts&&g.push(L.callbacks.getProducts(Array.from(d)).then(function(e){return L.products=e})),p.size>0&&L.callbacks.getCategories&&g.push(L.callbacks.getCategories(Array.from(p)).then(function(e){return L.categories=e})),y.size>0&&L.callbacks.getBrands&&g.push(L.callbacks.getBrands(Array.from(y)).then(function(e){return L.brands=e})),E.size>0&&L.callbacks.getTags&&g.push(L.callbacks.getTags(Array.from(E)).then(function(e){return L.tags=e})),[4,Promise.all(g)];case 3:return t.sent(),[3,6];case 4:return h=t.sent(),console.error("Failed to initialize loyalty data",h),[3,6];case 5:return T.current=!1,[7];case 6:return[2]}})})},[]),c(function(){if(!T.current){e(void 0,void 0,void 0,function(){var e,n,r,o,i;return t(this,function(t){switch(t.label){case 0:if(!L.callbacks)return[3,4];t.label=1;case 1:return t.trys.push([1,3,,4]),[4,Promise.all([L.callbacks.listSpendingMethodsByCartId(L.cartId),L.callbacks.getLoyaltyCustomerInfo(),L.callbacks.listLoyaltyProgramPointHistory({})])];case 2:return e=t.sent(),n=e[0],r=e[1],o=e[2],L.spendingMethods=n.map(function(e){return new b(e)}),L.user=r?new R(r):null,L.pointHistory=o?o.map(function(e){return new k(e)}):[],[3,4];case 3:return i=t.sent(),console.error("Failed to fetch cart dependent data",i),[3,4];case 4:return[2]}})})}},[L.cartId]),c(function(){var e;T.current||N&&(L.cartId=N.cartId||null,L.cdnURL=N.cdnURL||"",L.merchantId=N.merchantId||"",L.currency=N.currency||"",L.locale=N.locale||"",L.callbacks=N.callbacks,(null===(e=L.callbacks)||void 0===e?void 0:e.getLoyaltyWidget)&&L.callbacks.getLoyaltyWidget().then(function(e){L.loyaltyWidget=new C(e)}))},[N]);var M=function(e){L.selectedScreen=e},P=function(){var e;(null===(e=L.callbacks)||void 0===e?void 0:e.onWidgetClose)&&L.callbacks.onWidgetClose()},x=L.selectedScreen===d.MAIN_SCREEN,j=o(null),D=j[0],O=j[1];c(function(){L.selectedScreen!==d.MAIN_SCREEN&&O(L.selectedScreen)},[L.selectedScreen]);var B=x?D:L.selectedScreen;return r.createElement(a,{i18n:l},r.createElement(S,{$position:(null==N?void 0:N.position)||(null===(A=window.ikasLoyaltyWidgetConfig)||void 0===A?void 0:A.position)||"fixed"},r.createElement(_,null,r.createElement(w,{$isActive:x,$isMain:!0},r.createElement(p,{viewModel:L,onClose:P,onNavigate:M})),r.createElement(w,{$isActive:!x,$isMain:!1},function(){switch(B){case d.CREDIT_SPENDING_METHODS_SCREEN:return r.createElement(y,{viewModel:L,onBack:function(){return M(d.MAIN_SCREEN)},onClose:P});case d.CREDIT_EARNING_METHODS_SCREEN:return r.createElement(E,{viewModel:L,onBack:function(){return M(d.MAIN_SCREEN)},onClose:P});case d.CREDIT_HISTORY_SCREEN:return r.createElement(g,{viewModel:L,onBack:function(){return M(d.MAIN_SCREEN)},onClose:P});case d.LOYALTY_LEVEL_SCREEN:return r.createElement(h,{viewModel:L,onBack:function(){return M(d.MAIN_SCREEN)},onClose:P});default:return null}}()))))});export{A as default};
|