FIX: Default UX to notify on code reviews

FIX: Default UX to notify on code reviews

The custom field may be set to nil, in that case user is notified on code reviews

Ensure the user prefs reflect that

diff --git a/assets/javascripts/discourse/connectors/user-preferences-notifications/notify-code-review.js.es6 b/assets/javascripts/discourse/connectors/user-preferences-notifications/notify-code-review.js.es6
index b449c60..b1531d5 100644
--- a/assets/javascripts/discourse/connectors/user-preferences-notifications/notify-code-review.js.es6
+++ b/assets/javascripts/discourse/connectors/user-preferences-notifications/notify-code-review.js.es6
@@ -1,5 +1,18 @@
 export default {
-  //setupComponent(args, component) {},
+  setupComponent(args, component) {
+    const user = args.model;
+    this.set(
+      "notifyOnCodeReviews",
+      user.custom_fields.notify_on_code_reviews !== false
+    );
+
+    component.addObserver("notifyOnCodeReviews", () => {
+      user.set(
+        "custom_fields.notify_on_code_reviews",
+        component.get("notifyOnCodeReviews")
+      );
+    });
+  },
   shouldRender(args, component) {
     return component.currentUser && component.currentUser.admin;
   },
diff --git a/assets/javascripts/discourse/templates/connectors/user-preferences-notifications/notify-code-review.hbs b/assets/javascripts/discourse/templates/connectors/user-preferences-notifications/notify-code-review.hbs
index 48b52d2..471a9ab 100644
--- a/assets/javascripts/discourse/templates/connectors/user-preferences-notifications/notify-code-review.hbs
+++ b/assets/javascripts/discourse/templates/connectors/user-preferences-notifications/notify-code-review.hbs
@@ -3,6 +3,6 @@
   <div class="controls">
     {{preference-checkbox
           labelKey="code_review.notify_on_approval"
-          checked=model.custom_fields.notify_on_code_reviews}}
+          checked=notifyOnCodeReviews}}
   </div>
 </div>

GitHub sha: 9d836682

1 Like