user cancels subscription

This commit is contained in:
Rimian Perkins 2019-10-31 10:01:41 +11:00
parent 03cbc235b1
commit dbaa30ba18
7 changed files with 63 additions and 32 deletions

View File

@ -13,7 +13,6 @@ module DiscoursePatrons
expand: ['data.subscriptions'] expand: ['data.subscriptions']
) )
subscriptions = customers[:data].map do |customer| subscriptions = customers[:data].map do |customer|
customer[:subscriptions][:data] customer[:subscriptions][:data]
end.flatten(1) end.flatten(1)

View File

@ -7,6 +7,11 @@ const Subscription = Discourse.Model.extend({
return moment.unix(created).format(); return moment.unix(created).format();
}, },
@computed("status")
canceled(status) {
return status === 'canceled';
},
save() { save() {
const data = { const data = {
customer: this.customer, customer: this.customer,
@ -17,7 +22,9 @@ const Subscription = Discourse.Model.extend({
}, },
destroy() { destroy() {
return ajax(`/patrons/subscriptions/${this.id}`, { method: "delete" }); return ajax(`/patrons/subscriptions/${this.id}`, { method: "delete" }).then(result =>
Subscription.create(result)
);
}, },
}); });

View File

@ -11,5 +11,25 @@ export default Discourse.Route.extend({
} else { } else {
controller.setProperties({ model }); controller.setProperties({ model });
} }
},
actions: {
cancelSubscription(subscription) {
bootbox.confirm(
I18n.t("discourse_patrons.user.subscriptions.operations.destroy.confirm"),
I18n.t("no_value"),
I18n.t("yes_value"),
confirmed => {
if (confirmed) {
subscription
.destroy()
.then(result => subscription.set('status', result.status))
.catch(data =>
bootbox.alert(data.jqXHR.responseJSON.errors.join("\n"))
);
}
}
);
}
} }
}); });

View File

@ -1,21 +1,23 @@
{{#d-section class="user-secondary-navigation" pageClass="user-subscriptions"}}
<h3>{{i18n 'discourse_patrons.user.subscriptions.title'}}</h3> {{i18n 'discourse_patrons.user.subscriptions.title'}}
{{#if model}} {{#if model}}
<table class="topic-list"> <table class="table discourse-patrons-user-table">
<thead> <thead>
<th>{{i18n 'discourse_patrons.user.subscriptions.id'}}</th>
<th>{{i18n 'discourse_patrons.user.subscriptions.status'}}</th>
<th>{{i18n 'discourse_patrons.user.subscriptions.created_at'}}</th> <th>{{i18n 'discourse_patrons.user.subscriptions.created_at'}}</th>
<th></th> <th></th>
</thead> </thead>
{{#each model as |subscription|}} {{#each model as |subscription|}}
<tr> <tr>
<td>{{subscription.id}}</td>
<td>{{subscription.status}}</td>
<td>{{format-date subscription.createdFormatted}}</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>
</tr> </tr>
{{/each}} {{/each}}
</table> </table>
{{else}} {{else}}
<p>{{i18n 'discourse_patrons.user.subscriptions_help'}}</p> <p>{{i18n 'discourse_patrons.user.subscriptions_help'}}</p>
{{/if}} {{/if}}
{{/d-section}}

View File

@ -16,10 +16,15 @@ textarea[readonly] {
} }
} }
table.discourse-patrons-table {
.td-right { .td-right {
text-align: right; text-align: right;
} }
table.discourse-patrons-user-table {
width: 100%;
th, td {
padding: 10px;
}
} }
.desc { .desc {

View File

@ -28,14 +28,12 @@ en:
subscriptions_help: You have no subscriptions. subscriptions_help: You have no subscriptions.
subscriptions: subscriptions:
title: Subscriptions title: Subscriptions
id: Subscription ID
status: Status
created_at: Created created_at: Created
billing_help: We couldn't find a customer identifier in our system. operations:
billing: destroy:
title: Billing confirm: Are you sure you want to cancel this subscription?
invoices:
amount: Amount
number: Invoice Number
created_at: Created
title: Subscribe title: Subscribe
card: card:
title: Payment title: Payment