From 905b9a5cdd1bc7fd8679dbbb7c2fd98ba8af3320 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20M=C3=B8ller=20Jensen?= <26099018+JesmoDev@users.noreply.github.com> Date: Thu, 11 May 2023 21:08:38 +1200 Subject: [PATCH] add notifications --- .../repository/user-group.repository.ts | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/users/user-groups/repository/user-group.repository.ts b/src/Umbraco.Web.UI.Client/src/backoffice/users/user-groups/repository/user-group.repository.ts index fb8cb92997..c869b1641e 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/users/user-groups/repository/user-group.repository.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/users/user-groups/repository/user-group.repository.ts @@ -16,6 +16,8 @@ import { UmbRepositoryErrorResponse, UmbRepositoryResponse, } from '@umbraco-cms/backoffice/repository'; +import { UmbContextConsumerController } from '@umbraco-cms/backoffice/context-api'; +import { UMB_NOTIFICATION_CONTEXT_TOKEN, UmbNotificationContext } from '@umbraco-cms/backoffice/notification'; // TODO: implement export class UmbUserGroupRepository @@ -28,10 +30,16 @@ export class UmbUserGroupRepository #detailSource: UmbUserGroupDetailDataSource; #collectionSource: UmbCollectionDataSource; + #notificationContext?: UmbNotificationContext; + constructor(host: UmbControllerHostElement) { this.#host = host; this.#detailSource = new UmbUserGroupServerDataSource(this.#host); this.#collectionSource = new UmbUserGroupCollectionServerDataSource(this.#host); + + new UmbContextConsumerController(this.#host, UMB_NOTIFICATION_CONTEXT_TOKEN, (instance) => { + this.#notificationContext = instance; + }); } createScaffold(parentId: string | null): Promise> { return this.#detailSource.createScaffold(parentId); @@ -63,7 +71,12 @@ export class UmbUserGroupRepository const { data, error } = await this.#detailSource.insert(userGroupRequestData); - //TODO Put it in the store + //TODO Update store + + if (!error) { + const notification = { data: { message: `User group created` } }; + this.#notificationContext?.peek('positive', notification); + } return { error }; } @@ -74,7 +87,12 @@ export class UmbUserGroupRepository const { data, error } = await this.#detailSource.update(id, userGroup); - //TODO Put it in the store + //TODO Update store + + if (!error) { + const notification = { data: { message: `User group saved` } }; + this.#notificationContext?.peek('positive', notification); + } return { data, error }; } @@ -86,6 +104,11 @@ export class UmbUserGroupRepository //TODO Update store + if (!error) { + const notification = { data: { message: `User group deleted` } }; + this.#notificationContext?.peek('positive', notification); + } + return { error }; } }