UNPKG

@salla.sa/twilight-components

Version:
90 lines (85 loc) 5.34 kB
/*! * Crafted with ❤ by Salla */ 'use strict'; var index = require('./index-WgjOGof0.js'); var gift = require('./gift-BPDUPIY_.js'); const sallaLoyaltyProgramCss = ""; const formatDate = (timestamp) => { if (!timestamp) return ''; return new Date(Number(timestamp)).toLocaleDateString(salla.lang.locale, { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', hour: 'numeric', }); }; const translateKey = (key) => { if (!key) return ''; try { const k = key.toLowerCase(); const translation = salla.lang.get(`pages.loyalty_program.${k}`); return translation === `pages.loyalty_program.${k}` ? key : translation; } catch (_a) { return key; } }; const SallaWalletTable = class { constructor(hostRef) { index.registerInstance(this, hostRef); this.loyaltyPointsArray = []; this.isLoadingLoyalty = false; this.nextPageUrlLoyalty = ''; this.handleClick = () => { this.loadMoreLoyaltyPoints(); }; } componentWillLoad() { return salla.onReady().then(() => { this.loadLoyaltyPoints(); }); } async loadLoyaltyPoints() { this.isLoadingLoyalty = true; try { let url = `/balance/points?page=1`; let resp = await salla.api.request(url); this.loyaltyPointsArray = resp.data; this.nextPageUrlLoyalty = resp.cursor.next; } catch (error) { console.error('Error loading loyalty points transactions', error); } finally { this.isLoadingLoyalty = false; } } async loadMoreLoyaltyPoints() { var _a; if (!this.nextPageUrlLoyalty) return; this.isLoadingLoyalty = true; try { let resp = await salla.api.request(this.nextPageUrlLoyalty); this.loyaltyPointsArray = [...this.loyaltyPointsArray, ...resp.data]; this.nextPageUrlLoyalty = ((_a = resp.cursor) === null || _a === void 0 ? void 0 : _a.next) || ''; } catch (error) { console.error('Error loading more loyalty points', error); } finally { this.isLoadingLoyalty = false; } } render() { return (index.h(index.Host, { key: 'c62612b3bcbd5938b7a7e1609c0318a11c7ad6ee' }, index.h("div", { key: '8be48cf7e0f183e7d66a94f2ce4c8aad838e8a45' }, this.isLoadingLoyalty ? (index.h("salla-loading", null)) : (index.h("div", null, this.loyaltyPointsArray.length > 0 ? (index.h("div", null, index.h("table", { class: "s-loyalty-program-table" }, index.h("thead", { class: "s-loyalty-program-table-head" }, index.h("tr", { class: "s-loyalty-program-table-head-tr" }, index.h("th", { scope: "col", class: "s-loyalty-program-table-head-tr-th" }, salla.lang.get('pages.wallet.points')), index.h("th", { scope: "col", class: "s-loyalty-program-table-head-tr-th" }, salla.lang.get('pages.wallet.date')), index.h("th", { scope: "col", class: "s-loyalty-program-table-head-tr-th" }, salla.lang.get('pages.wallet.expiry_date')), index.h("th", { scope: "col", class: "s-loyalty-program-table-head-tr-th" }, salla.lang.get('common.elements.note')), index.h("th", { scope: "col", class: "s-loyalty-program-table-head-tr-th" }, salla.lang.get('common.elements.status')))), index.h("tbody", { class: "s-loyalty-program-table-tbody" }, this.loyaltyPointsArray.map(point => (index.h("tr", { class: "s-loyalty-program-table-tbody-tr" }, index.h("td", { class: "s-loyalty-program-table-tbody-tr-td" }, (point === null || point === void 0 ? void 0 : point.type) === 'plus' ? '+' : '', (point === null || point === void 0 ? void 0 : point.points) || '', " ", salla.lang.get('pages.loyalty_program.point')), index.h("td", { class: "s-loyalty-program-table-tbody-tr-td" }, formatDate((point === null || point === void 0 ? void 0 : point.created_at) ? Number(point.created_at) * 1000 : undefined)), index.h("td", { class: "s-loyalty-program-table-tbody-tr-td" }, formatDate(point === null || point === void 0 ? void 0 : point.points_expire_date)), index.h("td", { class: "s-loyalty-program-table-tbody-tr-td" }, translateKey(point === null || point === void 0 ? void 0 : point.key)), index.h("td", { class: "s-loyalty-program-table-tbody-tr-td" }, translateKey(point === null || point === void 0 ? void 0 : point.status_key))))))), index.h("div", { class: "s-infinite-scroll-wrapper" }, !!this.nextPageUrlLoyalty && (index.h("salla-button", { onClick: this.handleClick, loading: this.isLoadingLoyalty }, salla.lang.get('common.elements.load_more')))))) : (index.h("div", null, index.h("div", { class: "s-loyalty-program-table-empty-state" }, index.h("span", { innerHTML: gift.GiftIcon }), index.h("div", { class: "s-loyalty-program-table-placeholder-title" }, salla.lang.get('pages.loyalty_program.no_loyality_points_title')), index.h("div", { class: "s-loyalty-program-table-placeholder-sub-title" }, salla.lang.get('pages.loyalty_program.no_loyality_points_sub_title')))))))))); } }; SallaWalletTable.style = sallaLoyaltyProgramCss; exports.salla_loyalty_program = SallaWalletTable; //# sourceMappingURL=salla-loyalty-program.entry.cjs.js.map //# sourceMappingURL=salla-loyalty-program.cjs.entry.js.map