user action
This commit is contained in:
@@ -2,11 +2,7 @@ import { css, html, LitElement } from 'lit';
|
||||
import { customElement, state } from 'lit/decorators.js';
|
||||
import { UUITextStyles } from '@umbraco-ui/uui-css/lib';
|
||||
import type { UUIButtonState } from '@umbraco-ui/uui';
|
||||
import type { UmbUserStore } from '../../../../core/stores/user/user.store';
|
||||
import type { UmbUserContext } from '../user.context';
|
||||
|
||||
import type { UmbNotificationDefaultData } from '../../../../core/services/notification/layouts/default';
|
||||
import type { UmbNotificationService } from '../../../../core/services/notification';
|
||||
import { UmbWorkspaceUserContext } from '../workspace-user.context';
|
||||
import { UmbContextConsumerMixin } from '@umbraco-cms/context-api';
|
||||
|
||||
@customElement('umb-workspace-action-user-save')
|
||||
@@ -16,34 +12,26 @@ export class UmbWorkspaceActionUserSaveElement extends UmbContextConsumerMixin(L
|
||||
@state()
|
||||
private _saveButtonState?: UUIButtonState;
|
||||
|
||||
private _userStore?: UmbUserStore;
|
||||
private _userContext?: UmbUserContext;
|
||||
private _notificationService?: UmbNotificationService;
|
||||
private _workspaceContext?: UmbWorkspaceUserContext;
|
||||
|
||||
connectedCallback(): void {
|
||||
super.connectedCallback();
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.consumeAllContexts(['umbUserStore', 'umbUserContext', 'umbNotificationService'], (instances) => {
|
||||
this._userStore = instances['umbUserStore'];
|
||||
this._userContext = instances['umbUserContext'];
|
||||
this._notificationService = instances['umbNotificationService'];
|
||||
});
|
||||
this.consumeContext('umbWorkspaceContext', (instance) => {
|
||||
this._workspaceContext = instance;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private async _handleSave() {
|
||||
// TODO: What if store is not present, what if node is not loaded....
|
||||
if (!this._userStore || !this._userContext) return;
|
||||
if (!this._workspaceContext) return;
|
||||
|
||||
try {
|
||||
this._saveButtonState = 'waiting';
|
||||
const user = this._userContext.getData();
|
||||
await this._userStore.save([user]);
|
||||
const data: UmbNotificationDefaultData = { message: 'User Saved' };
|
||||
this._notificationService?.peek('positive', { data });
|
||||
this._saveButtonState = 'waiting';
|
||||
await this._workspaceContext.save().then(() => {
|
||||
this._saveButtonState = 'success';
|
||||
} catch (error) {
|
||||
}).catch(() => {
|
||||
this._saveButtonState = 'failed';
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
Reference in New Issue
Block a user