import Component from "@glimmer/component"; import { action } from "@ember/object"; import { service } from "@ember/service"; import { htmlSafe } from "@ember/template"; import DButton from "discourse/components/d-button"; import DropdownMenu from "discourse/components/dropdown-menu"; import { USER_FIELD_FLAGS } from "discourse/lib/constants"; import { i18n } from "discourse-i18n"; import UserField from "admin/models/user-field"; import DMenu from "float-kit/components/d-menu"; export default class AdminUserFieldItem extends Component { @service adminUserFields; @service adminCustomUserFields; @service dialog; @service router; get fieldName() { return UserField.fieldTypeById(this.fieldType)?.name; } get cantMoveUp() { return this.args.userField.id === this.adminUserFields.firstField?.id; } get cantMoveDown() { return this.args.userField.id === this.adminUserFields.lastField?.id; } get flags() { return USER_FIELD_FLAGS.map((flag) => { if (this.args.userField[flag]) { return i18n(`admin.user_fields.${flag}.enabled`); } }) .filter(Boolean) .join(", "); } @action moveUp() { this.args.moveUpAction(this.args.userField); this.dMenu.close(); } @action moveDown() { this.args.moveDownAction(this.args.userField); this.dMenu.close(); } @action destroy() { this.args.destroyAction(this.args.userField); this.dMenu.close(); } @action onRegisterApi(api) { this.dMenu = api; } @action edit() { this.router.transitionTo("adminUserFields.edit", this.args.userField); } }