discourse/app/assets/javascripts/select-kit/addon/components/future-date-input-selector.js
Bianca Nenciu 7d7551adfc
DEV: Remove user options from current user serializer (#19089)
User options were serialized at the root level of CurrentUserSerializer,
but UserSerializer has a user_option field. This inconsistency caused
issues in the past because user_option fields had to be duplicated on
the frontend.
2022-12-05 18:25:30 +02:00

42 lines
1.1 KiB
JavaScript

import ComboBoxComponent from "select-kit/components/combo-box";
import { equal } from "@ember/object/computed";
import { isEmpty } from "@ember/utils";
export const FORMAT = "YYYY-MM-DD HH:mmZ";
export default ComboBoxComponent.extend({
pluginApiIdentifiers: ["future-date-input-selector"],
classNames: ["future-date-input-selector"],
isCustom: equal("value", "custom"),
userTimezone: null,
selectKitOptions: {
autoInsertNoneItem: false,
headerComponent:
"future-date-input-selector/future-date-input-selector-header",
},
init() {
this._super(...arguments);
this.userTimezone = this.currentUser.user_option.timezone;
},
modifyComponentForRow() {
return "future-date-input-selector/future-date-input-selector-row";
},
actions: {
onChange(value) {
if (value !== "custom" && !isEmpty(value)) {
const { time } = this.content.find((x) => x.id === value);
if (time) {
this.attrs.onChangeInput &&
this.attrs.onChangeInput(time.locale("en").format(FORMAT));
}
}
this.attrs.onChange && this.attrs.onChange(value);
},
},
});