FileMaster
Search
Toggle Dark Mode
Home
/
.
/
wp-content
/
plugins
/
surecart
/
dist
/
components
/
components
Edit File: sc-licenses-list.js
import{proxyCustomElement,HTMLElement,h}from"@stencil/core/internal/client";import{o as onFirstVisible}from"./lazy.js";import{a as apiFetch}from"./fetch.js";import{d as defineCustomElement$g}from"./sc-alert2.js";import{d as defineCustomElement$f}from"./sc-button2.js";import{d as defineCustomElement$e}from"./sc-card2.js";import{d as defineCustomElement$d}from"./sc-dashboard-module2.js";import{d as defineCustomElement$c}from"./sc-divider2.js";import{d as defineCustomElement$b}from"./sc-empty2.js";import{d as defineCustomElement$a}from"./sc-flex2.js";import{d as defineCustomElement$9}from"./sc-icon2.js";import{d as defineCustomElement$8}from"./sc-pagination2.js";import{d as defineCustomElement$7}from"./sc-skeleton2.js";import{d as defineCustomElement$6}from"./sc-spinner2.js";import{d as defineCustomElement$5}from"./sc-stacked-list2.js";import{d as defineCustomElement$4}from"./sc-stacked-list-row2.js";import{d as defineCustomElement$3}from"./sc-tag2.js";import{d as defineCustomElement$2}from"./sc-visually-hidden2.js";import{a as addQueryArgs}from"./add-query-args.js";const scLicensesListCss=":host{display:block}.license__name{font-weight:var(--sc-font-weight-semibold)}.license__details{display:grid;gap:0.25em;color:var(--sc-input-label-color)}",ScLicensesListStyle0=scLicensesListCss,ScLicensesList$1=proxyCustomElement(class extends HTMLElement{constructor(){super(),this.__registerHost(),this.__attachShadow(),this.query={page:1,per_page:10},this.heading=wp.i18n.__("Licenses","surecart"),this.isCustomer=void 0,this.allLink=void 0,this.licenses=[],this.copied=!1,this.loading=!1,this.error="",this.pagination={total:0,total_pages:0}}componentWillLoad(){onFirstVisible(this.el,(()=>{this.initialFetch()}))}nextPage(){this.query.page=this.query.page+1,this.initialFetch()}prevPage(){this.query.page=this.query.page-1,this.initialFetch()}async initialFetch(){try{this.loading=!0,await this.getLicenses()}catch(e){console.error(e),this.error=(null==e?void 0:e.message)||wp.i18n.__("Something went wrong","surecart")}finally{this.loading=!1}}async getLicenses(){if(!this.isCustomer)return;const e=await await apiFetch({path:addQueryArgs("surecart/v1/licenses",{expand:["purchase","purchase.product","activations"],...this.query}),parse:!1});return this.pagination={total:parseInt(e.headers.get("X-WP-Total")),total_pages:parseInt(e.headers.get("X-WP-TotalPages"))},this.licenses=await e.json(),this.licenses}renderStatus(e){return"active"===e?h("sc-tag",{type:"success"},wp.i18n.__("Active","surecart")):"revoked"===e?h("sc-tag",{type:"danger"},wp.i18n.__("Revoked","surecart")):h("sc-tag",{type:"info"},"inactive"===e?wp.i18n.__("Not Activated","surecart"):e)}async copyKey(e){try{await navigator.clipboard.writeText(e),this.copied=!0,setTimeout((()=>{this.copied=!1}),2e3)}catch(e){console.error(e),alert(wp.i18n.__("Error copying to clipboard","surecart"))}}renderLoading(){return h("sc-card",{"no-padding":!0,style:{"--overflow":"hidden"}},h("sc-stacked-list",null,h("sc-stacked-list-row",{style:{"--columns":"2"},"mobile-size":0},h("div",{style:{padding:"0.5em"}},h("sc-skeleton",{style:{width:"30%",marginBottom:"0.75em"}}),h("sc-skeleton",{style:{width:"20%",marginBottom:"0.75em"}}),h("sc-skeleton",{style:{width:"40%"}})))))}renderEmpty(){return h("div",null,h("sc-divider",{style:{"--spacing":"0"}}),h("slot",{name:"empty"},h("sc-empty",{icon:"file-text"},wp.i18n.__("You don't have any licenses.","surecart"))))}renderContent(){var e,s;return this.loading?this.renderLoading():0===(null===(e=this.licenses)||void 0===e?void 0:e.length)?this.renderEmpty():h("sc-card",{"no-padding":!0},h("sc-stacked-list",null,null===(s=this.licenses)||void 0===s?void 0:s.map((({id:e,purchase:s,status:t,activation_limit:i,activation_count:n})=>{var a;return h("sc-stacked-list-row",{key:e,href:addQueryArgs(window.location.href,{action:"show",model:"license",id:e}),"mobile-size":0},h("div",{class:"license__details"},h("div",{class:"license__name"},null===(a=null==s?void 0:s.product)||void 0===a?void 0:a.name),h("div",null,this.renderStatus(t)," ",wp.i18n.sprintf(wp.i18n.__("%1s of %2s Activations Used"),n||0,i||"∞"))),h("sc-icon",{name:"chevron-right",slot:"suffix"}))}))))}render(){var e,s;return h("sc-dashboard-module",{key:"34ee7df77370131e228af4bb0bef147c0222a5a2",class:"purchase",part:"base",error:this.error},h("span",{key:"6faa343acdb336ab94351f9372c5ed79b2b6bdbf",slot:"heading"},h("slot",{key:"e4a96afd6e194275a68d7c0eb07fe9bb4b2be5e7",name:"heading"},this.heading||wp.i18n.__("License Keys","surecart"))),!!this.allLink&&!!(null===(e=this.licenses)||void 0===e?void 0:e.length)&&h("sc-button",{key:"a47686b70d445bb5363b8ddfb2d9ae8d3ce0dfdb",type:"link",href:this.allLink,slot:"end"},wp.i18n.__("View all","surecart"),h("sc-icon",{key:"d432bfd067f17d264ad83f86126cbec19cfd70fc",name:"chevron-right",slot:"suffix"})),this.renderContent(),!this.allLink&&h("sc-pagination",{key:"2fcd069e1d2b1fa826c8e5f8d98e0c8538e35d83",page:this.query.page,perPage:this.query.per_page,total:this.pagination.total,totalPages:this.pagination.total_pages,totalShowing:null===(s=null==this?void 0:this.licenses)||void 0===s?void 0:s.length,onScNextPage:()=>this.nextPage(),onScPrevPage:()=>this.prevPage()}))}get el(){return this}static get style(){return ScLicensesListStyle0}},[1,"sc-licenses-list",{query:[1040],heading:[1],isCustomer:[4,"is-customer"],allLink:[1,"all-link"],licenses:[1040],copied:[32],loading:[32],error:[32],pagination:[32]}]);function defineCustomElement$1(){"undefined"!=typeof customElements&&["sc-licenses-list","sc-alert","sc-button","sc-card","sc-dashboard-module","sc-divider","sc-empty","sc-flex","sc-icon","sc-pagination","sc-skeleton","sc-spinner","sc-stacked-list","sc-stacked-list-row","sc-tag","sc-visually-hidden"].forEach((e=>{switch(e){case"sc-licenses-list":customElements.get(e)||customElements.define(e,ScLicensesList$1);break;case"sc-alert":customElements.get(e)||defineCustomElement$g();break;case"sc-button":customElements.get(e)||defineCustomElement$f();break;case"sc-card":customElements.get(e)||defineCustomElement$e();break;case"sc-dashboard-module":customElements.get(e)||defineCustomElement$d();break;case"sc-divider":customElements.get(e)||defineCustomElement$c();break;case"sc-empty":customElements.get(e)||defineCustomElement$b();break;case"sc-flex":customElements.get(e)||defineCustomElement$a();break;case"sc-icon":customElements.get(e)||defineCustomElement$9();break;case"sc-pagination":customElements.get(e)||defineCustomElement$8();break;case"sc-skeleton":customElements.get(e)||defineCustomElement$7();break;case"sc-spinner":customElements.get(e)||defineCustomElement$6();break;case"sc-stacked-list":customElements.get(e)||defineCustomElement$5();break;case"sc-stacked-list-row":customElements.get(e)||defineCustomElement$4();break;case"sc-tag":customElements.get(e)||defineCustomElement$3();break;case"sc-visually-hidden":customElements.get(e)||defineCustomElement$2()}}))}const ScLicensesList=ScLicensesList$1,defineCustomElement=defineCustomElement$1;export{ScLicensesList,defineCustomElement};
Save
Back