FIX: Properly allow no group to be selected (#33)

This commit is contained in:
Justin DiRose 2020-11-24 14:52:00 -06:00 committed by GitHub
parent 52817018aa
commit d430098bad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 24 deletions

View File

@ -1,14 +1,31 @@
import discourseComputed from "discourse-common/utils/decorators";
import DiscourseURL from "discourse/lib/url";
import Controller from "@ember/controller";
import { alias } from "@ember/object/computed";
const RECURRING = "recurring";
const ONE_TIME = "one_time";
export default Controller.extend({
// Also defined in settings.
selectedCurrency: Ember.computed.alias("model.plan.currency"),
selectedInterval: Ember.computed.alias("model.plan.interval"),
selectedCurrency: alias("model.plan.currency"),
selectedInterval: alias("model.plan.interval"),
@discourseComputed("model.plan.metadata.group_name")
selectedGroup(groupName) {
return groupName || "no-group";
},
@discourseComputed("model.groups")
availableGroups(groups) {
return [
{
id: null,
name: "no-group",
},
...groups,
];
},
@discourseComputed
currencies() {
@ -57,13 +74,9 @@ export default Controller.extend({
},
createPlan() {
// TODO: set default group name beforehand
if (this.get("model.plan.metadata.group_name") === undefined) {
this.set("model.plan.metadata", {
group_name: this.get("model.groups.firstObject.name"),
});
if (this.model.plan.metadata.group_name === "no-group") {
this.set("model.plan.metadata.group_name", null);
}
this.get("model.plan")
.save()
.then(() => this.redirect(this.productId))
@ -73,6 +86,9 @@ export default Controller.extend({
},
updatePlan() {
if (this.model.plan.metadata.group_name === "no-group") {
this.set("model.plan.metadata.group_name", null);
}
this.get("model.plan")
.update()
.then(() => this.redirect(this.productId))

View File

@ -20,6 +20,9 @@ export default Route.extend({
isRecurring: true,
currency: Discourse.SiteSettings.discourse_subscriptions_currency,
product: product.get("id"),
metadata: {
group_name: null,
},
});
} else {
plan = AdminPlan.find(id).then((result) => {

View File

@ -15,10 +15,10 @@
</p>
<p>
<label for="interval">{{i18n 'discourse_subscriptions.admin.plans.plan.group'}}</label>
{{combo-box
{{combo-box
valueProperty="name"
content=model.groups
value=model.plan.metadata.group_name
content=availableGroups
value=selectedGroup
onChange=(action (mut model.plan.metadata.group_name))
}}
<div class="control-instructions">
@ -30,10 +30,10 @@
{{#if planFieldDisabled}}
{{input class="plan-amount plan-currency" disabled=true value=model.plan.currency}}
{{else}}
{{combo-box
disabled=planFieldDisabled
content=currencies
value=model.plan.currency
{{combo-box
disabled=planFieldDisabled
content=currencies
value=model.plan.currency
onChange=(action (mut model.plan.currency))
}}
{{/if}}
@ -44,16 +44,16 @@
{{i18n 'discourse_subscriptions.admin.plans.plan.recurring'}}
</label>
{{#if planFieldDisabled}}
{{input
type="checkbox"
name="recurring"
{{input
type="checkbox"
name="recurring"
checked=model.plan.isRecurring
disabled=true
}}
{{else}}
{{input
type="checkbox"
name="recurring"
{{input
type="checkbox"
name="recurring"
checked=model.plan.isRecurring
change=(action 'changeRecurring')
}}
@ -67,10 +67,10 @@
{{#if planFieldDisabled}}
{{input disabled=true value=selectedInterval}}
{{else}}
{{combo-box
{{combo-box
valueProperty="name"
content=availableIntervals
value=selectedInterval
content=availableIntervals
value=selectedInterval
onChange=(action (mut selectedInterval))
}}
{{/if}}