From 8cb8f130d90c1bccd7d1b7359376436180ab1ecb Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Fri, 15 Sep 2023 00:39:52 +0200 Subject: [PATCH] DEV: Convert request-group-membership-form to new modal api (#23600) --- .../app/components/group-membership-button.js | 11 +++-- .../modal/request-group-membership-form.hbs | 22 ++++++---- .../modal/request-group-membership-form.js | 39 +++++++++++++++++ .../request-group-membership-form.js | 43 ------------------- .../discourse/app/services/modal.js | 1 - .../base/request-group-membership-form.scss | 4 -- 6 files changed, 60 insertions(+), 60 deletions(-) rename app/assets/javascripts/discourse/app/{templates => components}/modal/request-group-membership-form.hbs (62%) create mode 100644 app/assets/javascripts/discourse/app/components/modal/request-group-membership-form.js delete mode 100644 app/assets/javascripts/discourse/app/controllers/request-group-membership-form.js diff --git a/app/assets/javascripts/discourse/app/components/group-membership-button.js b/app/assets/javascripts/discourse/app/components/group-membership-button.js index bad2835a199..85150a89236 100644 --- a/app/assets/javascripts/discourse/app/components/group-membership-button.js +++ b/app/assets/javascripts/discourse/app/components/group-membership-button.js @@ -4,11 +4,14 @@ import cookie from "discourse/lib/cookie"; import discourseComputed from "discourse-common/utils/decorators"; import { popupAjaxError } from "discourse/lib/ajax-error"; import { inject as service } from "@ember/service"; -import showModal from "discourse/lib/show-modal"; +import RequestGroupMembershipForm from "./modal/request-group-membership-form"; export default Component.extend({ classNames: ["group-membership-button"], + appEvents: service(), + currentUser: service(), dialog: service(), + modal: service(), @discourseComputed("model.public_admission", "userIsGroupUser") canJoinGroup(publicAdmission, userIsGroupUser) { @@ -84,8 +87,10 @@ export default Component.extend({ showRequestMembershipForm() { if (this.currentUser) { - showModal("request-group-membership-form", { - model: this.model, + this.modal.show(RequestGroupMembershipForm, { + model: { + group: this.model, + }, }); } else { this._showLoginModal(); diff --git a/app/assets/javascripts/discourse/app/templates/modal/request-group-membership-form.hbs b/app/assets/javascripts/discourse/app/components/modal/request-group-membership-form.hbs similarity index 62% rename from app/assets/javascripts/discourse/app/templates/modal/request-group-membership-form.hbs rename to app/assets/javascripts/discourse/app/components/modal/request-group-membership-form.hbs index 3a694479aec..6f347be5932 100644 --- a/app/assets/javascripts/discourse/app/templates/modal/request-group-membership-form.hbs +++ b/app/assets/javascripts/discourse/app/components/modal/request-group-membership-form.hbs @@ -1,5 +1,9 @@ -
- + + <:body>
-
+ - -
\ No newline at end of file + + \ No newline at end of file diff --git a/app/assets/javascripts/discourse/app/components/modal/request-group-membership-form.js b/app/assets/javascripts/discourse/app/components/modal/request-group-membership-form.js new file mode 100644 index 00000000000..4bd8e80d11e --- /dev/null +++ b/app/assets/javascripts/discourse/app/components/modal/request-group-membership-form.js @@ -0,0 +1,39 @@ +import Component from "@glimmer/component"; +import { tracked } from "@glimmer/tracking"; +import { action } from "@ember/object"; +import DiscourseURL from "discourse/lib/url"; +import I18n from "I18n"; +import { isEmpty } from "@ember/utils"; +import { popupAjaxError } from "discourse/lib/ajax-error"; + +export default class RequestGroupMembershipForm extends Component { + @tracked loading = false; + + get reason() { + return this.args.model.group.membership_request_template; + } + + get title() { + return I18n.t("groups.membership_request.title", { + group_name: this.args.model.group.name, + }); + } + + get disableSubmit() { + return this.loading || isEmpty(this.reason); + } + + @action + async requestMember() { + this.loading = true; + + try { + const result = await this.args.model.group.requestMembership(this.reason); + DiscourseURL.routeTo(result.relative_url); + } catch (e) { + popupAjaxError(e); + } finally { + this.loading = false; + } + } +} diff --git a/app/assets/javascripts/discourse/app/controllers/request-group-membership-form.js b/app/assets/javascripts/discourse/app/controllers/request-group-membership-form.js deleted file mode 100644 index 0d3b52f77f9..00000000000 --- a/app/assets/javascripts/discourse/app/controllers/request-group-membership-form.js +++ /dev/null @@ -1,43 +0,0 @@ -import Controller from "@ember/controller"; -import DiscourseURL from "discourse/lib/url"; -import I18n from "I18n"; -import ModalFunctionality from "discourse/mixins/modal-functionality"; -import { alias } from "@ember/object/computed"; -import discourseComputed from "discourse-common/utils/decorators"; -import { isEmpty } from "@ember/utils"; -import { popupAjaxError } from "discourse/lib/ajax-error"; - -export default Controller.extend(ModalFunctionality, { - loading: false, - reason: alias("model.membership_request_template"), - - @discourseComputed("model.name") - title(groupName) { - return I18n.t("groups.membership_request.title", { group_name: groupName }); - }, - - @discourseComputed("loading", "reason") - disableSubmit(loading, reason) { - return loading || isEmpty(reason); - }, - - actions: { - requestMember() { - if (this.currentUser) { - this.set("loading", true); - - this.model - .requestMembership(this.reason) - .then((result) => { - DiscourseURL.routeTo(result.relative_url); - }) - .catch(popupAjaxError) - .finally(() => { - this.set("loading", false); - }); - } else { - this._showLoginModal(); - } - }, - }, -}); diff --git a/app/assets/javascripts/discourse/app/services/modal.js b/app/assets/javascripts/discourse/app/services/modal.js index 8554f668a95..0aee5bba940 100644 --- a/app/assets/javascripts/discourse/app/services/modal.js +++ b/app/assets/javascripts/discourse/app/services/modal.js @@ -22,7 +22,6 @@ const KNOWN_LEGACY_MODALS = [ "group-default-notifications", "reject-reason-reviewable", "reorder-categories", - "request-group-membership-form", ]; const LEGACY_OPTS = new Set([ diff --git a/app/assets/stylesheets/common/base/request-group-membership-form.scss b/app/assets/stylesheets/common/base/request-group-membership-form.scss index 33669fc0e24..569ebfeb696 100644 --- a/app/assets/stylesheets/common/base/request-group-membership-form.scss +++ b/app/assets/stylesheets/common/base/request-group-membership-form.scss @@ -3,7 +3,3 @@ font-weight: bold; } } - -.group-add-membership-request-template { - width: 98%; -}