From de20f99fef2c36570bf2fe58edcb0109c3041a81 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Fri, 25 Oct 2024 14:00:54 +0200 Subject: [PATCH 1/2] show localized notification when user is enabled --- .../repository/enable/enable-user.repository.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/packages/user/user/repository/enable/enable-user.repository.ts b/src/packages/user/user/repository/enable/enable-user.repository.ts index 2728c4807d..4c871e5fd5 100644 --- a/src/packages/user/user/repository/enable/enable-user.repository.ts +++ b/src/packages/user/user/repository/enable/enable-user.repository.ts @@ -1,10 +1,14 @@ import { UmbUserRepositoryBase } from '../user-repository-base.js'; +import { UmbUserItemRepository } from '../item/index.js'; import { UmbEnableUserServerDataSource } from './enable-user.server.data-source.js'; +import { UmbLocalizationController } from '@umbraco-cms/backoffice/localization-api'; import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api'; import { UserStateModel } from '@umbraco-cms/backoffice/external/backend-api'; export class UmbEnableUserRepository extends UmbUserRepositoryBase { #enableSource: UmbEnableUserServerDataSource; + #localize = new UmbLocalizationController(this); + #userItemRepository = new UmbUserItemRepository(this); constructor(host: UmbControllerHost) { super(host); @@ -18,11 +22,22 @@ export class UmbEnableUserRepository extends UmbUserRepositoryBase { const { data, error } = await this.#enableSource.enable(ids); if (!error) { + const { data: items } = await this.#userItemRepository.requestItems(ids); + if (!items) throw new Error('Could not load user item'); + + // TODO: get state from item when available ids.forEach((id) => { this.detailStore?.updateItem(id, { state: UserStateModel.ACTIVE }); }); - const notification = { data: { message: `User disabled` } }; + let message = this.#localize.term('speechBubbles_enableUsersSuccess', items.length); + + if (items.length === 1) { + const names = items?.map((item) => item.name).join(', '); + message = this.#localize.term('speechBubbles_enableUserSuccess', names); + } + + const notification = { data: { message } }; this.notificationContext?.peek('positive', notification); } From 9ae042a6ed94768889148e9a3f5b6d8fd512ff9f Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Fri, 25 Oct 2024 14:03:38 +0200 Subject: [PATCH 2/2] localize disable messages --- .../disable/disable-user.repository.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/packages/user/user/repository/disable/disable-user.repository.ts b/src/packages/user/user/repository/disable/disable-user.repository.ts index d7c94c6beb..81bc35ff41 100644 --- a/src/packages/user/user/repository/disable/disable-user.repository.ts +++ b/src/packages/user/user/repository/disable/disable-user.repository.ts @@ -1,10 +1,14 @@ import { UmbUserRepositoryBase } from '../user-repository-base.js'; +import { UmbUserItemRepository } from '../item/index.js'; import { UmbDisableUserServerDataSource } from './disable-user.server.data-source.js'; +import { UmbLocalizationController } from '@umbraco-cms/backoffice/localization-api'; import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api'; import { UserStateModel } from '@umbraco-cms/backoffice/external/backend-api'; export class UmbDisableUserRepository extends UmbUserRepositoryBase { #disableSource: UmbDisableUserServerDataSource; + #localize = new UmbLocalizationController(this); + #userItemRepository = new UmbUserItemRepository(this); constructor(host: UmbControllerHost) { super(host); @@ -18,11 +22,22 @@ export class UmbDisableUserRepository extends UmbUserRepositoryBase { const { data, error } = await this.#disableSource.disable(ids); if (!error) { + const { data: items } = await this.#userItemRepository.requestItems(ids); + if (!items) throw new Error('Could not load user item'); + + // TODO: get state from item when available ids.forEach((id) => { this.detailStore?.updateItem(id, { state: UserStateModel.DISABLED }); }); - const notification = { data: { message: `User disabled` } }; + let message = this.#localize.term('speechBubbles_disableUsersSuccess', items.length); + + if (items.length === 1) { + const names = items?.map((item) => item.name).join(', '); + message = this.#localize.term('speechBubbles_disableUserSuccess', names); + } + + const notification = { data: { message } }; this.notificationContext?.peek('positive', notification); }