UNPKG

@salla.sa/twilight-components

Version:
131 lines (125 loc) 12 kB
/*! * Crafted with ❤ by Salla */ 'use strict'; var index = require('./index-uoA36zqH.js'); var translations = require('./translations-DMwpLvqi.js'); var functions = require('./functions-B2luUM6v.js'); var percentage = require('./percentage-Fs83gq6Q.js'); var shipping = require('./shipping-CPYcgyCL.js'); var cart2 = require('./cart2-B98PSAFN.js'); var userAdd = require('./user-add-BCGrddZS.js'); var giftSharing = require('./gift-sharing-BE0uszUm.js'); var gift = require('./gift-DbNivqYO.js'); var trackedPromise = require('./tracked-promise-CVeKKQ0b.js'); var anime_es = require('./anime.es-BqW8JHZi.js'); var SICartUpload = `<!-- Generated by IcoMoon.io --> <svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32"> <title>cart-upload</title> <path d="M14.545 7.669l3.121-2.732v9.729c0 0.736 0.597 1.333 1.333 1.333s1.333-0.597 1.333-1.333v-9.728l3.121 2.732c0.253 0.22 0.567 0.329 0.879 0.329 0.371 0 0.74-0.155 1.004-0.455 0.485-0.555 0.429-1.396-0.125-1.881l-5.333-4.667c-0.503-0.44-1.253-0.44-1.756 0l-5.333 4.667c-0.555 0.484-0.611 1.327-0.125 1.881 0.484 0.552 1.325 0.609 1.881 0.124zM30.647 5.371c-0.713-0.171-1.436 0.267-1.609 0.983l-2.744 11.363c-0.171 0.568-0.684 0.951-1.277 0.951h-12.136c-0.563 0-1.067-0.356-1.256-0.885l-6.035-16.896c-0.189-0.531-0.692-0.885-1.256-0.885h-2.667c-0.736 0-1.333 0.597-1.333 1.333s0.597 1.333 1.333 1.333h1.727l5.719 16.012c0.567 1.588 2.081 2.655 3.768 2.655h12.136c1.78 0 3.32-1.145 3.851-2.92l2.763-11.433c0.173-0.716-0.267-1.436-0.983-1.609zM13.667 24c-2.205 0-4 1.795-4 4s1.795 4 4 4 4-1.795 4-4-1.795-4-4-4zM13.667 29.333c-0.735 0-1.333-0.599-1.333-1.333s0.599-1.333 1.333-1.333 1.333 0.599 1.333 1.333-0.599 1.333-1.333 1.333zM24.333 24c-2.205 0-4 1.795-4 4s1.795 4 4 4 4-1.795 4-4-1.795-4-4-4zM24.333 29.333c-0.735 0-1.333-0.599-1.333-1.333s0.599-1.333 1.333-1.333 1.333 0.599 1.333 1.333-0.599 1.333-1.333 1.333z"></path> </svg> `; const sallaLoyaltyProgramCss = ""; var __decorate = (undefined && undefined.__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; }; const sicons = { all: index.h("span", { class: "s-loyalty-program-rewards-tab-icon", innerHTML: percentage.SILayoutGrid }), free_shipping: index.h("span", { class: "s-loyalty-program-rewards-tab-icon", innerHTML: shipping.SIShipping }), coupon_discount: index.h("span", { class: "s-loyalty-program-rewards-tab-icon", innerHTML: percentage.SIPercentage }), free_product: index.h("span", { class: "s-loyalty-program-rewards-tab-icon", innerHTML: cart2.SICart2 }), }; const SallaLoyaltyProgram = class { constructor(hostRef) { index.registerInstance(this, hostRef); /** * prize to show in details or exchange modals */ this.currentPrize = null; /** * collapsed state of points list */ this.collapsed = true; this.animatedPoints = 0; this.handleExchangeSucceeded = () => { this.points(); this.program(); }; } componentWillLoad() { return salla.onReady() .then(() => salla.lang.onLoaded()) .then(() => translations.setTranslations()) .then(() => { this.program(); this.points(); salla.event.on('loyalty::exchange.succeeded', this.handleExchangeSucceeded); }) .catch((error) => salla.logger.error(error)); } disconnectedCallback() { salla.event.off('loyalty::exchange.succeeded', this.handleExchangeSucceeded); } getOutlineItem(number, title, description) { const icons = { 1: index.h("span", { innerHTML: userAdd.SIUserAdd }), 2: index.h("span", { innerHTML: giftSharing.SIGiftSharing }), 3: index.h("span", { innerHTML: SICartUpload }), }; return (index.h("li", { class: "s-loyalty-program-item" }, index.h("div", { class: "s-loyalty-program-content" }, index.h("span", { class: "s-loyalty-program-icon-container" }, index.h("span", { class: "s-loyalty-program-text-gradient" }, number), index.h("span", { class: "s-loyalty-program-icon" }, icons[number])), index.h("div", { class: "s-loyalty-program-title" }, title), index.h("div", { class: "s-loyalty-program-description" }, description)))); } render() { if (this.program.status === 'error') { return index.h("p", null, salla.lang.get('common.errors.error_occured')); } const displayedPoints = this.program.data.points.slice(0, this.collapsed ? functions.nearestLowerMultiple(this.program.data.points.length) : this.program.data.points.length); const prizesGroups = this.program.data.prizes; const prizesCount = this.program.data.prizes_count; return (index.h("div", { class: "s-loyalty-program-container" }, index.h("salla-loyalty-hero", { name: this.program.data.name, description: this.program.data.description, image: this.program.data.image }, salla.config.isUser() ? index.h("div", { slot: "crosspoint", class: "s-loyalty-program-profile-wrapper" }, index.h("div", { class: "s-loyalty-program-profile-container" }, index.h("div", { class: "s-loyalty-program-profile-points-section" }, index.h("h2", { class: "s-loyalty-program-profile-label" }, salla.lang.get('pages.loyalty_program.your_points')), index.h("p", { class: "s-loyalty-program-profile-points" }, index.h("span", { class: "s-loyalty-program-profile-points-value" }, !!this.animatedPoints ? this.animatedPoints : this.points.data), "\u00A0", salla.lang.get('pages.loyalty_program.point'))), index.h("div", { class: "s-loyalty-program-profile-icon" }, index.h("span", { innerHTML: gift.SIGift })))) : index.h("button", { slot: "action", onClick: () => salla.event.dispatch('login::open'), class: { 's-loyalty-program-login-action': true, 's-loyalty-program-login-action-dark': !this.program.data.image, 's-loyalty-program-login-action-light': !!this.program.data.image, } }, salla.lang.get('blocks.header.login'))), index.h("div", { class: "s-loyalty-program-outline-section" }, index.h("section", { class: "s-loyalty-program-section" }, index.h("header", { class: "s-loyalty-program-header" }, index.h("h1", { class: "s-loyalty-program-main-title" }, salla.lang.get('pages.loyalty_program.how_to_start')), index.h("p", { class: "s-loyalty-program-subtitle" }, salla.lang.get('pages.loyalty_program.three_simple_steps'))), index.h("ol", { class: "s-loyalty-program-list" }, this.getOutlineItem(1, salla.lang.get('pages.loyalty_program.register'), salla.lang.get('pages.loyalty_program.create_account')), this.getOutlineItem(2, salla.lang.get('pages.loyalty_program.earn_points'), salla.lang.get('pages.loyalty_program.complete_tasks')), this.getOutlineItem(3, salla.lang.get('pages.loyalty_program.redeem_rewards'), salla.lang.get('pages.loyalty_program.enjoy_rewards'))))), index.h("div", { class: "s-loyalty-program-points-wrapper" }, index.h("section", { class: "s-loyalty-program-points-section" }, index.h("header", { class: "s-loyalty-program-points-header" }, index.h("h1", { class: "s-loyalty-program-points-title" }, this.program.data.promotion_title), index.h("p", { class: "s-loyalty-program-points-description" }, this.program.data.promotion_description)), index.h("div", { class: "s-loyalty-program-points-spacer" }), index.h("ul", { class: { 's-loyalty-program-points-list-one': this.program.data.points.length === 1, 's-loyalty-program-points-list-two': this.program.data.points.length === 2, 's-loyalty-program-points-list-multi': this.program.data.points.length > 2, } }, displayedPoints.map(point => (index.h("li", null, index.h("salla-loyalty-point", { point: point }))))), index.h("div", { class: "s-loyalty-program-points-spacer" }), functions.nearestLowerMultiple(this.program.data.points.length) !== this.program.data.points.length && index.h("button", { class: "s-loyalty-program-points-more-button", onClick: () => this.collapsed = !this.collapsed }, this.collapsed ? index.h("span", null, salla.lang.get('pages.loyalty_program.show_more'), "\u00A0\u00A0", index.h("span", { style: { fontSize: '1.2rem', fontWeight: '300' } }, "+")) : index.h("span", null, salla.lang.get('pages.loyalty_program.show_less'), "\u00A0\u00A0", index.h("span", { style: { fontSize: '1.2rem', fontWeight: '300' } }, "-"))))), this.program.status !== 'success' ? '' : index.h("div", { class: "s-loyalty-program-rewards-container s-loyalty-program-slider-arrows-edges" }, index.h("section", { class: { 's-loyalty-program-tabs-hider': prizesGroups.length <= 2 || prizesCount <= 4, } }, index.h("h1", { class: "s-loyalty-program-rewards-heading-mobile" }, salla.lang.get('pages.loyalty_program.rewards')), index.h("salla-tabs", null, index.h("div", { slot: "header", class: "s-loyalty-program-rewards-tab-items" }, prizesGroups.map((group) => (index.h("salla-tab-header", { slot: "header", name: group.type }, sicons[group.type], index.h("span", null, group.title))))), index.h("h1", { slot: "header", class: "s-loyalty-program-rewards-heading-desktop" }, salla.lang.get('pages.loyalty_program.rewards')), prizesGroups.map((group) => (index.h("salla-tab-content", { slot: "content", name: group.type }, index.h("salla-slider", { id: group.type, type: "default", "slider-config": '{"loop":false,"slidesPerView":"auto","freeMode":true,"spaceBetween":12,"breakpoints":{"768":{"slidesPerView":4,"spaceBetween":24,"freeMode":false,"speed":300}}}' }, index.h("div", { slot: "items" }, group.items.map((prize) => index.h("salla-reward-card", { prize: prize, onAreaClick: () => { this.currentPrize = prize; functions.closeModals(() => this.detailsModal.open()); }, onActionClick: () => { this.currentPrize = prize; functions.closeModals(() => this.detailsModal.open()); } })))))))), index.h("salla-modal", { ref: modal => this.detailsModal = modal, class: "s-loyalty-program-modal", width: "md", noPadding: true }, !this.currentPrize ? '' : index.h("salla-reward-details", { onActionClick: () => functions.closeModals(() => this.exchangeModal.open()), prize: this.currentPrize })), index.h("salla-modal", { ref: modal => this.exchangeModal = modal, class: "s-loyalty-program-modal", width: "sm" }, !this.currentPrize ? '' : index.h("salla-reward-exchange", { prize: this.currentPrize })))))); } }; __decorate([ trackedPromise.TrackedPromise(async function () { const { data } = await salla.loyalty.getProgram(); return functions.normalizeLoyaltyData(data); }, { initialData: { points: [], prizes: [], prizes_count: 0 } }) ], SallaLoyaltyProgram.prototype, "program", void 0); __decorate([ trackedPromise.TrackedPromise(async function () { const { data } = await salla.loyalty.getPoints(); anime_es.anime({ targets: { value: 0 }, value: data.points ?? 0, round: 1, easing: 'easeOutQuad', duration: 2000, update: (anim) => { this.animatedPoints = anim.animations[0].currentValue; } }); return data.points; }) ], SallaLoyaltyProgram.prototype, "points", void 0); SallaLoyaltyProgram.style = sallaLoyaltyProgramCss; exports.salla_loyalty_program = SallaLoyaltyProgram;