Skip to content

Commit

Permalink
Hotfix: Correct user enable notification (#2487)
Browse files Browse the repository at this point in the history
* show localized notification when user is enabled

* localize disable messages
  • Loading branch information
madsrasmussen authored Oct 28, 2024
1 parent 3bec2cb commit bbff154
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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);
}

Expand Down

0 comments on commit bbff154

Please sign in to comment.