format the amount in admin
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import Plan from "discourse/plugins/discourse-patrons/discourse/models/plan";
|
||||
import computed from "ember-addons/ember-computed-decorators";
|
||||
import { ajax } from "discourse/lib/ajax";
|
||||
|
||||
const AdminPlan = Discourse.Model.extend({
|
||||
const AdminPlan = Plan.extend({
|
||||
isNew: false,
|
||||
name: "",
|
||||
interval: "month",
|
||||
|
||||
@@ -2,10 +2,14 @@ import computed from "ember-addons/ember-computed-decorators";
|
||||
import { ajax } from "discourse/lib/ajax";
|
||||
|
||||
const Plan = Discourse.Model.extend({
|
||||
@computed("amount", "currency", "interval")
|
||||
subscriptionRate(amount, currency, interval) {
|
||||
const dollars = parseFloat(amount / 100).toFixed(2);
|
||||
return `$${dollars} ${currency.toUpperCase()} / ${interval}`;
|
||||
@computed("amount")
|
||||
amountDollars(amount) {
|
||||
return parseFloat(amount / 100).toFixed(2);
|
||||
},
|
||||
|
||||
@computed("amountDollars", "currency", "interval")
|
||||
subscriptionRate(amountDollars, currency, interval) {
|
||||
return `$${amountDollars} ${currency.toUpperCase()} / ${interval}`;
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import computed from "ember-addons/ember-computed-decorators";
|
||||
import { ajax } from "discourse/lib/ajax";
|
||||
import Plan from "discourse/plugins/discourse-patrons/discourse/models/plan";
|
||||
|
||||
const Subscription = Discourse.Model.extend({
|
||||
@computed("created")
|
||||
@@ -31,7 +32,10 @@ const Subscription = Discourse.Model.extend({
|
||||
Subscription.reopenClass({
|
||||
findAll() {
|
||||
return ajax("/patrons/subscriptions", { method: "get" }).then(result =>
|
||||
result.map(subscription => Subscription.create(subscription))
|
||||
result.map(subscription => {
|
||||
subscription.plan = Plan.create(subscription.plan);
|
||||
return Subscription.create(subscription)
|
||||
})
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -3,16 +3,8 @@ import Subscription from "discourse/plugins/discourse-patrons/discourse/models/s
|
||||
|
||||
export default Discourse.Route.extend({
|
||||
model() {
|
||||
const toCurrency = cents => parseFloat(cents / 100).toFixed(2);
|
||||
|
||||
const planSelectText = plan => {
|
||||
return `$${toCurrency(plan.amount)} ${plan.currency.toUpperCase()} / ${
|
||||
plan.interval
|
||||
}`;
|
||||
};
|
||||
|
||||
const plans = Plan.findAll().then(results =>
|
||||
results.map(p => ({ id: p.id, name: planSelectText(p) }))
|
||||
results.map(p => ({ id: p.id, name: p.subscriptionRate }))
|
||||
);
|
||||
|
||||
const subscription = Subscription.create();
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@
|
||||
<td>{{format-date plan.createdFormatted}}</td>
|
||||
<td>{{plan.metadata.group_name}}</td>
|
||||
<td>{{plan.active}}</td>
|
||||
<td class="td-right">{{plan.amount}}</td>
|
||||
<td class="td-right">{{plan.amountDollars}}</td>
|
||||
<td class="td-right">
|
||||
{{#link-to "adminPlugins.discourse-patrons.products.show.plans.show" model.product.id plan.id class="btn no-text btn-icon"}}
|
||||
{{d-icon "far-edit"}}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
<table class="table discourse-patrons-user-table">
|
||||
<thead>
|
||||
<th>{{i18n 'discourse_patrons.user.subscriptions.id'}}</th>
|
||||
<th>{{i18n 'discourse_patrons.user.plans.rate'}}</th>
|
||||
<th>{{i18n 'discourse_patrons.user.subscriptions.status'}}</th>
|
||||
<th>{{i18n 'discourse_patrons.user.subscriptions.created_at'}}</th>
|
||||
<th></th>
|
||||
@@ -12,6 +13,7 @@
|
||||
{{#each model as |subscription|}}
|
||||
<tr>
|
||||
<td>{{subscription.id}}</td>
|
||||
<td>{{subscription.plan.subscriptionRate}}</td>
|
||||
<td>{{subscription.status}}</td>
|
||||
<td>{{format-date subscription.createdFormatted}}</td>
|
||||
<td class="td-right">{{d-button disabled=subscription.canceled label="cancel" action=(route-action "cancelSubscription" subscription) icon="times"}}</td>
|
||||
|
||||
@@ -25,6 +25,8 @@ en:
|
||||
subscribe: Subscribe
|
||||
billing: Billing
|
||||
user:
|
||||
plans:
|
||||
rate: Rate
|
||||
subscriptions_help: You have no subscriptions.
|
||||
subscriptions:
|
||||
title: Subscriptions
|
||||
|
||||
@@ -12,6 +12,16 @@ QUnit.test("subscriptionRate", assert => {
|
||||
assert.equal(
|
||||
plan.get("subscriptionRate"),
|
||||
"$23.99 AUD / month",
|
||||
"it should return the formatted subscription rate"
|
||||
"it returns the formatted subscription rate"
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test("amountDollars", assert => {
|
||||
const plan = Plan.create({ amount: 2399 });
|
||||
|
||||
assert.equal(
|
||||
plan.get("amountDollars"),
|
||||
23.99,
|
||||
"it returns the formatted amount"
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user