mirror of
https://github.com/discourse/discourse.git
synced 2025-06-01 03:35:15 +08:00
DEV: Convert admin component definitions to native class syntax (#20311)
This conversion was achieved using the ember-native-class-codemod, plus a handful of manual fixes/tweaks
This commit is contained in:
@ -1,9 +1,11 @@
|
||||
import { action } from "@ember/object";
|
||||
import { classNames, tagName } from "@ember-decorators/component";
|
||||
import { inject as service } from "@ember/service";
|
||||
import discourseComputed from "discourse-common/utils/decorators";
|
||||
import Component from "@ember/component";
|
||||
import I18n from "I18n";
|
||||
import ScreenedIpAddress from "admin/models/screened-ip-address";
|
||||
import { schedule } from "@ember/runloop";
|
||||
import { inject as service } from "@ember/service";
|
||||
|
||||
/**
|
||||
A form to create an IP address that will be blocked or allowed.
|
||||
@ -16,12 +18,13 @@ import { inject as service } from "@ember/service";
|
||||
as an argument.
|
||||
**/
|
||||
|
||||
export default Component.extend({
|
||||
tagName: "form",
|
||||
dialog: service(),
|
||||
classNames: ["screened-ip-address-form", "inline-form"],
|
||||
formSubmitted: false,
|
||||
actionName: "block",
|
||||
@tagName("form")
|
||||
@classNames("screened-ip-address-form", "inline-form")
|
||||
export default class ScreenedIpAddressForm extends Component {
|
||||
@service dialog;
|
||||
|
||||
formSubmitted = false;
|
||||
actionName = "block";
|
||||
|
||||
@discourseComputed("siteSettings.use_admin_ip_allowlist")
|
||||
actionNames(adminAllowlistEnabled) {
|
||||
@ -46,43 +49,42 @@ export default Component.extend({
|
||||
},
|
||||
];
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
focusInput() {
|
||||
schedule("afterRender", () => {
|
||||
this.element.querySelector("input").focus();
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
actions: {
|
||||
submit() {
|
||||
if (!this.formSubmitted) {
|
||||
this.set("formSubmitted", true);
|
||||
const screenedIpAddress = ScreenedIpAddress.create({
|
||||
ip_address: this.ip_address,
|
||||
action_name: this.actionName,
|
||||
});
|
||||
screenedIpAddress
|
||||
.save()
|
||||
.then((result) => {
|
||||
this.setProperties({ ip_address: "", formSubmitted: false });
|
||||
this.action(ScreenedIpAddress.create(result.screened_ip_address));
|
||||
this.focusInput();
|
||||
})
|
||||
.catch((e) => {
|
||||
this.set("formSubmitted", false);
|
||||
const message = e.jqXHR.responseJSON?.errors
|
||||
? I18n.t("generic_error_with_reason", {
|
||||
error: e.jqXHR.responseJSON.errors.join(". "),
|
||||
})
|
||||
: I18n.t("generic_error");
|
||||
this.dialog.alert({
|
||||
message,
|
||||
didConfirm: () => this.focusInput(),
|
||||
didCancel: () => this.focusInput(),
|
||||
});
|
||||
@action
|
||||
submitForm() {
|
||||
if (!this.formSubmitted) {
|
||||
this.set("formSubmitted", true);
|
||||
const screenedIpAddress = ScreenedIpAddress.create({
|
||||
ip_address: this.ip_address,
|
||||
action_name: this.actionName,
|
||||
});
|
||||
screenedIpAddress
|
||||
.save()
|
||||
.then((result) => {
|
||||
this.setProperties({ ip_address: "", formSubmitted: false });
|
||||
this.action(ScreenedIpAddress.create(result.screened_ip_address));
|
||||
this.focusInput();
|
||||
})
|
||||
.catch((e) => {
|
||||
this.set("formSubmitted", false);
|
||||
const message = e.jqXHR.responseJSON?.errors
|
||||
? I18n.t("generic_error_with_reason", {
|
||||
error: e.jqXHR.responseJSON.errors.join(". "),
|
||||
})
|
||||
: I18n.t("generic_error");
|
||||
this.dialog.alert({
|
||||
message,
|
||||
didConfirm: () => this.focusInput(),
|
||||
didCancel: () => this.focusInput(),
|
||||
});
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user