FileMaster
Search
Toggle Dark Mode
Home
/
.
/
wp-content
/
plugins
/
surecart
/
dist
/
components
/
components
Edit File: sc-license.js
import{proxyCustomElement,HTMLElement,h,Fragment}from"@stencil/core/internal/client";import{o as onFirstVisible}from"./lazy.js";import{a as apiFetch}from"./fetch.js";import{d as defineCustomElement$k}from"./sc-alert2.js";import{d as defineCustomElement$j}from"./sc-block-ui2.js";import{d as defineCustomElement$i}from"./sc-button2.js";import{d as defineCustomElement$h}from"./sc-card2.js";import{d as defineCustomElement$g}from"./sc-dashboard-module2.js";import{d as defineCustomElement$f}from"./sc-dialog2.js";import{d as defineCustomElement$e}from"./sc-empty2.js";import{d as defineCustomElement$d}from"./sc-flex2.js";import{d as defineCustomElement$c}from"./sc-form-control2.js";import{d as defineCustomElement$b}from"./sc-icon2.js";import{d as defineCustomElement$a}from"./sc-input2.js";import{d as defineCustomElement$9}from"./sc-pagination2.js";import{d as defineCustomElement$8}from"./sc-skeleton2.js";import{d as defineCustomElement$7}from"./sc-spacing2.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 scLicenseCss=":host{display:block}.license__date{font-weight:var(--sc-font-weight-semibold)}.license__heading{display:flex;align-items:center;gap:1rem}.license__key{display:block}.close__button{position:absolute;top:0;right:0;font-size:22px;z-index:1}.license-cancel{display:grid;gap:0.5em}",ScLicenseStyle0=scLicenseCss,ScLicense$1=proxyCustomElement(class extends HTMLElement{constructor(){super(),this.__registerHost(),this.__attachShadow(),this.deleteActivation=async()=>{try{this.busy=!0,await apiFetch({path:`surecart/v1/activations/${this.selectedActivationId}`,method:"DELETE"}),this.onCloseDeleteModal(),await this.initialFetch()}catch(e){console.error(e),this.deleteActivationError=(null==e?void 0:e.message)||wp.i18n.__("Something went wrong","surecart")}finally{this.busy=!1}},this.onCloseDeleteModal=()=>{this.selectedActivationId="",this.showConfirmDelete=!1,this.busy=!1,this.deleteActivationError=""},this.licenseId=void 0,this.loading=!1,this.error="",this.license=void 0,this.activations=[],this.copied=!1,this.showConfirmDelete=!1,this.selectedActivationId="",this.deleteActivationError="",this.busy=!1,this.pagination={total:0,total_pages:0},this.query={page:1,per_page:10}}nextPage(){this.query.page=this.query.page+1,this.fetchActivations()}prevPage(){this.query.page=this.query.page-1,this.fetchActivations()}componentWillLoad(){onFirstVisible(this.el,(()=>{this.initialFetch()}))}async fetchActivations(){try{this.loading=!0,await this.getActivations()}catch(e){console.error(e),this.error=(null==e?void 0:e.message)||wp.i18n.__("Something went wrong","surecart")}finally{this.loading=!1}}async initialFetch(){try{this.loading=!0,await Promise.all([this.getLicense(),this.getActivations()])}catch(e){console.error(e),this.error=(null==e?void 0:e.message)||wp.i18n.__("Something went wrong","surecart")}finally{this.loading=!1}}async getLicense(){this.license=await apiFetch({path:addQueryArgs(`surecart/v1/licenses/${this.licenseId}`,{expand:["purchase","purchase.product"]})})}async getActivations(){const e=await apiFetch({path:addQueryArgs("surecart/v1/activations",{license_ids:[this.licenseId],...this.query}),parse:!1});this.pagination={total:parseInt(e.headers.get("X-WP-Total")),total_pages:parseInt(e.headers.get("X-WP-TotalPages"))},this.activations=await e.json()}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"))}}renderStatus(){var e,t,s,i;return"active"===(null===(e=this.license)||void 0===e?void 0:e.status)?h("sc-tag",{type:"success"},wp.i18n.__("Active","surecart")):"revoked"===(null===(t=this.license)||void 0===t?void 0:t.status)?h("sc-tag",{type:"danger"},wp.i18n.__("Revoked","surecart")):"inactive"===(null===(s=this.license)||void 0===s?void 0:s.status)?h("sc-tag",{type:"info"},wp.i18n.__("Inactive","surecart")):h("sc-tag",{type:"info"},null===(i=this.license)||void 0===i?void 0:i.status)}renderLoading(){return h("sc-dashboard-module",null,h("span",{slot:"heading"},h("sc-skeleton",{style:{width:"120px"}})),h("sc-card",null,h("sc-stacked-list",null,h("sc-flex",{flexDirection:"column",style:{gap:"1em"}},h("sc-skeleton",{style:{width:"20%",display:"inline-block"}}),h("sc-skeleton",{style:{width:"60%",display:"inline-block"}}),h("sc-skeleton",{style:{width:"40%",display:"inline-block"}})))))}renderEmpty(){return h("sc-empty",{icon:"activity"},wp.i18n.__("License not found.","surecart"))}renderLicenseHeader(){var e;const t=null===(e=this.license)||void 0===e?void 0:e.purchase,s=null==t?void 0:t.product;return h(Fragment,null,h("span",{slot:"heading"},h("div",{class:"license__heading"},null==s?void 0:s.name,!this.loading&&!t.live_mode&&h("sc-tag",{type:"warning",size:"small"},wp.i18n.__("Test Mode","surecart")))))}renderContent(){var e,t,s,i,n,o,a,c,l;return this.loading&&!(null===(e=this.license)||void 0===e?void 0:e.id)?this.renderLoading():(null===(t=this.license)||void 0===t?void 0:t.id)?h(Fragment,null,h("sc-dashboard-module",{error:this.error},this.renderLicenseHeader(),h("sc-card",{noPadding:!0},h("sc-stacked-list",null,h("sc-stacked-list-row",{style:{"--columns":"2","--sc-stacked-list-row-align-items":"center"}},h("div",null,wp.i18n.__("License Status","surecart")),this.renderStatus()),h("sc-stacked-list-row",{style:{"--columns":"2"}},h("div",null,wp.i18n.__("License Key","surecart")),h("div",{class:"license__key"},h("sc-input",{value:null===(s=this.license)||void 0===s?void 0:s.key,readonly:!0},h("sc-button",{class:"license__copy",type:"default",size:"small",slot:"suffix",onClick:()=>{var e;return this.copyKey(null===(e=this.license)||void 0===e?void 0:e.key)}},this.copied?wp.i18n.__("Copied!","surecart"):wp.i18n.__("Copy","surecart"))))),h("sc-stacked-list-row",{style:{"--columns":"2"}},h("div",null,wp.i18n.__("Date","surecart")),h("span",null,null===(i=this.license)||void 0===i?void 0:i.created_at_date)),h("sc-stacked-list-row",{style:{"--columns":"2"}},h("div",null,wp.i18n.__("Activations Count","surecart")),h("span",null,null===(n=this.license)||void 0===n?void 0:n.activation_count," / ",(null===(o=this.license)||void 0===o?void 0:o.activation_limit)||h("span",null,"∞")))))),h("sc-dashboard-module",null,h("span",{slot:"heading"},h("slot",{name:"heading"},wp.i18n.__("Activations","surecart"))),h("sc-card",{noPadding:!0},(null===(a=this.activations)||void 0===a?void 0:a.length)?h("sc-stacked-list",null,this.activations.map((e=>h("sc-stacked-list-row",{style:{"--columns":"4"}},h("div",{class:"license__date"},e.created_at_date),h("div",null,e.name),h("div",null,e.fingerprint),h("div",null,h("sc-button",{size:"small",onClick:()=>{this.selectedActivationId=e.id,this.showConfirmDelete=!0}},wp.i18n.__("Delete","surecart"))))))):h("sc-empty",null,wp.i18n.__("No activations present.","surecart")),this.loading&&h("sc-block-ui",{style:{"--sc-block-ui-opacity":"0.75"},spinner:!0})),(null===(c=this.pagination)||void 0===c?void 0:c.total_pages)>1&&h("sc-pagination",{page:this.query.page,perPage:this.query.per_page,total:this.pagination.total,totalPages:this.pagination.total_pages,totalShowing:null===(l=null==this?void 0:this.activations)||void 0===l?void 0:l.length,onScNextPage:()=>this.nextPage(),onScPrevPage:()=>this.prevPage()}))):this.renderEmpty()}renderConfirmDelete(){return h("sc-dialog",{open:this.showConfirmDelete,style:{"--body-spacing":"var(--sc-spacing-x-large)"},noHeader:!0,onScRequestClose:this.onCloseDeleteModal},h("sc-button",{class:"close__button",type:"text",circle:!0,onClick:this.onCloseDeleteModal,disabled:this.loading},h("sc-icon",{name:"x"})),h("sc-dashboard-module",{heading:wp.i18n.__("Delete Activation","surecart"),class:"license-cancel",error:this.error,style:{"--sc-dashboard-module-spacing":"1em"}},h("span",{slot:"description"},wp.i18n.__("Are you sure you want to delete activation?","surecart")),h("sc-flex",{justifyContent:"flex-start"},h("sc-button",{type:"primary",disabled:this.loading||this.busy,onClick:this.deleteActivation},wp.i18n.__("Delete Activation","surecart")),h("sc-button",{style:{color:"var(--sc-color-gray-500"},type:"text",onClick:this.onCloseDeleteModal,disabled:this.loading||this.busy},wp.i18n.__("Cancel","surecart"))),this.busy&&h("sc-block-ui",{style:{"--sc-block-ui-opacity":"0.75"},spinner:!0})))}render(){return h("sc-spacing",{key:"8b19a4ba277bf067362a5005bea577b408b70115",style:{"--spacing":"var(--sc-spacing-large)"}},this.renderContent(),this.renderConfirmDelete())}get el(){return this}static get style(){return ScLicenseStyle0}},[1,"sc-license",{licenseId:[1,"license-id"],query:[1040],loading:[32],error:[32],license:[32],activations:[32],copied:[32],showConfirmDelete:[32],selectedActivationId:[32],deleteActivationError:[32],busy:[32],pagination:[32]}]);function defineCustomElement$1(){"undefined"!=typeof customElements&&["sc-license","sc-alert","sc-block-ui","sc-button","sc-card","sc-dashboard-module","sc-dialog","sc-empty","sc-flex","sc-form-control","sc-icon","sc-input","sc-pagination","sc-skeleton","sc-spacing","sc-spinner","sc-stacked-list","sc-stacked-list-row","sc-tag","sc-visually-hidden"].forEach((e=>{switch(e){case"sc-license":customElements.get(e)||customElements.define(e,ScLicense$1);break;case"sc-alert":customElements.get(e)||defineCustomElement$k();break;case"sc-block-ui":customElements.get(e)||defineCustomElement$j();break;case"sc-button":customElements.get(e)||defineCustomElement$i();break;case"sc-card":customElements.get(e)||defineCustomElement$h();break;case"sc-dashboard-module":customElements.get(e)||defineCustomElement$g();break;case"sc-dialog":customElements.get(e)||defineCustomElement$f();break;case"sc-empty":customElements.get(e)||defineCustomElement$e();break;case"sc-flex":customElements.get(e)||defineCustomElement$d();break;case"sc-form-control":customElements.get(e)||defineCustomElement$c();break;case"sc-icon":customElements.get(e)||defineCustomElement$b();break;case"sc-input":customElements.get(e)||defineCustomElement$a();break;case"sc-pagination":customElements.get(e)||defineCustomElement$9();break;case"sc-skeleton":customElements.get(e)||defineCustomElement$8();break;case"sc-spacing":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 ScLicense=ScLicense$1,defineCustomElement=defineCustomElement$1;export{ScLicense,defineCustomElement};
Save
Back