Ghost/core/server/public/members.min.js

1 line
5.6 KiB
JavaScript
Raw Normal View History

Array.prototype.forEach.call(document.querySelectorAll("form[data-members-form]"),function(i){var c=i.querySelector("[data-members-error]");i.addEventListener("submit",function r(e){i.removeEventListener("submit",r),e.preventDefault(),c&&(c.innerText=""),i.classList.remove("success","invalid","error");for(var t=e.target.querySelector("input[data-members-email]").value,n=void 0,a=[],o=e.target.querySelectorAll("input[data-members-label]")||[],s=0;s<o.length;++s)a.push(o[s].value);i.dataset.membersForm&&(n=i.dataset.membersForm),i.classList.add("loading"),fetch("{{admin-url}}/api/canary/members/send-magic-link/",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:t,emailType:n,labels:a})}).then(function(e){i.addEventListener("submit",r),i.classList.remove("loading"),e.ok?i.classList.add("success"):(c&&(c.innerText="There was an error sending the email, please try again"),i.classList.add("error"))})})}),Array.prototype.forEach.call(document.querySelectorAll("[data-members-plan]"),function(i){var c=i.querySelector("[data-members-error]");i.addEventListener("click",function r(e){i.removeEventListener("click",r),e.preventDefault();var t,n,a=i.dataset.membersPlan,o=i.dataset.membersSuccess,s=i.dataset.membersCancel;o&&(t=new URL(o,window.location.href).href),s&&(n=new URL(s,window.location.href).href),c&&(c.innerText=""),i.classList.add("loading"),fetch("{{blog-url}}/members/ssr",{credentials:"same-origin"}).then(function(e){return e.ok?e.text():null}).then(function(e){return fetch("{{admin-url}}/api/canary/members/create-stripe-checkout-session/",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({plan:a,identity:e,successUrl:t,cancelUrl:n})}).then(function(e){if(!e.ok)throw new Error("Could not create stripe checkout session");return e.json()})}).then(function(e){return Stripe(e.publicKey).redirectToCheckout({sessionId:e.sessionId})}).then(function(e){if(e.error)throw new Error(e.error.message)}).catch(function(e){console.error(e),i.addEventListener("click",r),i.classList.remove("loading"),c&&(c.innerText=e.message),i.classList.add("error")})})}),Array.prototype.forEach.call(document.querySelectorAll("[data-members-edit-billing]"),function(t){var n,a,o=t.querySelector("[data-members-error]"),e=t.dataset.membersSuccess,r=t.dataset.membersCancel;e&&(n=new URL(e,window.location.href).href),r&&(a=new URL(r,window.location.href).href),t.addEventListener("click",function r(e){t.removeEventListener("click",r),e.preventDefault(),o&&(o.innerText=""),t.classList.add("loading"),fetch("{{blog-url}}/members/ssr",{credentials:"same-origin"}).then(function(e){return e.ok?e.text():null}).then(function(e){return fetch("{{admin-url}}/api/canary/members/create-stripe-setup-session/",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({identity:e,successUrl:n,cancelUrl:a})}).then(function(e){if(!e.ok)throw new Error("Could not create stripe checkout session");return e.json()})}).then(function(e){return Stripe(e.publicKey).redirectToCheckout({sessionId:e.sessionId})}).then(function(e){if(e.error)throw new Error(e.error.message)}).catch(function(e){console.error(e),t.addEventListener("click",r),t.classList.remove("loading"),o&&(o.innerText=e.message),t.classList.add("error")})})}),Array.prototype.forEach.call(document.querySelectorAll("[data-members-signout]"),function(t){t.addEventListener("click",function r(e){t.removeEventListener("click",r),e.preventDefault(),t.classList.remove("error"),t.classList.add("loading"),fetch("{{blog-url}}/members/ssr",{method:"DELETE"}).then(function(e){e.ok?window.location.reload():(t.addEventListener("click",r),t.classList.remove("loading"),t.classList.add("error"))})})}),Array.prototype.forEach.call(document.querySelectorAll("[data-members-cancel-subscription]"),function(n){var a=n.parentElement.querySelector("[data-members-error]");n.addEventListener("click",function r(e){n.removeEventListener("click",r),e.preventDefault(),n.classList.remove("error"),n.classList.add("loading");var t=n.dataset.membersCancelSubscription;retur