Skip to content

Commit e45ee3f

Browse files
committed
FIX: Use native checkbox to properly update model on change
The PreferenceCheckbox component doesn't properly propagate checkbox state changes back to the model when used in plugin outlet contexts. This caused the subscription preference to not be saved when users toggled the checkbox. Replace PreferenceCheckbox with a native checkbox element and an explicit @action handler that calls model.set() when the checkbox changes. This ensures the model value is properly updated before the preferences are saved to the server.
1 parent 86a69d7 commit e45ee3f

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

assets/javascripts/discourse/connectors/user-preferences-emails/subscribe-newsletter-section.gjs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Component from "@glimmer/component";
2+
import { on } from "@ember/modifier";
3+
import { action } from "@ember/object";
24
import { service } from "@ember/service";
3-
import PreferenceCheckbox from "discourse/components/preference-checkbox";
45
import { i18n } from "discourse-i18n";
56

67
export default class SubscribeNewsletterSection extends Component {
@@ -10,17 +11,32 @@ export default class SubscribeNewsletterSection extends Component {
1011
return this.site.newsletter_integration_plugin_configured;
1112
}
1213

14+
@action
15+
updateSubscription(event) {
16+
this.args.outletArgs.model.set(
17+
"newsletter_integration_subscribe_global_newsletter",
18+
event.target.checked
19+
);
20+
}
21+
1322
<template>
1423
{{#if this.showSubscribeSection}}
1524
<div class="control-group newsletter-integration-subscribe-section">
1625
<label class="control-label">{{i18n
1726
"discourse_newsletter_integration.preferences.section_head"
1827
}}</label>
19-
<PreferenceCheckbox
20-
@labelKey="discourse_newsletter_integration.preferences.checkbox_description"
21-
@checked={{@outletArgs.model.newsletter_integration_subscribe_global_newsletter}}
22-
class="subscribe-checkbox"
23-
/>
28+
<div class="controls subscribe-checkbox">
29+
<label class="checkbox-label">
30+
<input
31+
type="checkbox"
32+
checked={{@outletArgs.model.newsletter_integration_subscribe_global_newsletter}}
33+
{{on "change" this.updateSubscription}}
34+
/>
35+
{{i18n
36+
"discourse_newsletter_integration.preferences.checkbox_description"
37+
}}
38+
</label>
39+
</div>
2440
</div>
2541
{{/if}}
2642
</template>

0 commit comments

Comments
 (0)