FileMaster
Search
Toggle Dark Mode
Home
/
.
/
wp-content
/
plugins
/
surecart
/
dist
/
components
/
components
Edit File: sc-subscription-reactivate2.js
import{proxyCustomElement,HTMLElement,createEvent,h,Fragment}from"@stencil/core/internal/client";import{a as apiFetch}from"./fetch.js";import{d as defineCustomElement$a}from"./sc-alert2.js";import{d as defineCustomElement$9}from"./sc-block-ui2.js";import{d as defineCustomElement$8}from"./sc-button2.js";import{d as defineCustomElement$7}from"./sc-dashboard-module2.js";import{d as defineCustomElement$6}from"./sc-dialog2.js";import{d as defineCustomElement$5}from"./sc-flex2.js";import{d as defineCustomElement$4}from"./sc-icon2.js";import{d as defineCustomElement$3}from"./sc-skeleton2.js";import{d as defineCustomElement$2}from"./sc-spinner2.js";import{d as defineCustomElement$1}from"./sc-text2.js";import{a as addQueryArgs}from"./add-query-args.js";const ScSubscriptionReactivate=proxyCustomElement(class extends HTMLElement{constructor(){super(),this.__registerHost(),this.__attachShadow(),this.scRequestClose=createEvent(this,"scRequestClose",7),this.scRefresh=createEvent(this,"scRefresh",7),this.open=void 0,this.subscription=void 0,this.busy=void 0,this.error=void 0,this.upcomingPeriod=void 0,this.loading=!1}openChanged(){this.open&&this.fetchUpcoming()}async fetchUpcoming(){var e,t;this.loading=!0;try{this.upcomingPeriod=await apiFetch({method:"PATCH",path:addQueryArgs(`surecart/v1/subscriptions/${null===(e=this.subscription)||void 0===e?void 0:e.id}/upcoming_period`,{skip_product_group_validation:!0,expand:["period.checkout"]}),data:{purge_pending_update:!1}})}catch(e){this.error=(null===(t=null==e?void 0:e.additional_errors)||void 0===t?void 0:t.length)?e.additional_errors.map((e=>e.message)).join(", "):(null==e?void 0:e.message)||wp.i18n.__("Something went wrong","surecart")}finally{this.loading=!1}}async reactivateSubscription(){var e,t;try{this.error="",this.busy=!0,await apiFetch({path:`surecart/v1/subscriptions/${null===(e=this.subscription)||void 0===e?void 0:e.id}/restore`,method:"PATCH"}),this.scRefresh.emit(),this.scRequestClose.emit("close-button")}catch(e){this.error=(null===(t=null==e?void 0:e.additional_errors)||void 0===t?void 0:t.length)?e.additional_errors.map((e=>e.message)).join(", "):(null==e?void 0:e.message)||wp.i18n.__("Something went wrong","surecart")}finally{this.busy=!1}}renderLoading(){return 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"}}))}render(){var e,t,s;return h("sc-dialog",{key:"a053a64976d15fcd6589e1beb42e0d2d5db4e9a7",noHeader:!0,open:this.open,style:{"--width":"600px","--body-spacing":"var(--sc-spacing-xxx-large)"}},h("sc-dashboard-module",{key:"611aaff0aaec545720d547ca06b5e0cdcc549a35",loading:this.loading,heading:wp.i18n.__("Resubscribe","surecart"),class:"subscription-reactivate",error:this.error,style:{"--sc-dashboard-module-spacing":"1em"}},this.loading?this.renderLoading():h(Fragment,null,h("div",{slot:"description"},h("sc-alert",{open:!0,type:"warning",title:wp.i18n.__("Confirm Charge","surecart")},wp.i18n.__("You will be charged","surecart")," ",null===(t=null===(e=this.upcomingPeriod)||void 0===e?void 0:e.checkout)||void 0===t?void 0:t.amount_due_display_amount," ",wp.i18n.__("immediately for your subscription.","surecart")),h("sc-text",{style:{"--font-size":"var(--sc-font-size-medium)","--color":"var(--sc-input-label-color)","--line-height":"var(--sc-line-height-dense)","margin-top":"var(--sc-spacing-medium)"}},wp.i18n.__("Your subscription will be reactivated and will renew automatically on","surecart")," ",h("strong",null,null===(s=this.upcomingPeriod)||void 0===s?void 0:s.end_at_date))),h("sc-flex",{justifyContent:"flex-start"},h("sc-button",{type:"primary",loading:this.busy,disabled:this.busy,onClick:()=>this.reactivateSubscription()},wp.i18n.__("Yes, Reactivate","surecart")),h("sc-button",{disabled:this.busy,style:{color:"var(--sc-color-gray-500)"},type:"text",onClick:()=>this.scRequestClose.emit()},wp.i18n.__("No, Keep Inactive","surecart")))),this.busy&&h("sc-block-ui",{key:"7edd80f44a9aef268d8ab8bb083ed8a11ae326d6"})))}static get watchers(){return{open:["openChanged"]}}},[1,"sc-subscription-reactivate",{open:[4],subscription:[16],busy:[32],error:[32],upcomingPeriod:[32],loading:[32]},void 0,{open:["openChanged"]}]);function defineCustomElement(){"undefined"!=typeof customElements&&["sc-subscription-reactivate","sc-alert","sc-block-ui","sc-button","sc-dashboard-module","sc-dialog","sc-flex","sc-icon","sc-skeleton","sc-spinner","sc-text"].forEach((e=>{switch(e){case"sc-subscription-reactivate":customElements.get(e)||customElements.define(e,ScSubscriptionReactivate);break;case"sc-alert":customElements.get(e)||defineCustomElement$a();break;case"sc-block-ui":customElements.get(e)||defineCustomElement$9();break;case"sc-button":customElements.get(e)||defineCustomElement$8();break;case"sc-dashboard-module":customElements.get(e)||defineCustomElement$7();break;case"sc-dialog":customElements.get(e)||defineCustomElement$6();break;case"sc-flex":customElements.get(e)||defineCustomElement$5();break;case"sc-icon":customElements.get(e)||defineCustomElement$4();break;case"sc-skeleton":customElements.get(e)||defineCustomElement$3();break;case"sc-spinner":customElements.get(e)||defineCustomElement$2();break;case"sc-text":customElements.get(e)||defineCustomElement$1()}}))}export{ScSubscriptionReactivate as S,defineCustomElement as d};
Save
Back