DEV: converts user-status modal to component (#23168)
This commit is contained in:
parent
121cd886a4
commit
932fd089c5
|
@ -1,5 +1,9 @@
|
||||||
<DModalBody>
|
<DModal
|
||||||
<ConditionalLoadingSpinner @condition={{this.loading}}>
|
@closeModal={{@closeModal}}
|
||||||
|
class="user-status"
|
||||||
|
@title={{i18n "user_status.set_custom_status"}}
|
||||||
|
>
|
||||||
|
<:body>
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<UserStatusPicker @status={{this.status}} />
|
<UserStatusPicker @status={{this.status}} />
|
||||||
</div>
|
</div>
|
||||||
|
@ -15,30 +19,31 @@
|
||||||
<label class="control-label">
|
<label class="control-label">
|
||||||
{{i18n "user_status.remove_status"}}
|
{{i18n "user_status.remove_status"}}
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<TimeShortcutPicker
|
<TimeShortcutPicker
|
||||||
@timeShortcuts={{this.timeShortcuts}}
|
@timeShortcuts={{this.timeShortcuts}}
|
||||||
@hiddenOptions={{this.hiddenTimeShortcutOptions}}
|
@hiddenOptions={{this.hiddenTimeShortcutOptions}}
|
||||||
@customLabels={{this.customTimeShortcutLabels}}
|
@customLabels={{this.customTimeShortcutLabels}}
|
||||||
@prefilledDatetime={{this.prefilledDateTime}}
|
@prefilledDatetime={{this.prefilledDateTime}}
|
||||||
@onTimeSelected={{action "onTimeSelected"}}
|
@onTimeSelected={{this.onTimeSelected}}
|
||||||
@_itsatrap={{this._itsatrap}}
|
@_itsatrap={{this._itsatrap}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer control-group">
|
</:body>
|
||||||
|
<:footer>
|
||||||
|
<DButton
|
||||||
|
@label="user_status.save"
|
||||||
|
@class="btn-primary"
|
||||||
|
@disabled={{not this.statusIsSet}}
|
||||||
|
@action={{this.saveAndClose}}
|
||||||
|
/>
|
||||||
|
<DModalCancel @close={{@closeModal}} />
|
||||||
|
{{#if this.showDeleteButton}}
|
||||||
<DButton
|
<DButton
|
||||||
@label="user_status.save"
|
@icon="trash-alt"
|
||||||
@class="btn-primary"
|
@class="delete-status btn-danger"
|
||||||
@disabled={{not this.statusIsSet}}
|
@action={{this.delete}}
|
||||||
@action={{action "saveAndClose"}}
|
|
||||||
/>
|
/>
|
||||||
<DModalCancel @close={{action "closeModal"}} />
|
{{/if}}
|
||||||
{{#if this.showDeleteButton}}
|
</:footer>
|
||||||
<DButton
|
</DModal>
|
||||||
@icon="trash-alt"
|
|
||||||
@class="delete-status btn-danger"
|
|
||||||
@action={{action "delete"}}
|
|
||||||
/>
|
|
||||||
{{/if}}
|
|
||||||
</div>
|
|
||||||
</ConditionalLoadingSpinner>
|
|
||||||
</DModalBody>
|
|
|
@ -1,5 +1,3 @@
|
||||||
import Controller from "@ember/controller";
|
|
||||||
import ModalFunctionality from "discourse/mixins/modal-functionality";
|
|
||||||
import { action } from "@ember/object";
|
import { action } from "@ember/object";
|
||||||
import { popupAjaxError } from "discourse/lib/ajax-error";
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||||
import discourseComputed from "discourse-common/utils/decorators";
|
import discourseComputed from "discourse-common/utils/decorators";
|
||||||
|
@ -8,14 +6,17 @@ import {
|
||||||
TIME_SHORTCUT_TYPES,
|
TIME_SHORTCUT_TYPES,
|
||||||
timeShortcuts,
|
timeShortcuts,
|
||||||
} from "discourse/lib/time-shortcut";
|
} from "discourse/lib/time-shortcut";
|
||||||
|
import Component from "@ember/component";
|
||||||
|
|
||||||
export default Controller.extend(ModalFunctionality, {
|
export default class ModalUserStatus extends Component {
|
||||||
showDeleteButton: false,
|
showDeleteButton = false;
|
||||||
prefilledDateTime: null,
|
prefilledDateTime = null;
|
||||||
timeShortcuts: null,
|
timeShortcuts = null;
|
||||||
_itsatrap: null,
|
_itsatrap = null;
|
||||||
|
|
||||||
|
init() {
|
||||||
|
super.init(...arguments);
|
||||||
|
|
||||||
onShow() {
|
|
||||||
const currentStatus = { ...this.model.status };
|
const currentStatus = { ...this.model.status };
|
||||||
this.setProperties({
|
this.setProperties({
|
||||||
status: currentStatus,
|
status: currentStatus,
|
||||||
|
@ -27,42 +28,42 @@ export default Controller.extend(ModalFunctionality, {
|
||||||
});
|
});
|
||||||
|
|
||||||
this.set("_itsatrap", new ItsATrap());
|
this.set("_itsatrap", new ItsATrap());
|
||||||
},
|
}
|
||||||
|
|
||||||
onClose() {
|
willDestroy() {
|
||||||
this._itsatrap.destroy();
|
this._itsatrap.destroy();
|
||||||
this.set("_itsatrap", null);
|
this.set("_itsatrap", null);
|
||||||
this.set("timeShortcuts", null);
|
this.set("timeShortcuts", null);
|
||||||
},
|
}
|
||||||
|
|
||||||
@discourseComputed("status.emoji", "status.description")
|
@discourseComputed("status.emoji", "status.description")
|
||||||
statusIsSet(emoji, description) {
|
statusIsSet(emoji, description) {
|
||||||
return !!emoji && !!description;
|
return !!emoji && !!description;
|
||||||
},
|
}
|
||||||
|
|
||||||
@discourseComputed
|
@discourseComputed
|
||||||
customTimeShortcutLabels() {
|
customTimeShortcutLabels() {
|
||||||
const labels = {};
|
const labels = {};
|
||||||
labels[TIME_SHORTCUT_TYPES.NONE] = "time_shortcut.never";
|
labels[TIME_SHORTCUT_TYPES.NONE] = "time_shortcut.never";
|
||||||
return labels;
|
return labels;
|
||||||
},
|
}
|
||||||
|
|
||||||
@discourseComputed
|
@discourseComputed
|
||||||
hiddenTimeShortcutOptions() {
|
hiddenTimeShortcutOptions() {
|
||||||
return [TIME_SHORTCUT_TYPES.LAST_CUSTOM];
|
return [TIME_SHORTCUT_TYPES.LAST_CUSTOM];
|
||||||
},
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
delete() {
|
delete() {
|
||||||
Promise.resolve(this.model.deleteAction())
|
Promise.resolve(this.model.deleteAction())
|
||||||
.then(() => this.send("closeModal"))
|
.then(() => this.closeModal())
|
||||||
.catch((e) => this._handleError(e));
|
.catch((e) => this._handleError(e));
|
||||||
},
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
onTimeSelected(_, time) {
|
onTimeSelected(_, time) {
|
||||||
this.set("status.endsAt", time);
|
this.set("status.endsAt", time);
|
||||||
},
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
saveAndClose() {
|
saveAndClose() {
|
||||||
|
@ -73,9 +74,9 @@ export default Controller.extend(ModalFunctionality, {
|
||||||
};
|
};
|
||||||
|
|
||||||
Promise.resolve(this.model.saveAction(newStatus, this.pauseNotifications))
|
Promise.resolve(this.model.saveAction(newStatus, this.pauseNotifications))
|
||||||
.then(() => this.send("closeModal"))
|
.then(() => this.closeModal())
|
||||||
.catch((e) => this._handleError(e));
|
.catch((e) => this._handleError(e));
|
||||||
},
|
}
|
||||||
|
|
||||||
_handleError(e) {
|
_handleError(e) {
|
||||||
if (typeof e === "string") {
|
if (typeof e === "string") {
|
||||||
|
@ -83,11 +84,11 @@ export default Controller.extend(ModalFunctionality, {
|
||||||
} else {
|
} else {
|
||||||
popupAjaxError(e);
|
popupAjaxError(e);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
_buildTimeShortcuts() {
|
_buildTimeShortcuts() {
|
||||||
const timezone = this.currentUser.user_option.timezone;
|
const timezone = this.currentUser.user_option.timezone;
|
||||||
const shortcuts = timeShortcuts(timezone);
|
const shortcuts = timeShortcuts(timezone);
|
||||||
return [shortcuts.oneHour(), shortcuts.twoHours(), shortcuts.tomorrow()];
|
return [shortcuts.oneHour(), shortcuts.twoHours(), shortcuts.tomorrow()];
|
||||||
},
|
}
|
||||||
});
|
}
|
|
@ -1,9 +1,9 @@
|
||||||
import Component from "@glimmer/component";
|
import Component from "@glimmer/component";
|
||||||
import { inject as service } from "@ember/service";
|
import { inject as service } from "@ember/service";
|
||||||
import { action } from "@ember/object";
|
import { action } from "@ember/object";
|
||||||
import showModal from "discourse/lib/show-modal";
|
|
||||||
import DoNotDisturb from "discourse/lib/do-not-disturb";
|
import DoNotDisturb from "discourse/lib/do-not-disturb";
|
||||||
import DoNotDisturbModal from "discourse/components/modal/do-not-disturb";
|
import DoNotDisturbModal from "discourse/components/modal/do-not-disturb";
|
||||||
|
import UserStatusModal from "discourse/components/modal/user-status";
|
||||||
|
|
||||||
const _extraItems = [];
|
const _extraItems = [];
|
||||||
|
|
||||||
|
@ -81,9 +81,8 @@ export default class UserMenuProfileTabContent extends Component {
|
||||||
@action
|
@action
|
||||||
setUserStatusClick() {
|
setUserStatusClick() {
|
||||||
this.args.closeUserMenu();
|
this.args.closeUserMenu();
|
||||||
showModal("user-status", {
|
|
||||||
title: "user_status.set_custom_status",
|
this.modal.show(UserStatusModal, {
|
||||||
modalClass: "user-status",
|
|
||||||
model: {
|
model: {
|
||||||
status: this.currentUser.status,
|
status: this.currentUser.status,
|
||||||
pauseNotifications: this.currentUser.isInDoNotDisturb(),
|
pauseNotifications: this.currentUser.isInDoNotDisturb(),
|
||||||
|
|
|
@ -11,11 +11,12 @@ import getURL from "discourse-common/lib/get-url";
|
||||||
import { popupAjaxError } from "discourse/lib/ajax-error";
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||||
import { inject as service } from "@ember/service";
|
import { inject as service } from "@ember/service";
|
||||||
import { next } from "@ember/runloop";
|
import { next } from "@ember/runloop";
|
||||||
import showModal from "discourse/lib/show-modal";
|
|
||||||
import { exportUserArchive } from "discourse/lib/export-csv";
|
import { exportUserArchive } from "discourse/lib/export-csv";
|
||||||
|
import UserStatusModal from "discourse/components/modal/user-status";
|
||||||
|
|
||||||
export default Controller.extend(CanCheckEmails, {
|
export default Controller.extend(CanCheckEmails, {
|
||||||
dialog: service(),
|
dialog: service(),
|
||||||
|
modal: service(),
|
||||||
user: controller(),
|
user: controller(),
|
||||||
canDownloadPosts: alias("user.viewingSelf"),
|
canDownloadPosts: alias("user.viewingSelf"),
|
||||||
|
|
||||||
|
@ -164,9 +165,7 @@ export default Controller.extend(CanCheckEmails, {
|
||||||
|
|
||||||
@action
|
@action
|
||||||
showUserStatusModal(status) {
|
showUserStatusModal(status) {
|
||||||
showModal("user-status", {
|
this.modal.show(UserStatusModal, {
|
||||||
title: "user_status.set_custom_status",
|
|
||||||
modalClass: "user-status",
|
|
||||||
model: {
|
model: {
|
||||||
status,
|
status,
|
||||||
hidePauseNotifications: true,
|
hidePauseNotifications: true,
|
||||||
|
|
|
@ -5,10 +5,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.modal-footer {
|
.modal-footer {
|
||||||
margin: 0;
|
|
||||||
border-top: 0;
|
|
||||||
padding: 10px 0;
|
|
||||||
|
|
||||||
.delete-status {
|
.delete-status {
|
||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
margin-right: 0;
|
margin-right: 0;
|
||||||
|
@ -34,5 +30,9 @@
|
||||||
.control-label {
|
.control-label {
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.tap-tile:last-child {
|
||||||
|
border: 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue