diff --git a/assets/javascripts/discourse/components/donation-row.js.es6 b/assets/javascripts/discourse/components/donation-row.js.es6 deleted file mode 100644 index fb2ab1a..0000000 --- a/assets/javascripts/discourse/components/donation-row.js.es6 +++ /dev/null @@ -1,99 +0,0 @@ -import { ajax } from "discourse/lib/ajax"; -import { popupAjaxError } from "discourse/lib/ajax-error"; -import { formatAnchor, formatAmount } from "../lib/donation-utilities"; -import { default as computed } from "ember-addons/ember-computed-decorators"; -import showModal from "discourse/lib/show-modal"; - -export default Ember.Component.extend({ - classNameBindings: [":donation-row", "canceled", "updating"], - includePrefix: Ember.computed.or("invoice", "charge"), - canceled: Ember.computed.equal("subscription.status", "canceled"), - - @computed("subscription", "invoice", "charge", "customer") - data(subscription, invoice, charge, customer) { - if (subscription) { - return $.extend({}, subscription.plan, { - anchor: subscription.billing_cycle_anchor - }); - } else if (invoice) { - let receiptSent = false; - - if (invoice.receipt_number && customer.email) { - receiptSent = true; - } - - return $.extend({}, invoice.lines.data[0], { - anchor: invoice.date, - invoiceLink: invoice.invoice_pdf, - receiptSent - }); - } else if (charge) { - let receiptSent = false; - - if (charge.receipt_number && charge.receipt_email) { - receiptSent = true; - } - - return $.extend({}, charge, { - anchor: charge.created, - receiptSent - }); - } - }, - - @computed("data.currency") - currency(currency) { - return currency ? currency.toUpperCase() : null; - }, - - @computed("data.amount", "currency") - amount(amount, currency) { - return formatAmount(amount, currency); - }, - - @computed("data.interval") - interval(interval) { - return interval || "once"; - }, - - @computed("data.anchor", "interval") - period(anchor, interval) { - return I18n.t(`discourse_donations.period.${interval}`, { - anchor: formatAnchor(interval, moment.unix(anchor)) - }); - }, - - cancelSubscription() { - const subscriptionId = this.get("subscription.id"); - this.set("updating", true); - - ajax("/donate/charges/cancel-subscription", { - data: { - subscription_id: subscriptionId - }, - method: "put" - }) - .then(result => { - if (result.success) { - this.set("subscription", result.subscription); - } - }) - .catch(popupAjaxError) - .finally(() => { - this.set("updating", false); - }); - }, - - actions: { - cancelSubscription() { - showModal("cancel-subscription", { - model: { - currency: this.get("currency"), - amount: this.get("amount"), - period: this.get("period"), - confirm: () => this.cancelSubscription() - } - }); - } - } -}); diff --git a/assets/javascripts/discourse/templates/components/donation-row.hbs b/assets/javascripts/discourse/templates/components/donation-row.hbs deleted file mode 100644 index 0e6d17a..0000000 --- a/assets/javascripts/discourse/templates/components/donation-row.hbs +++ /dev/null @@ -1,41 +0,0 @@ -{{#if includePrefix}} - {{i18n 'discourse_donations.invoice_prefix'}} -{{/if}} - -{{currency}} - -{{amount}} - -{{period}} - -{{#if invoice}} - ({{i18n 'discourse_donations.invoice'}}) -{{/if}} - -{{#if currentUser}} - {{#if subscription}} - - {{#if updating}} - {{loading-spinner size='small'}} - {{else}} - {{#unless canceled}} - - {{i18n 'cancel'}} - - {{/unless}} - {{/if}} - - {{/if}} -{{/if}} - -{{#if receiptSent}} - - {{i18n 'discourse_donations.receipt' email=customer.email}} -{{/if}} - -{{#if new}} - - {{d-icon 'circle'}} - {{i18n 'new_item'}} - -{{/if}} diff --git a/test/javascripts/components/donation-row-test.js.es6 b/test/javascripts/components/donation-row-test.js.es6 deleted file mode 100644 index 14cfd2e..0000000 --- a/test/javascripts/components/donation-row-test.js.es6 +++ /dev/null @@ -1,33 +0,0 @@ -import componentTest from "helpers/component-test"; - -moduleForComponent("donation-row", { integration: true }); - -componentTest("Discourse Patrons donation-row", { - template: `{{donation-row currency=3 amount=21 period='monthly'}}`, - - test(assert) { - assert.equal(find(".donation-row-currency").text(), "3", "It has currency"); - assert.equal(find(".donation-row-amount").text(), "21", "It has an amount"); - assert.equal( - find(".donation-row-period").text(), - "monthly", - "It has a period" - ); - } -}); - -componentTest("donation-row cancels subscription", { - template: `{{donation-row currentUser=currentUser subscription=subscription}}`, - - beforeEach() { - this.set("currentUser", true); - this.set("subscription", true); - }, - - async test(assert) { - assert.ok( - find(".donation-row-subscription").length, - "It has a subscription" - ); - } -});