discourse/app/assets/javascripts/admin/addon/services/admin-user-fields.js
Ted Johansson 88af23e1ca
DEV: Modernize admin user fields (#29843)
This PR modernizes the user fields area of the admin UI. It is largely based on the work on the emoji section.
2024-11-25 11:54:43 +08:00

37 lines
795 B
JavaScript

import { tracked } from "@glimmer/tracking";
import { sort } from "@ember/object/computed";
import Service, { service } from "@ember/service";
import { popupAjaxError } from "discourse/lib/ajax-error";
export default class AdminUserFields extends Service {
@service store;
@tracked userFields = [];
@sort("userFields", "fieldSortOrder") sortedUserFields;
fieldSortOrder = ["position"];
constructor() {
super(...arguments);
this.#fetchUserFields();
}
async #fetchUserFields() {
try {
this.userFields = await this.store.findAll("user-field");
} catch (err) {
popupAjaxError(err);
}
}
get firstField() {
return this.sortedUserFields[0];
}
get lastField() {
return this.sortedUserFields[this.sortedUserFields.length - 1];
}
}