Skip to content

Commit 6033df6

Browse files
committed
feat: fetch the document name and use in headlines and notifications
1 parent b3cc51a commit 6033df6

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

src/packages/documents/documents/entity-actions/notifications/modal/document-notifications-modal.element.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { UmbDocumentItemRepository } from '../../../repository/index.js';
12
import { UmbDocumentNotificationsRepository } from '../repository/document-notifications.repository.js';
23
import type { UmbDocumentNotificationsModalData } from './document-notifications-modal.token.js';
34
import type { UmbEntityUnique } from '@umbraco-cms/backoffice/entity';
@@ -19,9 +20,23 @@ export class UmbDocumentNotificationsModalElement extends UmbModalBaseElement<
1920
@state()
2021
private _settings: UmbDocumentNotificationSettings = [];
2122

23+
@state()
24+
private _documentName = '';
25+
2226
override firstUpdated() {
2327
this.#unique = this.data?.unique;
2428
this.#readNotificationSettings();
29+
this.#getDocumentName();
30+
}
31+
32+
async #getDocumentName() {
33+
if (!this.#unique) return;
34+
// Should this be done here or in the action file?
35+
const { data } = await new UmbDocumentItemRepository(this).requestItems([this.#unique]);
36+
if (!data) return;
37+
const item = data[0];
38+
//TODO How do we ensure we get the correct variant?
39+
this._documentName = item.variants[0]?.name;
2540
}
2641

2742
async #readNotificationSettings() {
@@ -36,9 +51,13 @@ export class UmbDocumentNotificationsModalElement extends UmbModalBaseElement<
3651
if (!this.#unique) return;
3752

3853
const subscribedActionIds = this._settings.filter((x) => x.subscribed).map((x) => x.actionId);
39-
const { error } = await this.#documentNotificationsRepository.updateNotifications(this.#unique, {
40-
subscribedActionIds,
41-
});
54+
const { error } = await this.#documentNotificationsRepository.updateNotifications(
55+
this.#unique,
56+
this._documentName,
57+
{
58+
subscribedActionIds,
59+
},
60+
);
4261

4362
if (error) return;
4463
this._submitModal();
@@ -57,7 +76,7 @@ export class UmbDocumentNotificationsModalElement extends UmbModalBaseElement<
5776
override render() {
5877
return html`
5978
<umb-body-layout headline=${this.localize.term('notifications_notifications')}>
60-
<uui-box>
79+
<uui-box .headline=${this.localize.term('notifications_editNotifications', this._documentName)}>
6180
${repeat(
6281
this._settings,
6382
(setting) => setting.actionId,

src/packages/documents/documents/entity-actions/notifications/repository/document-notifications.repository.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api';
44
import { UMB_NOTIFICATION_CONTEXT } from '@umbraco-cms/backoffice/notification';
55
import type { UmbApi } from '@umbraco-cms/backoffice/extension-api';
66
import type { UpdateDocumentNotificationsRequestModel } from '@umbraco-cms/backoffice/external/backend-api';
7+
import { UmbLocalizationController } from '@umbraco-cms/backoffice/localization-api';
78

89
export class UmbDocumentNotificationsRepository extends UmbControllerBase implements UmbApi {
910
#dataSource = new UmbDocumentNotificationsServerDataSource(this);
1011

1112
#notificationContext?: typeof UMB_NOTIFICATION_CONTEXT.TYPE;
1213

14+
#localize = new UmbLocalizationController(this);
15+
1316
constructor(host: UmbControllerHost) {
1417
super(host);
1518

@@ -28,13 +31,15 @@ export class UmbDocumentNotificationsRepository extends UmbControllerBase implem
2831
return { error };
2932
}
3033

31-
async updateNotifications(unique: string, data: UpdateDocumentNotificationsRequestModel) {
34+
async updateNotifications(unique: string, documentName: string, data: UpdateDocumentNotificationsRequestModel) {
3235
if (!unique) throw new Error('Unique is missing');
3336
if (!data) throw new Error('Data is missing');
3437

3538
const { error } = await this.#dataSource.update(unique, data);
3639
if (!error) {
37-
const notification = { data: { message: `Notification settings saved` } };
40+
const notification = {
41+
data: { message: this.#localize.term('notifications_notificationsSavedFor', documentName) },
42+
};
3843
this.#notificationContext?.peek('positive', notification);
3944
}
4045
return { error };

0 commit comments

Comments
 (0)