UNPKG

@salla.sa/twilight-components

Version:
5 lines 6.31 kB
var __awaiter=this&&this.__awaiter||function(t,a,r,l){function e(t){return t instanceof r?t:new r((function(a){a(t)}))}return new(r||(r=Promise))((function(r,s){function o(t){try{i(l.next(t))}catch(t){s(t)}}function n(t){try{i(l["throw"](t))}catch(t){s(t)}}function i(t){t.done?r(t.value):e(t.value).then(o,n)}i((l=l.apply(t,a||[])).next())}))};var __generator=this&&this.__generator||function(t,a){var r={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},l,e,s,o;return o={next:n(0),throw:n(1),return:n(2)},typeof Symbol==="function"&&(o[Symbol.iterator]=function(){return this}),o;function n(t){return function(a){return i([t,a])}}function i(n){if(l)throw new TypeError("Generator is already executing.");while(o&&(o=0,n[0]&&(r=0)),r)try{if(l=1,e&&(s=n[0]&2?e["return"]:n[0]?e["throw"]||((s=e["return"])&&s.call(e),0):e.next)&&!(s=s.call(e,n[1])).done)return s;if(e=0,s)n=[n[0]&2,s.value];switch(n[0]){case 0:case 1:s=n;break;case 4:r.label++;return{value:n[1],done:false};case 5:r.label++;e=n[1];n=[0];continue;case 7:n=r.ops.pop();r.trys.pop();continue;default:if(!(s=r.trys,s=s.length>0&&s[s.length-1])&&(n[0]===6||n[0]===2)){r=0;continue}if(n[0]===3&&(!s||n[1]>s[0]&&n[1]<s[3])){r.label=n[1];break}if(n[0]===6&&r.label<s[1]){r.label=s[1];s=n;break}if(s&&r.label<s[2]){r.label=s[2];r.ops.push(n);break}if(s[2])r.ops.pop();r.trys.pop();continue}n=a.call(t,r)}catch(t){n=[6,t];e=0}finally{l=s=0}if(n[0]&5)throw n[1];return{value:n[0]?n[1]:void 0,done:true}}};var __spreadArray=this&&this.__spreadArray||function(t,a,r){if(r||arguments.length===2)for(var l=0,e=a.length,s;l<e;l++){if(s||!(l in a)){if(!s)s=Array.prototype.slice.call(a,0,l);s[l]=a[l]}}return t.concat(s||Array.prototype.slice.call(a))}; /*! * Crafted with ❤ by Salla */import{r as registerInstance,h,H as Host}from"./index-DWStDVKB.js";import{G as GiftIcon}from"./gift-C0JNGIpa.js";var sallaLoyaltyProgramCss="";var formatDate=function(t){if(!t)return"";return new Date(Number(t)).toLocaleDateString(salla.lang.locale,{weekday:"long",year:"numeric",month:"long",day:"numeric",hour:"numeric"})};var translateKey=function(t){if(!t)return"";try{var a=t.toLowerCase();var r=salla.lang.get("pages.loyalty_program.".concat(a));return r==="pages.loyalty_program.".concat(a)?t:r}catch(a){return t}};var SallaWalletTable=function(){function t(t){var a=this;registerInstance(this,t);this.loyaltyPointsArray=[];this.isLoadingLoyalty=false;this.nextPageUrlLoyalty="";this.handleClick=function(){a.loadMoreLoyaltyPoints()}}t.prototype.componentWillLoad=function(){var t=this;return salla.onReady().then((function(){t.loadLoyaltyPoints()}))};t.prototype.loadLoyaltyPoints=function(){return __awaiter(this,void 0,void 0,(function(){var t,a,r;return __generator(this,(function(l){switch(l.label){case 0:this.isLoadingLoyalty=true;l.label=1;case 1:l.trys.push([1,3,4,5]);t="/balance/points?page=1";return[4,salla.api.request(t)];case 2:a=l.sent();this.loyaltyPointsArray=a.data;this.nextPageUrlLoyalty=a.cursor.next;return[3,5];case 3:r=l.sent();console.error("Error loading loyalty points transactions",r);return[3,5];case 4:this.isLoadingLoyalty=false;return[7];case 5:return[2]}}))}))};t.prototype.loadMoreLoyaltyPoints=function(){return __awaiter(this,void 0,void 0,(function(){var t,a,r;return __generator(this,(function(l){switch(l.label){case 0:if(!this.nextPageUrlLoyalty)return[2];this.isLoadingLoyalty=true;l.label=1;case 1:l.trys.push([1,3,4,5]);return[4,salla.api.request(this.nextPageUrlLoyalty)];case 2:a=l.sent();this.loyaltyPointsArray=__spreadArray(__spreadArray([],this.loyaltyPointsArray,true),a.data,true);this.nextPageUrlLoyalty=((t=a.cursor)===null||t===void 0?void 0:t.next)||"";return[3,5];case 3:r=l.sent();console.error("Error loading more loyalty points",r);return[3,5];case 4:this.isLoadingLoyalty=false;return[7];case 5:return[2]}}))}))};t.prototype.render=function(){return h(Host,{key:"c62612b3bcbd5938b7a7e1609c0318a11c7ad6ee"},h("div",{key:"8be48cf7e0f183e7d66a94f2ce4c8aad838e8a45"},this.isLoadingLoyalty?h("salla-loading",null):h("div",null,this.loyaltyPointsArray.length>0?h("div",null,h("table",{class:"s-loyalty-program-table"},h("thead",{class:"s-loyalty-program-table-head"},h("tr",{class:"s-loyalty-program-table-head-tr"},h("th",{scope:"col",class:"s-loyalty-program-table-head-tr-th"},salla.lang.get("pages.wallet.points")),h("th",{scope:"col",class:"s-loyalty-program-table-head-tr-th"},salla.lang.get("pages.wallet.date")),h("th",{scope:"col",class:"s-loyalty-program-table-head-tr-th"},salla.lang.get("pages.wallet.expiry_date")),h("th",{scope:"col",class:"s-loyalty-program-table-head-tr-th"},salla.lang.get("common.elements.note")),h("th",{scope:"col",class:"s-loyalty-program-table-head-tr-th"},salla.lang.get("common.elements.status")))),h("tbody",{class:"s-loyalty-program-table-tbody"},this.loyaltyPointsArray.map((function(t){return h("tr",{class:"s-loyalty-program-table-tbody-tr"},h("td",{class:"s-loyalty-program-table-tbody-tr-td"},(t===null||t===void 0?void 0:t.type)==="plus"?"+":"",(t===null||t===void 0?void 0:t.points)||""," ",salla.lang.get("pages.loyalty_program.point")),h("td",{class:"s-loyalty-program-table-tbody-tr-td"},formatDate((t===null||t===void 0?void 0:t.created_at)?Number(t.created_at)*1e3:undefined)),h("td",{class:"s-loyalty-program-table-tbody-tr-td"},formatDate(t===null||t===void 0?void 0:t.points_expire_date)),h("td",{class:"s-loyalty-program-table-tbody-tr-td"},translateKey(t===null||t===void 0?void 0:t.key)),h("td",{class:"s-loyalty-program-table-tbody-tr-td"},translateKey(t===null||t===void 0?void 0:t.status_key)))})))),h("div",{class:"s-infinite-scroll-wrapper"},!!this.nextPageUrlLoyalty&&h("salla-button",{onClick:this.handleClick,loading:this.isLoadingLoyalty},salla.lang.get("common.elements.load_more")))):h("div",null,h("div",{class:"s-loyalty-program-table-empty-state"},h("span",{innerHTML:GiftIcon}),h("div",{class:"s-loyalty-program-table-placeholder-title"},salla.lang.get("pages.loyalty_program.no_loyality_points_title")),h("div",{class:"s-loyalty-program-table-placeholder-sub-title"},salla.lang.get("pages.loyalty_program.no_loyality_points_sub_title")))))))};return t}();SallaWalletTable.style=sallaLoyaltyProgramCss;export{SallaWalletTable as salla_loyalty_program}; //# sourceMappingURL=salla-loyalty-program.entry.js.map