rm redundant component
This commit is contained in:
parent
dfba5471f9
commit
55bab5d936
|
@ -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()
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
|
@ -1,41 +0,0 @@
|
|||
{{#if includePrefix}}
|
||||
<span>{{i18n 'discourse_donations.invoice_prefix'}}</span>
|
||||
{{/if}}
|
||||
|
||||
<span class="donation-row-currency">{{currency}}</span>
|
||||
|
||||
<span class="donation-row-amount">{{amount}}</span>
|
||||
|
||||
<span class="donation-row-period">{{period}}</span>
|
||||
|
||||
{{#if invoice}}
|
||||
<a href='{{data.invoiceLink}}' target='_blank'>({{i18n 'discourse_donations.invoice'}})</a>
|
||||
{{/if}}
|
||||
|
||||
{{#if currentUser}}
|
||||
{{#if subscription}}
|
||||
<span class="donation-row-subscription">
|
||||
{{#if updating}}
|
||||
{{loading-spinner size='small'}}
|
||||
{{else}}
|
||||
{{#unless canceled}}
|
||||
<a {{action 'cancelSubscription'}}>
|
||||
{{i18n 'cancel'}}
|
||||
</a>
|
||||
{{/unless}}
|
||||
{{/if}}
|
||||
</span>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
|
||||
{{#if receiptSent}}
|
||||
<span>–</span>
|
||||
<span>{{i18n 'discourse_donations.receipt' email=customer.email}}</span>
|
||||
{{/if}}
|
||||
|
||||
{{#if new}}
|
||||
<span class="new-flag">
|
||||
{{d-icon 'circle'}}
|
||||
<span>{{i18n 'new_item'}}</span>
|
||||
</span>
|
||||
{{/if}}
|
|
@ -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"
|
||||
);
|
||||
}
|
||||
});
|
Loading…
Reference in New Issue