From cedabc16f0e1076e1b8c36cd87499d5f98149bbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Lyngs=C3=B8?= Date: Tue, 20 Dec 2022 16:16:51 +0100 Subject: [PATCH] user group action --- ...orkspace-action-user-group-save.element.ts | 45 +++++-------------- .../src/core/stores/user/user-group.store.ts | 8 ++++ 2 files changed, 19 insertions(+), 34 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/workspaces/user-group/actions/workspace-action-user-group-save.element.ts b/src/Umbraco.Web.UI.Client/src/backoffice/workspaces/user-group/actions/workspace-action-user-group-save.element.ts index 9b643cb8a5..b85554d8ea 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/workspaces/user-group/actions/workspace-action-user-group-save.element.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/workspaces/user-group/actions/workspace-action-user-group-save.element.ts @@ -2,12 +2,8 @@ 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 { UmbNotificationDefaultData } from '../../../../core/services/notification/layouts/default'; -import type { UmbNotificationService } from '../../../../core/services/notification'; -import { UmbUserGroupContext } from '../user-group.context'; +import type { UmbWorkspaceUserContext } from '../../user/workspace-user.context'; import { UmbContextConsumerMixin } from '@umbraco-cms/context-api'; -import { UmbUserGroupStore } from 'src/core/stores/user/user-group.store'; -import { UmbUserStore } from 'src/core/stores/user/user.store'; @customElement('umb-workspace-action-user-group-save') export class UmbWorkspaceActionUserGroupSaveElement extends UmbContextConsumerMixin(LitElement) { @@ -16,45 +12,26 @@ export class UmbWorkspaceActionUserGroupSaveElement extends UmbContextConsumerMi @state() private _saveButtonState?: UUIButtonState; - private _userGroupStore?: UmbUserGroupStore; - private _userStore?: UmbUserStore; - private _userGroupContext?: UmbUserGroupContext; - private _notificationService?: UmbNotificationService; + private _workspaceContext?: UmbWorkspaceUserContext; - connectedCallback(): void { - super.connectedCallback(); + constructor() { + super(); - this.consumeAllContexts( - ['umbUserGroupStore', 'umbUserStore', 'umbUserGroupContext', 'umbNotificationService'], - (instances) => { - this._userGroupStore = instances['umbUserGroupStore']; - this._userStore = instances['umbUserStore']; - this._userGroupContext = instances['umbUserGroupContext']; - 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._userGroupStore || !this._userGroupContext) return; + if (!this._workspaceContext) return; - try { - this._saveButtonState = 'waiting'; - const userGroup = this._userGroupContext.getData(); - await this._userGroupStore.save([userGroup]); - if (this._userStore && userGroup.users) { - await this._userStore.updateUserGroup(userGroup.users, userGroup.key); - } - - const notificationData: UmbNotificationDefaultData = { message: 'User Group Saved' }; - this._notificationService?.peek('positive', { data: notificationData }); + this._saveButtonState = 'waiting'; + await this._workspaceContext.save().then(() => { this._saveButtonState = 'success'; - } catch (error) { - const notificationData: UmbNotificationDefaultData = { message: 'User Group Save Failed' }; - this._notificationService?.peek('danger', { data: notificationData }); + }).catch(() => { this._saveButtonState = 'failed'; - } + }) } render() { diff --git a/src/Umbraco.Web.UI.Client/src/core/stores/user/user-group.store.ts b/src/Umbraco.Web.UI.Client/src/core/stores/user/user-group.store.ts index 12b3542b50..a22b286778 100644 --- a/src/Umbraco.Web.UI.Client/src/core/stores/user/user-group.store.ts +++ b/src/Umbraco.Web.UI.Client/src/core/stores/user/user-group.store.ts @@ -56,6 +56,14 @@ export class UmbUserGroupStore extends UmbDataStoreBase): Promise { // TODO: use Fetcher API. + + // TODO: implement so user group store updates the + /* + if (this._userStore && userGroup.users) { + await this._userStore.updateUserGroup(userGroup.users, userGroup.key); + } + */ + try { const res = await fetch('/umbraco/backoffice/user-groups/save', { method: 'POST',