UNPKG

@salla.sa/twilight-components

Version:
115 lines (114 loc) 5.64 kB
/*! * Crafted with ❤ by Salla */ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; import { h, Host } from "@stencil/core"; import { closeModals } from "./functions"; import SIGift from "../../assets/svg/gift.svg"; import { TrackedPromise } from "../../Helpers/tracked-promise"; export class SallaRewardExchange { constructor() { this.productId = null; } reset(timeout = 0) { setTimeout(() => { closeModals(); }, timeout); } getApiErrorMessage(error) { return error?.response?.data?.error?.message || error?.response?.data?.message || (typeof error === 'string' ? error : null) || salla.lang.get('common.errors.error_occurred'); } async handleConfirm() { try { await this.exchange(this.prize.id, null, this.productId); this.reset(300); } catch (error) { salla.notify.error(this.getApiErrorMessage(error)); } } handleCancel() { this.reset(0); } render() { return (h(Host, { key: 'ceecba37884a11443b52b76dad69bd164b52b788' }, h("div", { key: '598f185363b917969b9de0fb6a536884d6578c95', class: "s-loyalty-program-exchange-heading" }, h("div", { key: 'a2aa6b15d97533a973f7f2fb6a2cf517c147367d', class: "s-loyalty-program-circle-base s-loyalty-program-circle-size-xl s-loyalty-program-circle-variant-fill" }, h("span", { key: '9745001d514643add62fe9a64df7fc2c0a694513', innerHTML: SIGift })), h("h2", { key: '4819327aacc1307c0f75014d9faef50f55115289' }, salla.lang.get('pages.loyalty_program.redeem_reward')), h("p", { key: 'b39c99abcefb0f3baf609cd21049b083a115cdef' }, salla.lang.get('pages.loyalty_program.redeem_confirmation'), " ", h("span", { key: '50852d87c9686f66beddc7b0a0a3062f0ced1a61' }, "(", this.prize.cost_points, " ", salla.lang.get('pages.loyalty_program.point'), ")"), " ", salla.lang.get('pages.loyalty_program.for'), " ", h("span", { key: '5a4baa0f02859ced6fdcf7ce77c31bf9b27c45e6' }, "(", this.prize.name, ")"))), h("div", { key: 'b1f1067bd0f3a84231ac017f4b66a71277a5d209', class: "s-loyalty-program-exchange-btns" }, h("button", { key: '7d4ce6c08fcac58290b364a0df55f8acb715d362', class: "s-loyalty-program-rewards-action-base s-loyalty-program-rewards-action-confirm", onClick: () => this.handleConfirm() }, h("span", { key: 'ef1deb96c4bbb2843ae088b539848c15aacdb244', style: { opacity: this.exchange.status !== 'pending' ? '1' : '0', } }, salla.lang.get('common.elements.confirm')), h("span", { key: '0f949386c85d7544f7098e2bdc8c7ce4390c4383', class: "s-loyalty-program-exchange-loading", style: { opacity: this.exchange.status === 'pending' ? '1' : '0', } }, h("salla-loading", { key: '9cdfbfdc7ebfb2e1874f1956560dc464e4aa2a9f', color: "primary", size: 24 }))), h("button", { key: '79a2e8b44be5eb4b3ec5f1a285a8f4eba5324814', class: "s-loyalty-program-rewards-action-base s-loyalty-program-rewards-action-cancel", onClick: () => this.handleCancel() }, salla.lang.get('common.elements.cancel'))))); } static get is() { return "salla-reward-exchange"; } static get originalStyleUrls() { return { "$": ["salla-loyalty-program.scss"] }; } static get styleUrls() { return { "$": ["salla-loyalty-program.css"] }; } static get properties() { return { "prize": { "type": "unknown", "attribute": "prize", "mutable": false, "complexType": { "original": "Prize", "resolved": "Prize", "references": { "Prize": { "location": "import", "path": "./interfaces", "id": "src/components/salla-loyalty-program/interfaces.ts::Prize" } } }, "required": false, "optional": false, "docs": { "tags": [], "text": "" }, "getter": false, "setter": false }, "productId": { "type": "number", "attribute": "product-id", "mutable": false, "complexType": { "original": "number | null", "resolved": "number", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "" }, "getter": false, "setter": false, "reflect": false, "defaultValue": "null" } }; } } __decorate([ TrackedPromise(async (...args) => await salla.loyalty.exchange(...args)) ], SallaRewardExchange.prototype, "exchange", void 0);